[Pkg-gnupg-commit] [gnupg2] 25/42: gpg: Remove some xmallocs.

Daniel Kahn Gillmor dkg at fifthhorseman.net
Wed Jan 3 18:25:54 UTC 2018


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

dkg pushed a commit to branch upstream
in repository gnupg2.

commit 29119a6492eda5dd7920e45e7f2faa043d436591
Author: Werner Koch <wk at gnupg.org>
Date:   Wed Dec 13 10:06:37 2017 +0100

    gpg: Remove some xmallocs.
    
    * g10/getkey.c (get_pubkeys): Do not use xmalloc.
    --
    
    We eventually need to get rid of all xmallocs so that gpg won't fail
    easily when we make more use of the s server mode.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>
---
 g10/getkey.c | 33 ++++++++++++++++++++++++++-------
 1 file changed, 26 insertions(+), 7 deletions(-)

diff --git a/g10/getkey.c b/g10/getkey.c
index eaf15ad..e31e023 100644
--- a/g10/getkey.c
+++ b/g10/getkey.c
@@ -497,7 +497,7 @@ get_pubkeys (ctrl_t ctrl,
                 search_terms, gpg_strerror (err));
       if (!opt.quiet && source)
         log_info (_("(check argument of option '%s')\n"), source);
-      goto out;
+      goto leave;
     }
 
   if (warn_possibly_ambiguous
@@ -517,8 +517,16 @@ get_pubkeys (ctrl_t ctrl,
   count = 0;
   do
     {
-      PKT_public_key *pk = xmalloc_clear (sizeof *pk);
+      PKT_public_key *pk;
       KBNODE kb;
+
+      pk = xtrycalloc (1, sizeof *pk);
+      if (!pk)
+        {
+          err = gpg_error_from_syserror ();
+          goto leave;
+        }
+
       pk->req_usage = use;
 
       if (! ctx)
@@ -542,7 +550,13 @@ get_pubkeys (ctrl_t ctrl,
       /* Another result!  */
       count ++;
 
-      r = xmalloc_clear (sizeof (*r));
+      r = xtrycalloc (1, sizeof (*r));
+      if (!r)
+        {
+          err = gpg_error_from_syserror ();
+          xfree (pk);
+          goto leave;
+        }
       r->pk = pk;
       r->keyblock = kb;
       r->next = results;
@@ -569,14 +583,14 @@ get_pubkeys (ctrl_t ctrl,
       if (!opt.quiet && source)
         log_info (_("(check argument of option '%s')\n"), source);
 
-      goto out;
+      goto leave;
     }
   else if (gpg_err_code (err) == GPG_ERR_NOT_FOUND)
     ; /* No more matches.  */
   else if (err)
     { /* Some other error.  An error message was already printed out.
        * Free RESULTS and continue.  */
-      goto out;
+      goto leave;
     }
 
   /* Check for duplicates.  */
@@ -641,7 +655,7 @@ get_pubkeys (ctrl_t ctrl,
                                    fingerprint, sizeof fingerprint));
     }
 
- out:
+ leave:
   if (err)
     pubkeys_free (results);
   else
@@ -712,8 +726,13 @@ get_pubkey (ctrl_t ctrl, PKT_public_key * pk, u32 * keyid)
   /* More init stuff.  */
   if (!pk)
     {
-      pk = xmalloc_clear (sizeof *pk);
       internal++;
+      pk = xtrycalloc (1, sizeof *pk);
+      if (!pk)
+        {
+          rc = gpg_error_from_syserror ();
+          goto leave;
+        }
     }
 
 

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



More information about the Pkg-gnupg-commit mailing list