Skip to content

Commit 0d0ff65

Browse files
drafnelgitster
authored andcommitted
builtin/mv.c: plug miniscule memory leak
The "it" string would not be free'ed if base_name was non-NULL. Let's free it. Signed-off-by: Brandon Casey <drafnel@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 040a655 commit 0d0ff65

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

builtin/mv.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ static const char **copy_pathspec(const char *prefix, const char **pathspec,
2929
to_copy--;
3030
if (to_copy != length || base_name) {
3131
char *it = xmemdupz(result[i], to_copy);
32-
result[i] = base_name ? xstrdup(basename(it)) : it;
32+
if (base_name) {
33+
result[i] = xstrdup(basename(it));
34+
free(it);
35+
} else
36+
result[i] = it;
3337
}
3438
}
3539
return get_pathspec(prefix, result);

0 commit comments

Comments
 (0)