Skip to content

Commit d57690a

Browse files
ffyuandagitster
authored andcommitted
mv: free the with_slash in check_dir_in_index()
with_slash may be a malloc'd pointer, and when it is, free it. Helped-by: Derrick Stolee <[email protected]> Helped-by: Victoria Dye <[email protected]> Signed-off-by: Shaoxuan Yuan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 72e59ba commit d57690a

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

builtin/mv.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ static int index_range_of_same_dir(const char *src, int length,
133133
*/
134134
static int empty_dir_has_sparse_contents(const char *name)
135135
{
136+
int ret = 0;
136137
const char *with_slash = add_slash(name);
137138
int length = strlen(with_slash);
138139

@@ -142,14 +143,18 @@ static int empty_dir_has_sparse_contents(const char *name)
142143
if (pos < 0) {
143144
pos = -pos - 1;
144145
if (pos >= the_index.cache_nr)
145-
return 0;
146+
goto free_return;
146147
ce = active_cache[pos];
147148
if (strncmp(with_slash, ce->name, length))
148-
return 0;
149+
goto free_return;
149150
if (ce_skip_worktree(ce))
150-
return 1;
151+
ret = 1;
151152
}
152-
return 0;
153+
154+
free_return:
155+
if (with_slash != name)
156+
free((char *)with_slash);
157+
return ret;
153158
}
154159

155160
int cmd_mv(int argc, const char **argv, const char *prefix)

0 commit comments

Comments
 (0)