aboutsummaryrefslogtreecommitdiffstats
path: root/send-pack.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 /send-pack.c
parent49d47eb5416d22f185877a57380a1ffc28f172e1 (diff)
downloadgit-b8849e236f7a32d43ab3ba087587a336d69329b0.tar.gz
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 'send-pack.c')
-rw-r--r--send-pack.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/send-pack.c b/send-pack.c
index c37f6ab3c0..31a62e6a98 100644
--- a/send-pack.c
+++ b/send-pack.c
@@ -348,7 +348,8 @@ static int generate_push_cert(struct strbuf *req_buf,
{
const struct ref *ref;
struct string_list_item *item;
- char *signing_key_id = xstrdup(get_signing_key_id());
+ char *signing_key_id = get_signing_key_id();
+ char *signing_key = get_signing_key();
const char *cp, *np;
struct strbuf cert = STRBUF_INIT;
int update_seen = 0;
@@ -381,7 +382,7 @@ static int generate_push_cert(struct strbuf *req_buf,
if (!update_seen)
goto free_return;
- if (sign_buffer(&cert, &cert, get_signing_key()))
+ if (sign_buffer(&cert, &cert, signing_key))
die(_("failed to sign the push certificate"));
packet_buf_write(req_buf, "push-cert%c%s", 0, cap_string);
@@ -394,6 +395,7 @@ static int generate_push_cert(struct strbuf *req_buf,
free_return:
free(signing_key_id);
+ free(signing_key);
strbuf_release(&cert);
return update_seen;
}