Skip to content

Commit 7093d08

Browse files
author
Kevin Willford
committed
fscache: fix crash when clearing the cache
fscache_clear was crashing because when using hashmap_iter_next method the next entry will be saved. Meanwhile the call to fscache_release will free the directory and the list of entries for the directory. This causes the next entry saved by the iter to be freed, invalid and the crash with the next loop iteration. This changes the clear to simple call hashmap_free to free the hashmap and all the entries and then call hashmap_init to reinitialize the hashmap for the next fscache use. The reason this is safe is fscache_clear is only called from fscache_enable when this cache is being disabled which is only called in preload_index after all the thread have exited. It is also guarded by the critical section mutex.
1 parent 0f0a44f commit 7093d08

File tree

1 file changed

+2
-21
lines changed

1 file changed

+2
-21
lines changed

compat/win32/fscache.c

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -238,32 +238,13 @@ static void fscache_add(struct fsentry *fse)
238238
hashmap_add(&map, fse);
239239
}
240240

241-
/*
242-
* Removes a directory listing from the cache.
243-
*/
244-
static void fscache_remove(struct fsentry *fse)
245-
{
246-
if (fse->list)
247-
fse = fse->list;
248-
249-
for (; fse; fse = fse->next)
250-
hashmap_remove(&map, fse, NULL);
251-
}
252-
253241
/*
254242
* Clears the cache.
255243
*/
256244
static void fscache_clear(void)
257245
{
258-
struct hashmap_iter iter;
259-
struct fsentry *fse;
260-
hashmap_disallow_rehash(&map, 1);
261-
hashmap_iter_init(&map, &iter);
262-
while ((fse = hashmap_iter_next(&iter))) {
263-
fscache_remove(fse);
264-
fsentry_release(fse);
265-
}
266-
hashmap_disallow_rehash(&map, 0);
246+
hashmap_free(&map, 1);
247+
hashmap_init(&map, (hashmap_cmp_fn)fsentry_cmp, 0);
267248
}
268249

269250
/*

0 commit comments

Comments
 (0)