From e7c282fed754bfc4a2fbdc2e8e1a7598b5fae27c Mon Sep 17 00:00:00 2001 From: Thomas Jarosch Date: Sat, 27 Dec 2014 17:33:24 +0100 Subject: More standard conforming codec_realloc() - Leave original ptr untouched if allocation fails (bail out early) - Behave like malloc() in case ptr is NULL Change-Id: Ib854ca19bd0e069999b7780d2d9a533ece705add --- lib/rbcodec/codecs/lib/codeclib.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/rbcodec/codecs/lib/codeclib.c b/lib/rbcodec/codecs/lib/codeclib.c index a12038eeb8..1f52c00434 100644 --- a/lib/rbcodec/codecs/lib/codeclib.c +++ b/lib/rbcodec/codecs/lib/codeclib.c @@ -91,8 +91,12 @@ void* codec_realloc(void* ptr, size_t size) { void* x; x = codec_malloc(size); - ci->memcpy(x, ptr, size); - codec_free(ptr); + if (x == NULL) + return NULL; + if (ptr) { + ci->memcpy(x, ptr, size); + codec_free(ptr); + } return(x); } -- cgit v1.2.3