Skip to content

Commit 7f66a70

Browse files
author
Edward Thomson
committed
attr_cache_remove: don't remove given file
If `attr_cache_lookup_entry` fails to find the given file, make sure that we do not try to free the given file.
1 parent a0d3847 commit 7f66a70

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/attrcache.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,20 +121,22 @@ static int attr_cache_remove(git_attr_cache *cache, git_attr_file *file)
121121
{
122122
int error = 0;
123123
git_attr_file_entry *entry;
124+
git_attr_file *old = NULL;
124125

125126
if (!file)
126127
return 0;
128+
127129
if ((error = attr_cache_lock(cache)) < 0)
128130
return error;
129131

130132
if ((entry = attr_cache_lookup_entry(cache, file->entry->path)) != NULL)
131-
file = git__compare_and_swap(&entry->file[file->source], file, NULL);
133+
old = git__compare_and_swap(&entry->file[file->source], file, NULL);
132134

133135
attr_cache_unlock(cache);
134136

135-
if (file) {
136-
GIT_REFCOUNT_OWN(file, NULL);
137-
git_attr_file__free(file);
137+
if (old) {
138+
GIT_REFCOUNT_OWN(old, NULL);
139+
git_attr_file__free(old);
138140
}
139141

140142
return error;

0 commit comments

Comments
 (0)