]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
logging: proper failure on memory allocation error
authorJason Ish <ish@unx.ca>
Wed, 24 Aug 2016 14:39:39 +0000 (08:39 -0600)
committerVictor Julien <victor@inliniac.net>
Mon, 19 Sep 2016 11:47:52 +0000 (13:47 +0200)
unwinds all previous logger allocations

src/flow-worker.c
src/output.c

index 89894c7199b4af27d24130c711b231b69fdf0286..f9f7228ed7f97e59bb8397918e27d33b2e0e0aa4 100644 (file)
@@ -94,7 +94,9 @@ static TmEcode FlowWorkerThreadInit(ThreadVars *tv, void *initdata, void **data)
     }
 
     /* Setup outputs for this thread. */
-    OutputLoggerThreadInit(tv, initdata, &fw->output_thread);
+    if (OutputLoggerThreadInit(tv, initdata, &fw->output_thread) != TM_ECODE_OK) {
+        return TM_ECODE_FAILED;
+    }
 
     /* setup pq for stream end pkts */
     memset(&fw->pq, 0, sizeof(PacketQueue));
index 6c6ee8f805ddc15680e895f3100ebd0e2264ffc0..d4dbb7da3f84e908fc58ce1396a1dc9a69af90fc 100644 (file)
@@ -932,8 +932,7 @@ TmEcode OutputLoggerLog(ThreadVars *tv, Packet *p, void *thread_data)
     return TM_ECODE_OK;
 }
 
-TmEcode OutputLoggerThreadInit(ThreadVars *tv, void *initdata,
-    void **data)
+TmEcode OutputLoggerThreadInit(ThreadVars *tv, void *initdata, void **data)
 {
     LoggerThreadStore *thread_store = SCCalloc(1, sizeof(*thread_store));
     if (thread_store == NULL) {
@@ -950,7 +949,12 @@ TmEcode OutputLoggerThreadInit(ThreadVars *tv, void *initdata,
             if (logger->ThreadInit(tv, initdata, &child_thread_data) == TM_ECODE_OK) {
                 LoggerThreadStoreNode *thread_store_node =
                     SCCalloc(1, sizeof(*thread_store_node));
-                BUG_ON(thread_store_node == NULL);
+                if (thread_store_node == NULL) {
+                    /* Undo everything, calling de-init will take care
+                     * of that. */
+                    OutputLoggerThreadDeinit(tv, thread_store);
+                    return TM_ECODE_FAILED;
+                }
                 thread_store_node->thread_data = child_thread_data;
                 TAILQ_INSERT_TAIL(thread_store, thread_store_node, entries);
             }