From: Jason Ish Date: Wed, 24 Aug 2016 14:39:39 +0000 (-0600) Subject: logging: proper failure on memory allocation error X-Git-Tag: suricata-3.2beta1~347 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=108d37a52defb8c1298f1bfdf8c3d2c4d8eeef2e;p=thirdparty%2Fsuricata.git logging: proper failure on memory allocation error unwinds all previous logger allocations --- diff --git a/src/flow-worker.c b/src/flow-worker.c index 89894c7199..f9f7228ed7 100644 --- a/src/flow-worker.c +++ b/src/flow-worker.c @@ -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)); diff --git a/src/output.c b/src/output.c index 6c6ee8f805..d4dbb7da3f 100644 --- a/src/output.c +++ b/src/output.c @@ -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); }