summaryrefslogtreecommitdiff
path: root/src/init.c
diff options
context:
space:
mode:
authorJustus Winter <justus@g10code.com>2015-11-19 11:21:21 +0100
committerJustus Winter <justus@g10code.com>2015-11-19 11:27:44 +0100
commit06af687beaa1f8e72a05bd3a057b73fecb158c3d (patch)
treed485743c10f031443840997b2a539bbc7bb12269 /src/init.c
parenta144fa8863846dc3f6d34731741cd63251620837 (diff)
downloadlibgpg-error-06af687beaa1f8e72a05bd3a057b73fecb158c3d.tar.gz
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 <justus@g10code.com>
Diffstat (limited to 'src/init.c')
-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);
}