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
9
commit.c
9
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,
|
||||
|
||||
Reference in New Issue
Block a user