Instead of exiting on memory failure, log a warning then return NULL

to signify an error to the caller.
pull/678/merge
Jason Ish 12 years ago committed by Victor Julien
parent 5f6705c4dc
commit 8d29dfca59

@ -55,7 +55,7 @@ static ConfNode *root_backup = NULL;
* \param name The name of the configuration node to get. * \param name The name of the configuration node to get.
* *
* \retval The existing configuration node if it exists, or a newly * \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 * static ConfNode *
ConfGetNodeOrCreate(char *name) ConfGetNodeOrCreate(char *name)
@ -68,9 +68,9 @@ ConfGetNodeOrCreate(char *name)
tmpname = SCStrdup(name); tmpname = SCStrdup(name);
if (unlikely(tmpname == NULL)) { if (unlikely(tmpname == NULL)) {
SCLogError(SC_ERR_MEM_ALLOC, SCLogWarning(SC_ERR_MEM_ALLOC,
"Failed to allocate memory for configuration."); "Failed to allocate memory for configuration.");
exit(EXIT_FAILURE); goto end;
} }
key = tmpname; key = tmpname;
@ -80,9 +80,9 @@ ConfGetNodeOrCreate(char *name)
if ((node = ConfNodeLookupChild(parent, key)) == NULL) { if ((node = ConfNodeLookupChild(parent, key)) == NULL) {
node = ConfNodeNew(); node = ConfNodeNew();
if (unlikely(node == NULL)) { if (unlikely(node == NULL)) {
SCLogError(SC_ERR_MEM_ALLOC, SCLogWarning(SC_ERR_MEM_ALLOC,
"Failed to allocate memory for configuration."); "Failed to allocate memory for configuration.");
exit(EXIT_FAILURE); goto end;
} }
node->name = SCStrdup(key); node->name = SCStrdup(key);
node->parent = parent; node->parent = parent;
@ -92,7 +92,9 @@ ConfGetNodeOrCreate(char *name)
parent = node; parent = node;
} while (next != NULL); } while (next != NULL);
SCFree(tmpname); end:
if (tmpname != NULL)
SCFree(tmpname);
return node; return node;
} }

Loading…
Cancel
Save