memory leak cleanups in misc places

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
remotes/origin/master-1.0.x
Steve Grubb 15 years ago committed by Victor Julien
parent 60ad9d29c5
commit c95cd2e80a

@ -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 *SCPerfGetCounterArrayRange(uint16_t s_id, uint16_t e_id,
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);

@ -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);

@ -192,6 +192,7 @@ TmEcode LogHttpLogThreadInit(ThreadVars *t, void *initdata, void **data)
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) */

@ -150,6 +150,7 @@ TmEcode ReceivePcapFileThreadInit(ThreadVars *tv, void *initdata, void **data) {
default:
printf("Error: datalink type %" PRId32 " not yet supported in module PcapFile.\n", pcap_g.datalink);
free(ptv);
return TM_ECODE_FAILED;
}

@ -149,6 +149,7 @@ Packet **UTHBuildPacketArrayFromEth(uint8_t *raw_eth[], int *pktsize, int numpkt
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));

Loading…
Cancel
Save