Skip to content

Commit 083fd1a

Browse files
avargitster
authored andcommitted
dir.c: free "ident" and "exclude_per_dir" in "struct untracked_cache"
When the "ident" member of the structure was added in 1e8fef6 (untracked cache: guard and disable on system changes, 2015-03-08) this function wasn't updated to free it. Let's do so. Let's also free the "exclude_per_dir" memory we've been leaking since[1], while making sure not to free() the constant ".gitignore" string we add by default[2]. As we now have three struct members we're freeing let's change free_untracked_cache() to return early if "uc" isn't defined. We won't hand it to free() now, but that was just for convenience, once we're dealing with >=2 struct members this pattern is more convenient. 1. f9e6c64 (untracked cache: load from UNTR index extension, 2015-03-08) 2. 039bc64 (core.excludesfile clean-up, 2007-11-14) Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Taylor Blau <[email protected]>
1 parent b5fcb1c commit 083fd1a

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

dir.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3581,8 +3581,12 @@ static void free_untracked(struct untracked_cache_dir *ucd)
35813581

35823582
void free_untracked_cache(struct untracked_cache *uc)
35833583
{
3584-
if (uc)
3585-
free_untracked(uc->root);
3584+
if (!uc)
3585+
return;
3586+
3587+
free(uc->exclude_per_dir_to_free);
3588+
strbuf_release(&uc->ident);
3589+
free_untracked(uc->root);
35863590
free(uc);
35873591
}
35883592

@@ -3739,7 +3743,7 @@ struct untracked_cache *read_untracked_extension(const void *data, unsigned long
37393743
next + offset + hashsz);
37403744
uc->dir_flags = get_be32(next + ouc_offset(dir_flags));
37413745
exclude_per_dir = (const char *)next + exclude_per_dir_offset;
3742-
uc->exclude_per_dir = xstrdup(exclude_per_dir);
3746+
uc->exclude_per_dir = uc->exclude_per_dir_to_free = xstrdup(exclude_per_dir);
37433747
/* NUL after exclude_per_dir is covered by sizeof(*ouc) */
37443748
next += exclude_per_dir_offset + strlen(exclude_per_dir) + 1;
37453749
if (next >= end)

dir.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ struct untracked_cache {
188188
struct oid_stat ss_info_exclude;
189189
struct oid_stat ss_excludes_file;
190190
const char *exclude_per_dir;
191+
char *exclude_per_dir_to_free;
191192
struct strbuf ident;
192193
/*
193194
* dir_struct#flags must match dir_flags or the untracked

0 commit comments

Comments
 (0)