5 ex_gui_reentrant_8c example
gullradriel edited this page 2026-10-09 00:51:57 +02:00

ex_gui_reentrant.c

n_gui_process_event re-entrancy regression test (headless). A button on_click that opens/raises another window reorders ctx->windows (n_gui_raise_window removes + re-pushes + re-sorts the window list). The mouse-release handler in n_gui_process_event iterates ctx->windows while firing that callback; firing it inline freed the LIST_NODE the iterator had already cached as "next", a use-after-free that crashed on the following step. This test reproduces the exact click (press then release over the button) headlessly and asserts the callback fired and the process survives, which under ASan fails loudly if the deferred-dispatch fix regresses.