Skip to content

Commit b822423

Browse files
drafnelgitster
authored andcommitted
wt-status.c: don't leak directory entries when processing untracked,ignored
When iterating through the list of directory entries, searching for untracked entries, only the entries added to the string_list were free'd. The rest (tracked or not matching the pathspec) were leaked. Ditto for the "ignored" loop. Rearrange the loops so that all entries are free'd. Signed-off-by: Brandon Casey <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d212cef commit b822423

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

wt-status.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -390,11 +390,9 @@ static void wt_status_collect_untracked(struct wt_status *s)
390390
fill_directory(&dir, s->pathspec);
391391
for (i = 0; i < dir.nr; i++) {
392392
struct dir_entry *ent = dir.entries[i];
393-
if (!cache_name_is_other(ent->name, ent->len))
394-
continue;
395-
if (!match_pathspec(s->pathspec, ent->name, ent->len, 0, NULL))
396-
continue;
397-
string_list_insert(&s->untracked, ent->name);
393+
if (cache_name_is_other(ent->name, ent->len) &&
394+
match_pathspec(s->pathspec, ent->name, ent->len, 0, NULL))
395+
string_list_insert(&s->untracked, ent->name);
398396
free(ent);
399397
}
400398

@@ -404,11 +402,9 @@ static void wt_status_collect_untracked(struct wt_status *s)
404402
fill_directory(&dir, s->pathspec);
405403
for (i = 0; i < dir.nr; i++) {
406404
struct dir_entry *ent = dir.entries[i];
407-
if (!cache_name_is_other(ent->name, ent->len))
408-
continue;
409-
if (!match_pathspec(s->pathspec, ent->name, ent->len, 0, NULL))
410-
continue;
411-
string_list_insert(&s->ignored, ent->name);
405+
if (cache_name_is_other(ent->name, ent->len) &&
406+
match_pathspec(s->pathspec, ent->name, ent->len, 0, NULL))
407+
string_list_insert(&s->ignored, ent->name);
412408
free(ent);
413409
}
414410
}

0 commit comments

Comments
 (0)