Skip to content

Commit bb10afa

Browse files
committed
show_worktree(): plug memory leak
The buffer allocated by shorten_unambiguous_ref() needs to be released. Discovered by Coverity. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 994749c commit bb10afa

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

builtin/worktree.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -414,9 +414,11 @@ static void show_worktree(struct worktree *wt, int path_maxlen, int abbrev_len)
414414
find_unique_abbrev(wt->head_sha1, DEFAULT_ABBREV));
415415
if (wt->is_detached)
416416
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
420422
strbuf_addstr(&sb, "(error)");
421423
}
422424
printf("%s\n", sb.buf);

0 commit comments

Comments
 (0)