Re: [PATCH] lib/assoc_array: fix stale nr_leaves_on_tree after gc
From: Andrew Morton
Date: Wed Mar 18 2026 - 14:53:40 EST
On Wed, 18 Mar 2026 17:29:10 +0000 Josh Law <objecting@xxxxxxxxxxxxx> wrote:
> >
> >But assoc_array_apply_edit() alters array->nr_leaves_on_tree and now we
> >immediately overwrite that alteration?
>
>
> Hi Andrew,
>
> It probably doesn't overwrite it in this specific case.
>
>
> In assoc_array_gc(), the edit script is zero-initialized, meaning edit->adjust_count_on is NULL. Because of this (and since array->root isn't NULL), assoc_array_apply_edit() safely skips the block that modifies nr_leaves_on_tree.
wordwrapping, please.
> Since apply_edit() doesn't touch the count here, the explicit assignment right after is necessary to record the newly calculated post-GC count.
How about asking the author of this code?