From: Dmitry Bely Date: Thu, 9 Dec 2010 21:33:20 +0000 (+0000) Subject: Fix error path if realloc call fails. X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=HEAD;p=ocaml-ancient.git Fix error path if realloc call fails. --- diff --git a/ancient_c.c b/ancient_c.c index d5b11af..58735d0 100644 --- a/ancient_c.c +++ b/ancient_c.c @@ -133,13 +133,15 @@ area_init_custom (area *a, static inline int area_append (area *a, const void *obj, size_t size) { + void *ptr; while (a->n + size > a->size) { if (a->size == 0) a->size = 256; else a->size <<= 1; - a->ptr = + ptr = a->realloc ? a->realloc (a->data, a->ptr, a->size) : realloc (a->ptr, a->size); - if (a->ptr == 0) return -1; // Out of memory. + if (ptr == 0) return -1; // Out of memory. + a->ptr = ptr; } memcpy (a->ptr + a->n, obj, size); a->n += size;