[Pkg-gnupg-commit] [gnupg2] 22/112: common: Rework resource cleanup when handling errors.

Daniel Kahn Gillmor dkg at fifthhorseman.net
Tue Aug 30 17:48:15 UTC 2016


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

dkg pushed a commit to branch master
in repository gnupg2.

commit 35132a8b119dbc3393ceb0d0874917905d1a6354
Author: Justus Winter <justus at g10code.com>
Date:   Tue Jul 26 14:31:11 2016 +0200

    common: Rework resource cleanup when handling errors.
    
    * common/exectool.c (gnupg_exec_tool_stream): Rework error handling.
    
    Signed-off-by: Justus Winter <justus at g10code.com>
---
 common/exectool.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/common/exectool.c b/common/exectool.c
index b43e7cb..9c1cf65 100644
--- a/common/exectool.c
+++ b/common/exectool.c
@@ -1,5 +1,6 @@
 /* exectool.c - Utility functions to execute a helper tool
  * Copyright (C) 2015 Werner Koch
+ * Copyright (C) 2016 g10 Code GmbH
  *
  * This file is part of GnuPG.
  *
@@ -303,10 +304,10 @@ gnupg_exec_tool_stream (const char *pgmname, const char *argv[],
                         void *status_cb_value)
 {
   gpg_error_t err;
-  pid_t pid;
+  pid_t pid = (pid_t) -1;
   estream_t infp = NULL;
   estream_t extrafp = NULL;
-  estream_t outfp, errfp;
+  estream_t outfp = NULL, errfp = NULL;
   es_poll_t fds[4];
   int exceptclose[2];
   int extrapipe[2] = {-1, -1};
@@ -329,7 +330,10 @@ gnupg_exec_tool_stream (const char *pgmname, const char *argv[],
   fderrstate.buffer_size = 256;
   fderrstate.buffer = xtrymalloc (fderrstate.buffer_size);
   if (!fderrstate.buffer)
-    return my_error_from_syserror ();
+    {
+      err = my_error_from_syserror ();
+      goto leave;
+    }
 
   if (inextra)
     {
@@ -338,8 +342,7 @@ gnupg_exec_tool_stream (const char *pgmname, const char *argv[],
         {
           log_error ("error running outbound pipe for extra fp: %s\n",
                      gpg_strerror (err));
-          xfree (fderrstate.buffer);
-          return err;
+          goto leave;
         }
       exceptclose[0] = extrapipe[0]; /* Do not close in child. */
       exceptclose[1] = -1;
@@ -369,9 +372,7 @@ gnupg_exec_tool_stream (const char *pgmname, const char *argv[],
   if (err)
     {
       log_error ("error running '%s': %s\n", pgmname, gpg_strerror (err));
-      es_fclose (extrafp);
-      xfree (fderrstate.buffer);
-      return err;
+      goto leave;
     }
 
   fds[0].stream = infp;
@@ -494,7 +495,7 @@ gnupg_exec_tool_stream (const char *pgmname, const char *argv[],
   pid = (pid_t)(-1);
 
  leave:
-  if (err)
+  if (err && pid != (pid_t) -1)
     gnupg_kill_process (pid);
 
   es_fclose (infp);

-- 
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