diff options
author | Jeff King <peff@peff.net> | 2021-10-18 13:15:37 -0400 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2021-10-18 13:16:53 -0700 |
commit | f3af71c947cdf2e5acd16cacf50586b829a68f6e (patch) | |
tree | 3c1672c317ae47228a344c45e7576d0d1b89bbde /gpg-interface.c | |
parent | 78d468f1a9c7bf9d1724840ff322b9144061b308 (diff) | |
download | git-f3af71c947cdf2e5acd16cacf50586b829a68f6e.tar.gz |
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 <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'gpg-interface.c')
-rw-r--r-- | gpg-interface.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/gpg-interface.c b/gpg-interface.c index c60b9cd19d..800d8caa67 100644 --- a/gpg-interface.c +++ b/gpg-interface.c @@ -711,6 +711,7 @@ static char *get_ssh_key_fingerprint(const char *signing_key) int ret = -1; struct strbuf fingerprint_stdout = STRBUF_INIT; struct strbuf **fingerprint; + char *fingerprint_ret; /* * 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) die_errno(_("failed to get the ssh fingerprint for key '%s'"), signing_key); - return strbuf_detach(fingerprint[1], NULL); + fingerprint_ret = strbuf_detach(fingerprint[1], NULL); + strbuf_list_free(fingerprint); + strbuf_release(&fingerprint_stdout); + return fingerprint_ret; } /* Returns the first public key from an ssh-agent to use for signing */ |