aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustus Winter <[email protected]>2015-11-19 10:21:21 +0000
committerJustus Winter <[email protected]>2015-11-19 10:27:44 +0000
commit06af687beaa1f8e72a05bd3a057b73fecb158c3d (patch)
treed485743c10f031443840997b2a539bbc7bb12269
parentAdd error codes NO_NAME, NO_KEY, and SERVER_FAILURE. (diff)
downloadlibgpg-error-06af687beaa1f8e72a05bd3a057b73fecb158c3d.tar.gz
libgpg-error-06af687beaa1f8e72a05bd3a057b73fecb158c3d.zip
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 <[email protected]>
-rw-r--r--src/init.c6
1 files 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);
}