From: Johannes Schindelin Date: Wed, 26 Apr 2017 20:21:59 GMT Subject: [PATCH 25/26] show_worktree(): plug memory leak Message-ID: <51890c396683ddc9485a44d50b8ccaf04e06a3e2.1493237937.git.johannes.schindelin@gmx.de> In-Reply-To: The buffer allocated by shorten_unambiguous_ref() needs to be released. Discovered by Coverity. Signed-off-by: Johannes Schindelin --- builtin/worktree.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/builtin/worktree.c b/builtin/worktree.c index 9993ded41aa..6bfd7ad5323 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -409,9 +409,11 @@ static void show_worktree(struct worktree *wt, int path_maxlen, int abbrev_len) find_unique_abbrev(wt->head_sha1, DEFAULT_ABBREV)); if (wt->is_detached) strbuf_addstr(&sb, "(detached HEAD)"); - else if (wt->head_ref) - strbuf_addf(&sb, "[%s]", shorten_unambiguous_ref(wt->head_ref, 0)); - else + else if (wt->head_ref) { + char *ref = shorten_unambiguous_ref(wt->head_ref, 0); + strbuf_addf(&sb, "[%s]", ref); + free(ref); + } else strbuf_addstr(&sb, "(error)"); } printf("%s\n", sb.buf); -- 2.12.2.windows.2.800.gede8f145e06