X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=util%2Fxmalloc.c;h=ce7852aafe3ccc86899d433c7452debbfb6cb329;hb=113640450c45ca7ac96285cc8ca666bfd597ed21;hp=fad55d83901558a86e269cba77cc3ba23b6addc4;hpb=00a64eba41e963e73b71f6b6850f748b5071663a;p=yaz-moved-to-github.git diff --git a/util/xmalloc.c b/util/xmalloc.c index fad55d8..ce7852a 100644 --- a/util/xmalloc.c +++ b/util/xmalloc.c @@ -4,7 +4,16 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: xmalloc.c,v $ - * Revision 1.1 1995-11-01 11:56:53 quinn + * Revision 1.4 1996-07-03 13:21:36 adam + * Function xfree_f checks for NULL pointer. + * + * Revision 1.3 1995/12/05 15:08:44 adam + * Fixed verbose of xrealloc. + * + * Revision 1.2 1995/12/05 11:08:37 adam + * More verbose malloc routines. + * + * Revision 1.1 1995/11/01 11:56:53 quinn * Added Xmalloc. * * Revision 1.6 1995/10/16 14:03:11 quinn @@ -37,12 +46,11 @@ void *xrealloc_f (void *o, size_t size, char *file, int line) { - void *p; + void *p = realloc (o, size); #ifdef TRACE_XMALLOC - fprintf(stderr, "%s:%d: xrealloc(s=%d)\n", file, line, size); + fprintf(stderr, "%s:%d: xrealloc(s=%d) %p -> %p\n", file, line, size, o, p); #endif - p = realloc (o, size); if (!p) { logf (LOG_FATAL|LOG_ERRNO, "Out of memory, realloc (%d bytes)", size); @@ -53,12 +61,11 @@ void *xrealloc_f (void *o, size_t size, char *file, int line) void *xmalloc_f (size_t size, char *file, int line) { - void *p; + void *p = malloc (size); #ifdef TRACE_XMALLOC - fprintf(stderr, "%s:%d: xmalloc(s=%d)\n", file, line, size); + fprintf(stderr, "%s:%d: xmalloc(s=%d) %p\n", file, line, size, p); #endif - p = malloc (size); if (!p) { logf (LOG_FATAL, "Out of memory - malloc (%d bytes)", size); @@ -69,11 +76,10 @@ void *xmalloc_f (size_t size, char *file, int line) void *xcalloc_f (size_t nmemb, size_t size, char *file, int line) { - void *p; + void *p = calloc (nmemb, size); #ifdef TRACE_XMALLOC - fprintf(stderr, "%s:%d: xcalloc(s=%d)\n", file, line, size); + fprintf(stderr, "%s:%d: xcalloc(s=%d) %p\n", file, line, size, p); #endif - p = calloc (nmemb, size); if (!p) { logf (LOG_FATAL, "Out of memory - calloc (%d, %d)", nmemb, size); @@ -86,7 +92,7 @@ char *xstrdup_f (const char *s, char *file, int line) { char *p = xmalloc (strlen(s)+1); #ifdef TRACE_XMALLOC - fprintf(stderr, "%s:%d: xstrdup(s=%d)\n", file, line, strlen(s)+1); + fprintf(stderr, "%s:%d: xstrdup(s=%d) %p\n", file, line, strlen(s)+1, p); #endif strcpy (p, s); return p; @@ -95,8 +101,11 @@ char *xstrdup_f (const char *s, char *file, int line) void xfree_f(void *p, char *file, int line) { + if (!p) + return ; #ifdef TRACE_XMALLOC - fprintf(stderr, "%s:%d: xfree\n", file, line); + if (p) + fprintf(stderr, "%s:%d: xfree %p\n", file, line, p); #endif free(p); }