Skip to content
Permalink
Browse files

fixup! Win32: add a cache below mingw's lstat and dirent implementations

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>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
  • Loading branch information...
dscho committed Jun 13, 2017
1 parent 13f583b commit a36e14b3aaa0ddb633c40a9c8483e6fe12d99616
Showing with 2 additions and 21 deletions.
  1. +2 −21 compat/win32/fscache.c
@@ -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);
}

/*

5 comments on commit a36e14b

@orgads

This comment has been minimized.

Copy link

replied Jun 14, 2017

This fixes a crash for me on git diff -- file. Please release soon.

@dscho

This comment has been minimized.

Copy link
Member Author

replied Jun 14, 2017

@orgads

This comment has been minimized.

Copy link

replied Jun 15, 2017

Yes, it works.

@dscho

This comment has been minimized.

Copy link
Member Author

replied Jun 15, 2017

v2.13.1(2) was released, with this fix as only change relative to v2.13.1.

@orgads

This comment has been minimized.

Copy link

replied Jun 15, 2017

Thanks!

Please sign in to comment.
You can’t perform that action at this time.