summaryrefslogtreecommitdiff
path: root/commit.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2024-09-05 12:09:07 +0200
committerJunio C Hamano <gitster@pobox.com>2024-09-05 08:49:11 -0700
commitb8849e236f7a32d43ab3ba087587a336d69329b0 (patch)
tree6b1df61ebb81e62c9ce99caf9312dafb01e5acb7 /commit.c
parent49d47eb5416d22f185877a57380a1ffc28f172e1 (diff)
gpg-interface: fix misdesigned signing key interfaces
The interfaces to retrieve signing keys and their IDs are misdesigned as they return string constants even though they indeed allocate memory, which leads to memory leaks. Refactor the code to instead always return allocated strings and let the callers free them accordingly. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'commit.c')
-rw-r--r--commit.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/commit.c b/commit.c
index 24ab5c1b50..ec9efc189d 100644
--- a/commit.c
+++ b/commit.c
@@ -1150,11 +1150,14 @@ int add_header_signature(struct strbuf *buf, struct strbuf *sig, const struct gi
static int sign_commit_to_strbuf(struct strbuf *sig, struct strbuf *buf, const char *keyid)
{
+ char *keyid_to_free = NULL;
+ int ret = 0;
if (!keyid || !*keyid)
- keyid = get_signing_key();
+ keyid = keyid_to_free = get_signing_key();
if (sign_buffer(buf, sig, keyid))
- return -1;
- return 0;
+ ret = -1;
+ free(keyid_to_free);
+ return ret;
}
int parse_signed_commit(const struct commit *commit,