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
@ -160,7 +160,7 @@ static int do_sign(struct strbuf *buffer, struct object_id **compat_oid,
|
||||
const struct git_hash_algo *compat = the_repository->compat_hash_algo;
|
||||
struct strbuf sig = STRBUF_INIT, compat_sig = STRBUF_INIT;
|
||||
struct strbuf compat_buf = STRBUF_INIT;
|
||||
const char *keyid = get_signing_key();
|
||||
char *keyid = get_signing_key();
|
||||
int ret = -1;
|
||||
|
||||
if (sign_buffer(buffer, &sig, keyid))
|
||||
@ -190,6 +190,7 @@ out:
|
||||
strbuf_release(&sig);
|
||||
strbuf_release(&compat_sig);
|
||||
strbuf_release(&compat_buf);
|
||||
free(keyid);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user