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:
Patrick Steinhardt
2024-09-05 12:09:07 +02:00
committed by Junio C Hamano
parent 49d47eb541
commit b8849e236f
6 changed files with 30 additions and 19 deletions

View File

@ -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,