Skip to content

Commit

Permalink
fixup! Win32: add a cache below mingw's lstat and dirent implementations
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>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
  • Loading branch information
dscho committed Jun 13, 2017
1 parent 13f583b commit a36e14b
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

5 comments on commit a36e14b

@orgads
Copy link

@orgads orgads commented on a36e14b Jun 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@dscho
Copy link
Member Author

@dscho dscho commented on a36e14b Jun 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@orgads
Copy link

@orgads orgads commented on a36e14b Jun 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it works.

@dscho
Copy link
Member Author

@dscho dscho commented on a36e14b Jun 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@orgads
Copy link

@orgads orgads commented on a36e14b Jun 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Please sign in to comment.