Merge branch 'sb/gpg-plug-fd-leak' into maint
authorJunio C Hamano <gitster@pobox.com>
Thu, 7 Feb 2013 23:14:54 +0000 (15:14 -0800)
committerJunio C Hamano <gitster@pobox.com>
Thu, 7 Feb 2013 23:14:54 +0000 (15:14 -0800)
We forgot to close the file descriptor reading from "gpg" output,
killing "git log --show-signature" on a long history.

* sb/gpg-plug-fd-leak:
gpg: close stderr once finished with it in verify_signed_buffer()

1  2 
gpg-interface.c
diff --combined gpg-interface.c
index 0863c618007a02fa20c27b62614de8a554128d0c,bcf55a433e53a0ffc351316c505eb3585b8fb47f..5f142f619855ccd664a84be366bf6877a48e6da4
@@@ -5,7 -5,6 +5,7 @@@
  #include "sigchain.h"
  
  static char *configured_signing_key;
 +static const char *gpg_program = "gpg";
  
  void set_signing_key(const char *key)
  {
  int git_gpg_config(const char *var, const char *value, void *cb)
  {
        if (!strcmp(var, "user.signingkey")) {
 +              set_signing_key(value);
 +      }
 +      if (!strcmp(var, "gpg.program")) {
                if (!value)
                        return config_error_nonbool(var);
 -              set_signing_key(value);
 +              gpg_program = xstrdup(value);
        }
        return 0;
  }
@@@ -30,7 -26,7 +30,7 @@@ const char *get_signing_key(void
  {
        if (configured_signing_key)
                return configured_signing_key;
 -      return git_committer_info(IDENT_ERROR_ON_NO_NAME|IDENT_NO_DATE);
 +      return git_committer_info(IDENT_STRICT|IDENT_NO_DATE);
  }
  
  /*
@@@ -50,7 -46,7 +50,7 @@@ int sign_buffer(struct strbuf *buffer, 
        gpg.argv = args;
        gpg.in = -1;
        gpg.out = -1;
 -      args[0] = "gpg";
 +      args[0] = gpg_program;
        args[1] = "-bsau";
        args[2] = signing_key;
        args[3] = NULL;
  
  /*
   * Run "gpg" to see if the payload matches the detached signature.
 - * gpg_output_to tells where the output from "gpg" should go:
 - *   < 0: /dev/null
 - *   = 0: standard error of the calling process
 - *   > 0: the specified file descriptor
 + * gpg_output, when set, receives the diagnostic output from GPG.
   */
  int verify_signed_buffer(const char *payload, size_t payload_size,
                         const char *signature, size_t signature_size,
                         struct strbuf *gpg_output)
  {
        struct child_process gpg;
 -      const char *args_gpg[] = {"gpg", "--verify", "FILE", "-", NULL};
 +      const char *args_gpg[] = {NULL, "--verify", "FILE", "-", NULL};
        char path[PATH_MAX];
        int fd, ret;
  
 +      args_gpg[0] = gpg_program;
        fd = git_mkstemp(path, PATH_MAX, ".git_vtag_tmpXXXXXX");
        if (fd < 0)
                return error("could not create temporary file '%s': %s",
        write_in_full(gpg.in, payload, payload_size);
        close(gpg.in);
  
-       if (gpg_output)
+       if (gpg_output) {
                strbuf_read(gpg_output, gpg.err, 0);
+               close(gpg.err);
+       }
        ret = finish_command(&gpg);
  
        unlink_or_warn(path);