Skip to content

Commit ac070af

Browse files
authored
Merge pull request libgit2#5088 from pks-t/pks/cache-eviction-segfault
cache: fix cache eviction using deallocated key
2 parents bcb4d1d + add1743 commit ac070af

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/cache.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,8 @@ static void cache_evict_entries(git_cache *cache)
134134

135135
evict_count--;
136136
evicted_memory += evict->size;
137-
git_cached_obj_decref(evict);
138-
139137
git_oidmap_delete(cache->map, key);
138+
git_cached_obj_decref(evict);
140139
}
141140

142141
cache->used_memory -= evicted_memory;

tests/blame/simple.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,14 @@ void test_blame_simple__trivial_libgit2(void)
203203
check_blame_hunk_index(g_repo, g_blame, 49, 60, 1, 0, "d12299fe", "src/git.h");
204204
}
205205

206+
/* This was leading to segfaults on some systems during cache eviction. */
207+
void test_blame_simple__trivial_libgit2_under_cache_pressure(void)
208+
{
209+
ssize_t old_max_storage = git_cache__max_storage;
210+
git_cache__max_storage = 1024 * 1024;
211+
test_blame_simple__trivial_libgit2();
212+
git_cache__max_storage = old_max_storage;
213+
}
206214

207215
/*
208216
* $ git blame -n b.txt -L 8

0 commit comments

Comments
 (0)