mirror of
https://github.com/git/git.git
synced 2025-12-12 20:36:24 +01:00
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>
This commit is contained in:
committed by
Junio C Hamano
parent
49d47eb541
commit
b8849e236f
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user