From 7c6e12295236ee73ca46b785983673c7fc3c0597 Mon Sep 17 00:00:00 2001 From: Dmitry Bely Date: Thu, 9 Dec 2010 21:33:20 +0000 Subject: [PATCH] Fix error path if realloc call fails. --- ancient_c.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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; -- 1.8.3.1