Skip to content

Commit

Permalink
ck_rhs: Restore the probe number on memory allocation failure.
Browse files Browse the repository at this point in the history
In ck_rhs_put_robin_hood(), if we try to grow the map, and fail, make
sure we restore the probe number for each entry we changed to what it
was.
This should fix github issue #217.
  • Loading branch information
cognet committed Mar 8, 2024
1 parent 4715581 commit 872522a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/ck_rhs.c
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,7 @@ ck_rhs_put_robin_hood(struct ck_rhs *hs,
long prev;
void *key;
long prevs[CK_RHS_MAX_RH];
int prev_probes[CK_RHS_MAX_RH];
unsigned int prevs_nb = 0;
unsigned int i;

Expand All @@ -938,8 +939,11 @@ ck_rhs_put_robin_hood(struct ck_rhs *hs,
if (ck_rhs_grow(hs, map->capacity << 1) == false) {
desc->in_rh = false;

for (i = 0; i < prevs_nb; i++)
for (i = 0; i < prevs_nb; i++) {

ck_rhs_set_probes(map, prevs[i], prev_probes[i]);
ck_rhs_unset_rh(map, prevs[i]);
}

return -1;
}
Expand All @@ -955,6 +959,7 @@ ck_rhs_put_robin_hood(struct ck_rhs *hs,
h = ck_rhs_get_first_offset(map, first, n_probes);
ck_rhs_map_bound_set(map, h, n_probes);
prev = orig_slot;
prev_probes[prevs_nb] = old_probes;
prevs[prevs_nb++] = prev;
n_probes = old_probes;
goto restart;
Expand Down

0 comments on commit 872522a

Please sign in to comment.