- malloc and realloc(0) are valid requests. Some implementations
may return NULL for these, which would not indicate an error.
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;
}
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;
}