From: Richard W.M. Jones Date: Fri, 29 May 2009 14:30:57 +0000 (+0100) Subject: Correctly handle malloc/realloc(0) X-Git-Tag: 1.0.38~4 X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=afa6f05e2e0d784250ab6408ff13152920d74495;p=libguestfs.git Correctly handle malloc/realloc(0) - malloc and realloc(0) are valid requests. Some implementations may return NULL for these, which would not indicate an error. --- diff --git a/src/guestfs.c b/src/guestfs.c index fb214c5..c5056d4 100644 --- a/src/guestfs.c +++ b/src/guestfs.c @@ -418,7 +418,7 @@ void * guestfs_safe_malloc (guestfs_h *g, size_t nbytes) { void *ptr = malloc (nbytes); - if (!ptr) g->abort_cb (); + if (nbytes > 0 && !ptr) g->abort_cb (); return ptr; } @@ -426,7 +426,7 @@ void * guestfs_safe_realloc (guestfs_h *g, void *ptr, int nbytes) { void *p = realloc (ptr, nbytes); - if (!p) g->abort_cb (); + if (nbytes > 0 && !p) g->abort_cb (); return p; }