Skip to content

Commit f3af71c

Browse files
peffgitster
authored andcommitted
gpg-interface: fix leak of strbufs in get_ssh_key_fingerprint()
We read stdout from gpg into a strbuf, then split it into a list of strbufs, pull out one element, and return it. But we don't free either the original stdout buffer, nor the list returned from strbuf_split(). This patch fixes both. Note that we have to detach the returned string from its strbuf before calling strbuf_list_free(), as that would otherwise throw it away. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 78d468f commit f3af71c

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

gpg-interface.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,7 @@ static char *get_ssh_key_fingerprint(const char *signing_key)
711711
int ret = -1;
712712
struct strbuf fingerprint_stdout = STRBUF_INIT;
713713
struct strbuf **fingerprint;
714+
char *fingerprint_ret;
714715

715716
/*
716717
* With SSH Signing this can contain a filename or a public key
@@ -737,7 +738,10 @@ static char *get_ssh_key_fingerprint(const char *signing_key)
737738
die_errno(_("failed to get the ssh fingerprint for key '%s'"),
738739
signing_key);
739740

740-
return strbuf_detach(fingerprint[1], NULL);
741+
fingerprint_ret = strbuf_detach(fingerprint[1], NULL);
742+
strbuf_list_free(fingerprint);
743+
strbuf_release(&fingerprint_stdout);
744+
return fingerprint_ret;
741745
}
742746

743747
/* Returns the first public key from an ssh-agent to use for signing */

0 commit comments

Comments
 (0)