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>

Johannes Schindelin committed May 4, 2017 at 15:59 UTC 2e11f58fa6a0c904d9b00e51cfb2d8a3ee77b360
1 file changed +5 -3
builtin/worktree.c
+5 -3
@@ -414,9 +414,11 @@ static void show_worktree(struct worktree *wt, int path_maxlen, int abbrev_len)
414 find_unique_abbrev(wt->head_sha1, DEFAULT_ABBREV));
415 if (wt->is_detached)
416 strbuf_addstr(&sb, "(detached HEAD)");
417 - else if (wt->head_ref)
418 - strbuf_addf(&sb, "[%s]", shorten_unambiguous_ref(wt->head_ref, 0));
419 - else
417 + else if (wt->head_ref) {
418 + char *ref = shorten_unambiguous_ref(wt->head_ref, 0);
419 + strbuf_addf(&sb, "[%s]", ref);
420 + free(ref);
421 + } else
422 strbuf_addstr(&sb, "(error)");
423 }
424 printf("%s\n", sb.buf);