From 9e9e1925b901dff87518f0e1534a33e48eab8303 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Tue, 21 Nov 2000 09:13:59 +0000 Subject: [PATCH] - Check for NULL tree->delete callback - Add xstrdup() function --- lib/rbl.c | 10 ++++++++-- lib/xalloc.h | 2 ++ lib/xmalloc.c | 13 +++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/rbl.c b/lib/rbl.c index 3b97da6..c5114ef 100644 --- a/lib/rbl.c +++ b/lib/rbl.c @@ -17,13 +17,16 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: rbl.c,v 1.1.2.8 2000/11/20 19:12:10 guus Exp $ + $Id: rbl.c,v 1.1.2.9 2000/11/21 09:13:59 guus Exp $ */ +#include "config.h" + #include #include #include "rbl.h" +#include /* Allocate a new rbl node */ rbl_t *new_rbl() @@ -34,6 +37,8 @@ rbl_t *new_rbl() /* Free a rbl node */ void free_rbl(rbl_t *rbl) { + if(rbl->data && rbl->tree->delete) + rbl->tree->delete(rbl->data); free(rbl); } @@ -507,7 +512,8 @@ void rbl_delete_rbltree(rbltree_t *tree) for(rbl = tree->head; rbl; rbl = next) { next = rbl->next; - tree->delete(rbl->data); + if(tree->delete) + tree->delete(rbl->data); } tree->top = NULL; diff --git a/lib/xalloc.h b/lib/xalloc.h index 84b6cac..3579efc 100644 --- a/lib/xalloc.h +++ b/lib/xalloc.h @@ -22,3 +22,5 @@ void *xmalloc PARAMS ((size_t n)); void *xmalloc_and_zero PARAMS ((size_t n)); void *xcalloc PARAMS ((size_t n, size_t s)); void *xrealloc PARAMS ((void *p, size_t n)); + +char *xstrdup PARAMS ((char *s)); diff --git a/lib/xmalloc.c b/lib/xmalloc.c index 037fab8..e86fb07 100644 --- a/lib/xmalloc.c +++ b/lib/xmalloc.c @@ -21,6 +21,7 @@ #include #include +#include #if STDC_HEADERS # include @@ -124,6 +125,18 @@ xrealloc (p, n) return p; } +/* Duplicate a string */ + +char *xstrdup(char *s) +{ + char *p; + + p = strdup(s); + if(!p) + xalloc_fail ((int)strlen(s)); + return p; +} + #ifdef NOT_USED /* Allocate memory for N elements of S bytes, with error checking. */ -- 2.25.1