summaryrefslogtreecommitdiff
path: root/src/attrcache.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@github.com>2017-01-23 23:00:00 +0000
committerEdward Thomson <ethomson@github.com>2017-01-23 23:23:54 +0000
commit7f66a70eec3db66fba3dd4a73d5a0151546d2a2f (patch)
treefdd21e4981e33dbf069d5c2b7d09baee46d6ef5e /src/attrcache.c
parenta0d384798312df3b2c79194ced81bf5a3d2afddc (diff)
downloadlibgit2-7f66a70eec3db66fba3dd4a73d5a0151546d2a2f.tar.gz
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.
Diffstat (limited to 'src/attrcache.c')
-rw-r--r--src/attrcache.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/attrcache.c b/src/attrcache.c
index 0ade38c7c..cf0707ef0 100644
--- a/src/attrcache.c
+++ b/src/attrcache.c
@@ -121,20 +121,22 @@ static int attr_cache_remove(git_attr_cache *cache, git_attr_file *file)
{
int error = 0;
git_attr_file_entry *entry;
+ git_attr_file *old = NULL;
if (!file)
return 0;
+
if ((error = attr_cache_lock(cache)) < 0)
return error;
if ((entry = attr_cache_lookup_entry(cache, file->entry->path)) != NULL)
- file = git__compare_and_swap(&entry->file[file->source], file, NULL);
+ old = git__compare_and_swap(&entry->file[file->source], file, NULL);
attr_cache_unlock(cache);
- if (file) {
- GIT_REFCOUNT_OWN(file, NULL);
- git_attr_file__free(file);
+ if (old) {
+ GIT_REFCOUNT_OWN(old, NULL);
+ git_attr_file__free(old);
}
return error;