When a library function calls exit(), it prevents the calling program from handling the error, reporting it to the user, closing files properly, and cleaning up any state that the program has. It is preferred for the library to return an actual error code and let the calling program decide how to handle the situation.
list.c is used in libdspam.so.
Cheers,
-- andreas
From b4a4d3578223feacf05ccc733f1335bd4ccae9b6 Mon Sep 17 00:00:00 2001 From: Andreas Schneider <[email protected]> Date: Thu, 16 Apr 2009 12:01:12 +0200 Subject: [PATCH] Don't exit() if malloc fails. When a library function calls exit(), it prevents the calling program from handling the error, reporting it to the user, closing files properly, and cleaning up any state that the program has. It is preferred for the library to return an actual error code and let the calling program decide how to handle the situation. Signed-off-by: Andreas Schneider <[email protected]> --- src/list.c | 10 ++++++++-- 1 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/list.c b/src/list.c index 15fded2..832b55a 100644 --- a/src/list.c +++ b/src/list.c @@ -33,10 +33,10 @@ static struct bnr_list_node * bnr_list_node_create (void *data) { struct bnr_list_node *node; - if ((node = (struct bnr_list_node *) malloc (sizeof (struct bnr_list_node))) == 0) + if ((node = (struct bnr_list_node *) malloc (sizeof (struct bnr_list_node))) == NULL) { perror("memory allocation error: list_node_create() failed"); - exit (1); + return NULL; } node->ptr = data; node->next = (struct bnr_list_node *) NULL; @@ -126,6 +126,9 @@ bnr_list_insert (struct bnr_list *list, void *data, float value) if (prev) { node = bnr_list_node_create (vptr); + if (node == NULL) { + return NULL; + } node->value = value; node->eliminated = 0; prev->next = node; @@ -135,6 +138,9 @@ bnr_list_insert (struct bnr_list *list, void *data, float value) else { node = bnr_list_node_create (vptr); + if (node == NULL) { + return NULL; + } node->value = value; node->eliminated = 0; list->first = node; -- 1.6.0.2
signature.asc
Description: This is a digitally signed message part.
------------------------------------------------------------------------------ Stay on top of everything new and different, both inside and around Java (TM) technology - register by April 22, and save $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco. 300 plus technical and hands-on sessions. Register today. Use priority code J9JMT32. http://p.sf.net/sfu/p
_______________________________________________ Dspam-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/dspam-devel
