Skip to content

Commit

Permalink
fixup! fscache: optimize fscache_clear()
Browse files Browse the repository at this point in the history
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.

Signed-off-by: Kevin Willford <kewillf@microsoft.com>
  • Loading branch information
Kevin Willford authored and dscho committed Jun 6, 2017
1 parent 1fd9bb7 commit 91f19f3
Showing 1 changed file with 2 additions and 21 deletions.
23 changes: 2 additions & 21 deletions compat/win32/fscache.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,32 +238,13 @@ static void fscache_add(struct fsentry *fse)
hashmap_add(&map, fse);
}

/*
* Removes a directory listing from the cache.
*/
static void fscache_remove(struct fsentry *fse)
{
if (fse->list)
fse = fse->list;

for (; fse; fse = fse->next)
hashmap_remove(&map, fse, NULL);
}

/*
* Clears the cache.
*/
static void fscache_clear(void)
{
struct hashmap_iter iter;
struct fsentry *fse;
hashmap_disallow_rehash(&map, 1);
hashmap_iter_init(&map, &iter);
while ((fse = hashmap_iter_next(&iter))) {
fscache_remove(fse);
fsentry_release(fse);
}
hashmap_disallow_rehash(&map, 0);
hashmap_free(&map, 1);
hashmap_init(&map, (hashmap_cmp_fn)fsentry_cmp, 0);
}

/*
Expand Down

0 comments on commit 91f19f3

Please sign in to comment.