]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
counters: fix 2 scan-build warnings
authorVictor Julien <victor@inliniac.net>
Thu, 19 Dec 2013 20:14:06 +0000 (21:14 +0100)
committerVictor Julien <victor@inliniac.net>
Sat, 11 Jan 2014 10:54:58 +0000 (11:54 +0100)
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.

src/counters.c

index ce5a439da2ee0403a7af2ea376079b628ffd008e..f17dc8294cc752b89705d48c1e8566d42a684cb4 100644 (file)
@@ -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;