Skip to content

Commit 01e57b5

Browse files
Michael J Grubergitster
authored andcommitted
gpg-interface: provide clear helper for struct signature_check
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0953113 commit 01e57b5

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

builtin/merge.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,10 +1282,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
12821282
printf(_("Commit %s has a good GPG signature by %s\n"),
12831283
hex, signature_check.signer);
12841284

1285-
free(signature_check.gpg_output);
1286-
free(signature_check.gpg_status);
1287-
free(signature_check.signer);
1288-
free(signature_check.key);
1285+
signature_check_clear(&signature_check);
12891286
}
12901287
}
12911288

gpg-interface.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@
77
static char *configured_signing_key;
88
static const char *gpg_program = "gpg";
99

10+
void signature_check_clear(struct signature_check *sigc)
11+
{
12+
free(sigc->gpg_output);
13+
free(sigc->gpg_status);
14+
free(sigc->signer);
15+
free(sigc->key);
16+
sigc->gpg_output = NULL;
17+
sigc->gpg_status = NULL;
18+
sigc->signer = NULL;
19+
sigc->key = NULL;
20+
}
21+
1022
void set_signing_key(const char *key)
1123
{
1224
free(configured_signing_key);

gpg-interface.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ struct signature_check {
1313
char *key;
1414
};
1515

16+
extern void signature_check_clear(struct signature_check *sigc);
1617
extern int sign_buffer(struct strbuf *buffer, struct strbuf *signature, const char *signing_key);
1718
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);
1819
extern int git_gpg_config(const char *, const char *, void *);

pretty.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,8 +1532,7 @@ void format_commit_message(const struct commit *commit,
15321532

15331533
free(context.commit_encoding);
15341534
logmsg_free(context.message, commit);
1535-
free(context.signature_check.gpg_output);
1536-
free(context.signature_check.signer);
1535+
signature_check_clear(&context.signature_check);
15371536
}
15381537

15391538
static void pp_header(struct pretty_print_context *pp,

0 commit comments

Comments
 (0)