This is continuation of
fix_all_session_vcol_exprs() works on expr_arena which allocates from table memory pool (TABLE::mem_root). Since expr_arena does not free its items until TABLE is destroyed, continuous work with virtual columns under some circumstances (FIXME: get test case from
MDEV-16039 or from main.default_session ) leads to memory leak until table is flushed.
The problem is common to use cases of long-living query arenas (FIXME: get more cases).
Discover the idea of making temporary query subarena with it's own item free-list. fix_fields() should run on that subarena and freeing its list will not delete items from the master arena. Freeing master arena items list should free subarena list as well. cleanup() procedure should be tied with that temporary subarena and remove all temporary pointers from master items. And either cleanup() process should automatically free temporary subarena or vice versa the subarena initiates cleanup() of master items. The final goal is that after subarena destroy there is no stale pointers in master items.
Another more straightforward approach is to destroy query arena on each command. The items are transferred to new arena via build_clone(). That approach is coupled with a number of problems: delayed insert, items clone does not do String::copy() for their properties, cached_table cleanup, proper name resolution context, etc. The proof-of-concept in bb-10.2-midenok-MDEV-25794 tries to fix them to some level of success.
Note that after this fix granular refix via VCOL_NOT_STRICTLY_DETERMINISTIC flags will not be needed.