[map] Fix bad memory access if hb_map.fini() was called twice.

This commit is contained in:
Garret Rieger 2022-01-14 16:20:31 -08:00 committed by Behdad Esfahbod
parent 8a69e00639
commit ff4e8c7eac
2 changed files with 15 additions and 5 deletions

View File

@ -131,11 +131,13 @@ struct hb_hashmap_t
} }
void fini_shallow () void fini_shallow ()
{ {
unsigned size = mask + 1; if (unlikely (!items)) {
for (unsigned i = 0; i < size; i++) unsigned size = mask + 1;
items[i].~item_t (); for (unsigned i = 0; i < size; i++)
hb_free (items); items[i].~item_t ();
items = nullptr; hb_free (items);
items = nullptr;
}
population = occupancy = 0; population = occupancy = 0;
} }
void fini () void fini ()

View File

@ -78,6 +78,14 @@ main (int argc, char **argv)
assert (v.get_population () == 2); assert (v.get_population () == 2);
} }
/* Test call fini() twice. */
{
hb_map_t s;
for (int i = 0; i < 16; i++)
s.set(i, i+1);
s.fini();
}
/* Test initializing from iterator. */ /* Test initializing from iterator. */
{ {
hb_map_t s; hb_map_t s;