Skip to content

Commit

Permalink
gpg-interface: provide clear helper for struct signature_check
Browse files Browse the repository at this point in the history
The struct has been growing members whose malloced memory needs to be
freed. Do this with one helper function so that no malloced memory shall
be left unfreed.

Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Michael J Gruber authored and Junio C Hamano committed Jun 23, 2014
1 parent 0953113 commit 01e57b5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
5 changes: 1 addition & 4 deletions builtin/merge.c
Original file line number Diff line number Diff line change
Expand Up @@ -1282,10 +1282,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
printf(_("Commit %s has a good GPG signature by %s\n"),
hex, signature_check.signer);

free(signature_check.gpg_output);
free(signature_check.gpg_status);
free(signature_check.signer);
free(signature_check.key);
signature_check_clear(&signature_check);
}
}

Expand Down
12 changes: 12 additions & 0 deletions gpg-interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@
static char *configured_signing_key;
static const char *gpg_program = "gpg";

void signature_check_clear(struct signature_check *sigc)
{
free(sigc->gpg_output);
free(sigc->gpg_status);
free(sigc->signer);
free(sigc->key);
sigc->gpg_output = NULL;
sigc->gpg_status = NULL;
sigc->signer = NULL;
sigc->key = NULL;
}

void set_signing_key(const char *key)
{
free(configured_signing_key);
Expand Down
1 change: 1 addition & 0 deletions gpg-interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ struct signature_check {
char *key;
};

extern void signature_check_clear(struct signature_check *sigc);
extern int sign_buffer(struct strbuf *buffer, struct strbuf *signature, const char *signing_key);
extern int verify_signed_buffer(const char *payload, size_t payload_size, const char *signature, size_t signature_size, struct strbuf *gpg_output, struct strbuf *gpg_status);
extern int git_gpg_config(const char *, const char *, void *);
Expand Down
3 changes: 1 addition & 2 deletions pretty.c
Original file line number Diff line number Diff line change
Expand Up @@ -1532,8 +1532,7 @@ void format_commit_message(const struct commit *commit,

free(context.commit_encoding);
logmsg_free(context.message, commit);
free(context.signature_check.gpg_output);
free(context.signature_check.signer);
signature_check_clear(&context.signature_check);
}

static void pp_header(struct pretty_print_context *pp,
Expand Down

0 comments on commit 01e57b5

Please sign in to comment.