tempfile: release deactivated strbufs instead of resetting
[gitweb.git] / gpg-interface.c
index e44cc27da15f03629989ee0083664d0af09c55b3..4ea2597ff4cb304c82419eb515b07a04673b7f5f 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "run-command.h"
 #include "strbuf.h"
 #include "gpg-interface.h"
@@ -13,16 +14,11 @@ static const char *gpg_program = "gpg";
 
 void signature_check_clear(struct signature_check *sigc)
 {
-       free(sigc->payload);
-       free(sigc->gpg_output);
-       free(sigc->gpg_status);
-       free(sigc->signer);
-       free(sigc->key);
-       sigc->payload = NULL;
-       sigc->gpg_output = NULL;
-       sigc->gpg_status = NULL;
-       sigc->signer = NULL;
-       sigc->key = NULL;
+       FREE_AND_NULL(sigc->payload);
+       FREE_AND_NULL(sigc->gpg_output);
+       FREE_AND_NULL(sigc->gpg_status);
+       FREE_AND_NULL(sigc->signer);
+       FREE_AND_NULL(sigc->key);
 }
 
 static struct {
@@ -213,13 +209,13 @@ int verify_signed_buffer(const char *payload, size_t payload_size,
        fd = mks_tempfile_t(&temp, ".git_vtag_tmpXXXXXX");
        if (fd < 0)
                return error_errno(_("could not create temporary file"));
-       if (write_in_full(fd, signature, signature_size) < 0) {
+       if (write_in_full(fd, signature, signature_size) < 0 ||
+           close_tempfile_gently(&temp) < 0) {
                error_errno(_("failed writing detached signature to '%s'"),
                            temp.filename.buf);
                delete_tempfile(&temp);
                return -1;
        }
-       close(fd);
 
        argv_array_pushl(&gpg.args,
                         gpg_program,