Skip to content

Commit e4ba54d

Browse files
pks-tgitster
authored andcommitted
dir: release untracked cache data
There are several cases where we invalidate untracked cache directory entries where we do not free the underlying data, but reset the number of entries. This causes us to leak memory because `free_untracked()` will not iterate over any potential entries which we still had in the array. Fix this issue by freeing old entries. The leak is exposed by t7519, but plugging it alone does not make the whole test suite pass. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1981d1e commit e4ba54d

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

dir.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,8 @@ static void do_invalidate_gitignore(struct untracked_cache_dir *dir)
10561056
{
10571057
int i;
10581058
dir->valid = 0;
1059+
for (size_t i = 0; i < dir->untracked_nr; i++)
1060+
free(dir->untracked[i]);
10591061
dir->untracked_nr = 0;
10601062
for (i = 0; i < dir->dirs_nr; i++)
10611063
do_invalidate_gitignore(dir->dirs[i]);
@@ -1083,6 +1085,8 @@ static void invalidate_directory(struct untracked_cache *uc,
10831085
uc->dir_invalidated++;
10841086

10851087
dir->valid = 0;
1088+
for (size_t i = 0; i < dir->untracked_nr; i++)
1089+
free(dir->untracked[i]);
10861090
dir->untracked_nr = 0;
10871091
for (i = 0; i < dir->dirs_nr; i++)
10881092
dir->dirs[i]->recurse = 0;
@@ -3573,6 +3577,8 @@ static void write_one_dir(struct untracked_cache_dir *untracked,
35733577
* for safety..
35743578
*/
35753579
if (!untracked->valid) {
3580+
for (size_t i = 0; i < untracked->untracked_nr; i++)
3581+
free(untracked->untracked[i]);
35763582
untracked->untracked_nr = 0;
35773583
untracked->check_only = 0;
35783584
}
@@ -3905,6 +3911,8 @@ static void invalidate_one_directory(struct untracked_cache *uc,
39053911
{
39063912
uc->dir_invalidated++;
39073913
ucd->valid = 0;
3914+
for (size_t i = 0; i < ucd->untracked_nr; i++)
3915+
free(ucd->untracked[i]);
39083916
ucd->untracked_nr = 0;
39093917
}
39103918

0 commit comments

Comments
 (0)