summaryrefslogtreecommitdiff
path: root/builtin/worktree.c
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2017-05-04 13:59:13 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-05-08 03:18:20 (GMT)
commit2e11f58fa6a0c904d9b00e51cfb2d8a3ee77b360 (patch)
tree268786c219d42ae0975509ddbc4ac6fe2731d16a /builtin/worktree.c
parent5308224633cf138f436357b2a8a87a546373af72 (diff)
downloadgit-2e11f58fa6a0c904d9b00e51cfb2d8a3ee77b360.zip
git-2e11f58fa6a0c904d9b00e51cfb2d8a3ee77b360.tar.gz
git-2e11f58fa6a0c904d9b00e51cfb2d8a3ee77b360.tar.bz2
show_worktree(): plug memory leak
The buffer allocated by shorten_unambiguous_ref() needs to be released. Discovered by Coverity. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/worktree.c')
-rw-r--r--builtin/worktree.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/builtin/worktree.c b/builtin/worktree.c
index 1722a9b..ff5dfd2 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -414,9 +414,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);