Skip to content

Commit

Permalink
wt-status.c: don't leak directory entries when processing untracked,i…
Browse files Browse the repository at this point in the history
…gnored

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 <drafnel@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Brandon Casey authored and Junio C Hamano committed Sep 27, 2010
1 parent d212cef commit b822423
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions wt-status.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,11 +390,9 @@ static void wt_status_collect_untracked(struct wt_status *s)
fill_directory(&dir, s->pathspec);
for (i = 0; i < dir.nr; i++) {
struct dir_entry *ent = dir.entries[i];
if (!cache_name_is_other(ent->name, ent->len))
continue;
if (!match_pathspec(s->pathspec, ent->name, ent->len, 0, NULL))
continue;
string_list_insert(&s->untracked, ent->name);
if (cache_name_is_other(ent->name, ent->len) &&
match_pathspec(s->pathspec, ent->name, ent->len, 0, NULL))
string_list_insert(&s->untracked, ent->name);
free(ent);
}

Expand All @@ -404,11 +402,9 @@ static void wt_status_collect_untracked(struct wt_status *s)
fill_directory(&dir, s->pathspec);
for (i = 0; i < dir.nr; i++) {
struct dir_entry *ent = dir.entries[i];
if (!cache_name_is_other(ent->name, ent->len))
continue;
if (!match_pathspec(s->pathspec, ent->name, ent->len, 0, NULL))
continue;
string_list_insert(&s->ignored, ent->name);
if (cache_name_is_other(ent->name, ent->len) &&
match_pathspec(s->pathspec, ent->name, ent->len, 0, NULL))
string_list_insert(&s->ignored, ent->name);
free(ent);
}
}
Expand Down

0 comments on commit b822423

Please sign in to comment.