From 06af687beaa1f8e72a05bd3a057b73fecb158c3d Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Thu, 19 Nov 2015 11:21:21 +0100 Subject: Avoid 'malloc' corner case. * src/init.c (_gpgrt_realloc): Avoid calling 'malloc(0)'. -- Previously, if '_gpgrt_realloc' was called with both A and N being zero, malloc is invoked with a size of zero. This happens e.g. when calling '_gpgrt_free' with a NULL pointer, which is supposed to be a no-op. Found using the Clang Static Analyzer. Signed-off-by: Justus Winter --- src/init.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/init.c b/src/init.c index e84b234..7abb6ff 100644 --- a/src/init.c +++ b/src/init.c @@ -171,15 +171,15 @@ _gpgrt_realloc (void *a, size_t n) if (custom_realloc) return custom_realloc (a, n); - if (!a) - return malloc (n); - if (!n) { free (a); return NULL; } + if (!a) + return malloc (n); + return realloc (a, n); } -- cgit v1.2.3