[Oisf-devel] [PATCH] memory leak cleanups in misc places
Victor Julien
victor at inliniac.net
Sun Jan 24 19:40:50 UTC 2010
Applied as well, thanks Steve!
Steve Grubb wrote:
> Hello,
>
> This is all the rest of the memory leaks I found.
>
> *In src/source-pcap-file.c at line 152, ptv is not being freed.
> *In src/util-unittest-helper.c at line 152, p was not being freed.
> *In src/log-httplog.c at line 195, aft was not being freed
> *In src/counters.c at line 51, log_filename was not being freed. At line 1188
> pctx is being tested to see if its NULL. However, at 1173 it exits the
> function if it were NULL. This test is not needed and should be deleted.
> *In src/defrag.c at line 351, tracker was not being freed. At line 390, dc is
> being checked for NULL but this was already done at line 384. Probably what
> was meant was checking the value of dc->frag_table which was just assigned.
>
> The patch below makes the above described changes.
>
> -Steve
>
>
> diff -urp suricata-0.8.1.orig/src/counters.c suricata-0.8.1/src/counters.c
> --- suricata-0.8.1.orig/src/counters.c 2010-01-24 09:08:23.000000000 -0500
> +++ suricata-0.8.1/src/counters.c 2010-01-24 14:02:28.000000000 -0500
> @@ -48,6 +48,7 @@ static char *SCPerfGetLogFilename(void)
> if (snprintf(log_filename, PATH_MAX, "%s/%s", log_dir,
> SC_PERF_DEFAULT_LOG_FILENAME) < 0) {
> SCLogError(SC_SPRINTF_ERROR, "Sprintf Error");
> + free(log_filename);
> return NULL;
> }
>
> @@ -1185,11 +1186,6 @@ SCPerfCounterArray *SCPerfGetCounterArra
> return NULL;
> }
>
> - if (pctx == NULL) {
> - SCLogDebug("perfcontext is NULL");
> - return NULL;
> - }
> -
> if ( (pca = malloc(sizeof(SCPerfCounterArray))) == NULL) {
> SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
> exit(EXIT_FAILURE);
> diff -urp suricata-0.8.1.orig/src/defrag.c suricata-0.8.1/src/defrag.c
> --- suricata-0.8.1.orig/src/defrag.c 2010-01-24 09:08:23.000000000 -0500
> +++ suricata-0.8.1/src/defrag.c 2010-01-24 14:12:04.000000000 -0500
> @@ -347,8 +347,10 @@ DefragTrackerNew(void *arg)
> tracker = calloc(1, sizeof(*tracker));
> if (tracker == NULL)
> return NULL;
> - if (SCMutexInit(&tracker->lock, NULL) != 0)
> + if (SCMutexInit(&tracker->lock, NULL) != 0) {
> + free(tracker);
> return NULL;
> + }
> tracker->dc = dc;
> TAILQ_INIT(&tracker->frags);
>
> @@ -387,7 +389,7 @@ DefragContextNew(void)
> /* Initialize the hash table. */
> dc->frag_table = HashListTableInit(DEFAULT_DEFRAG_HASH_SIZE, DefragHashFunc,
> DefragHashCompare, DefragHashFree);
> - if (dc == NULL) {
> + if (dc->frag_table == NULL) {
> SCLogError(SC_ERR_MEM_ALLOC,
> "Defrag: Failed to initialize hash table.");
> exit(EXIT_FAILURE);
> diff -urp suricata-0.8.1.orig/src/log-httplog.c suricata-0.8.1/src/log-httplog.c
> --- suricata-0.8.1.orig/src/log-httplog.c 2010-01-24 09:08:23.000000000 -0500
> +++ suricata-0.8.1/src/log-httplog.c 2010-01-24 13:57:18.000000000 -0500
> @@ -192,6 +192,7 @@ TmEcode LogHttpLogThreadInit(ThreadVars
> if(initdata == NULL)
> {
> SCLogDebug("Error getting context for HTTPLog. \"initdata\" argument NULL");
> + free(aft);
> return TM_ECODE_FAILED;
> }
> /** Use the Ouptut Context (file pointer and mutex) */
> diff -urp suricata-0.8.1.orig/src/source-pcap-file.c suricata-0.8.1/src/source-pcap-file.c
> --- suricata-0.8.1.orig/src/source-pcap-file.c 2010-01-24 09:08:23.000000000 -0500
> +++ suricata-0.8.1/src/source-pcap-file.c 2010-01-24 10:53:58.000000000 -0500
> @@ -150,6 +150,7 @@ TmEcode ReceivePcapFileThreadInit(Thread
>
> default:
> printf("Error: datalink type %" PRId32 " not yet supported in module PcapFile.\n", pcap_g.datalink);
> + free(ptv);
> return TM_ECODE_FAILED;
> }
>
> diff -urp suricata-0.8.1.orig/src/util-unittest-helper.c suricata-0.8.1/src/util-unittest-helper.c
> --- suricata-0.8.1.orig/src/util-unittest-helper.c 2010-01-24 09:08:23.000000000 -0500
> +++ suricata-0.8.1/src/util-unittest-helper.c 2010-01-24 13:19:23.000000000 -0500
> @@ -149,6 +149,7 @@ Packet **UTHBuildPacketArrayFromEth(uint
> p[i] = malloc(sizeof(Packet));
> if (p[i] == NULL) {
> SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory for a packet of the array");
> + free(p);
> return NULL;
> }
> memset(p[i], 0, sizeof(Packet));
> _______________________________________________
> Oisf-devel mailing list
> Oisf-devel at openinfosecfoundation.org
> http://lists.openinfosecfoundation.org/mailman/listinfo/oisf-devel
--
---------------------------------------------
Victor Julien
http://www.inliniac.net/
PGP: http://www.inliniac.net/victorjulien.asc
---------------------------------------------
More information about the Oisf-devel
mailing list