Skip to contentSkip to conversation

lib/assoc_array: fix stale nr_leaves_on_tree after gc

PATCH New Josh Law 1 participant 1 message Mar 18 Library code

lore
Share & tools
lore

Josh Law

author
#0 lore raw

PATCH 1/1 lib/assoc_array: fix stale nr_leaves_on_tree after gc

In assoc_array_gc(), assoc_array_apply_edit() publishes the new tree root before nr_leaves_on_tree is updated, creating a window where the tree is visible with a stale leaf count. Move the nr_leaves_on_tree assignment before assoc_array_apply_edit() so the count is consistent when the new root becomes visible.

---
 lib/assoc_array.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/assoc_array.c +1 -1
index bcc6e0a013eb..0752fd44e066 100644
@@ -1711,8 +1711,8 @@ int assoc_array_gc(struct assoc_array *array,
 
 gc_complete:
 	edit->set[0].to = new_root;
-	assoc_array_apply_edit(edit);
 	array->nr_leaves_on_tree = nr_leaves_on_tree;
+	assoc_array_apply_edit(edit);
 	return 0;
 
 enomem:
Signature · 1 line
2.34.1