[Pkg-gnupg-commit] [libgpg-error] 09/19: Avoid 'malloc' corner case.

Daniel Kahn Gillmor dkg at fifthhorseman.net
Tue Dec 15 15:55:27 UTC 2015


This is an automated email from the git hooks/post-receive script.

dkg pushed a commit to branch master
in repository libgpg-error.

commit 06af687beaa1f8e72a05bd3a057b73fecb158c3d
Author: Justus Winter <justus at g10code.com>
Date:   Thu Nov 19 11:21:21 2015 +0100

    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 at g10code.com>
---
 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);
 }
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/libgpg-error.git



More information about the Pkg-gnupg-commit mailing list