From 872522abff84afceb5af3835bd8c3875de690674 Mon Sep 17 00:00:00 2001 From: Olivier Houchard Date: Fri, 8 Mar 2024 22:34:52 +0100 Subject: [PATCH] ck_rhs: Restore the probe number on memory allocation failure. 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. --- src/ck_rhs.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/ck_rhs.c b/src/ck_rhs.c index 1d6b0f0d..a575ee58 100644 --- a/src/ck_rhs.c +++ b/src/ck_rhs.c @@ -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; @@ -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; } @@ -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;