]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
Instead of exiting on memory failure, log a warning then return NULL
authorJason Ish <jason.ish@emulex.com>
Thu, 28 Nov 2013 16:04:16 +0000 (10:04 -0600)
committerVictor Julien <victor@inliniac.net>
Wed, 4 Dec 2013 10:21:52 +0000 (11:21 +0100)
to signify an error to the caller.

src/conf.c

index f27bab78780fe66052ea04ba9d580cdb05f185f2..f210e75d47df9b33d892fa0b03c8d8d3eb86c684 100644 (file)
@@ -55,7 +55,7 @@ static ConfNode *root_backup = NULL;
  * \param name The name of the configuration node to get.
  *
  * \retval The existing configuration node if it exists, or a newly
- *   created node for the provided name.
+ *   created node for the provided name.  On error, NULL will be returned.
  */
 static ConfNode *
 ConfGetNodeOrCreate(char *name)
@@ -68,9 +68,9 @@ ConfGetNodeOrCreate(char *name)
 
     tmpname = SCStrdup(name);
     if (unlikely(tmpname == NULL)) {
-        SCLogError(SC_ERR_MEM_ALLOC,
+        SCLogWarning(SC_ERR_MEM_ALLOC,
             "Failed to allocate memory for configuration.");
-        exit(EXIT_FAILURE);
+        goto end;
     }
     key = tmpname;
 
@@ -80,9 +80,9 @@ ConfGetNodeOrCreate(char *name)
         if ((node = ConfNodeLookupChild(parent, key)) == NULL) {
             node = ConfNodeNew();
             if (unlikely(node == NULL)) {
-                SCLogError(SC_ERR_MEM_ALLOC,
+                SCLogWarning(SC_ERR_MEM_ALLOC,
                     "Failed to allocate memory for configuration.");
-                exit(EXIT_FAILURE);
+                goto end;
             }
             node->name = SCStrdup(key);
             node->parent = parent;
@@ -92,7 +92,9 @@ ConfGetNodeOrCreate(char *name)
         parent = node;
     } while (next != NULL);
 
-    SCFree(tmpname);
+end:
+    if (tmpname != NULL)
+        SCFree(tmpname);
 
     return node;
 }