From: Victor Julien Date: Thu, 19 Dec 2013 20:14:06 +0000 (+0100) Subject: counters: fix 2 scan-build warnings X-Git-Tag: suricata-2.0rc1~209 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=399246881daaf117b68fbd4fdfe4c82a32f67ef8;p=thirdparty%2Fsuricata.git counters: fix 2 scan-build warnings counters.c:1069:13: warning: Potential leak of memory pointed to by 'temp' SCMutexUnlock(&sc_perf_op_ctx->pctmi_lock); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ./threads.h:121:28: note: expanded from macro 'SCMutexUnlock' ^~~~~~~~~~~~~~~~~~~~ counters.c:1156:16: warning: Potential leak of memory pointed to by 'pca' return NULL; ^~~~ /usr/include/clang/3.3/include/stddef.h:77:24: note: expanded from macro 'NULL' ^ 2 warnings generated. --- diff --git a/src/counters.c b/src/counters.c index ce5a439da2..f17dc8294c 100644 --- a/src/counters.c +++ b/src/counters.c @@ -1060,12 +1060,15 @@ int SCPerfAddToClubbedTMTable(char *tm_name, SCPerfContext *pctx) temp->size = 1; temp->head = SCMalloc(sizeof(SCPerfContext **)); if (temp->head == NULL) { + SCFree(temp); SCMutexUnlock(&sc_perf_op_ctx->pctmi_lock); return 0; } temp->head[0] = pctx; temp->tm_name = SCStrdup(tm_name); if (unlikely(temp->tm_name == NULL)) { + SCFree(temp->head); + SCFree(temp); SCMutexUnlock(&sc_perf_op_ctx->pctmi_lock); return 0; } @@ -1152,8 +1155,10 @@ SCPerfCounterArray *SCPerfGetCounterArrayRange(uint16_t s_id, uint16_t e_id, return NULL; memset(pca, 0, sizeof(SCPerfCounterArray)); - if ( (pca->head = SCMalloc(sizeof(SCPCAElem) * (e_id - s_id + 2))) == NULL) + if ( (pca->head = SCMalloc(sizeof(SCPCAElem) * (e_id - s_id + 2))) == NULL) { + SCFree(pca); return NULL; + } memset(pca->head, 0, sizeof(SCPCAElem) * (e_id - s_id + 2)); pc = pctx->head;