esp32/main: Fix mp_deinit order.#17423
Conversation
Move `mp_deinit` to be called before `gc_sweep_all` to prevent `mp_deinit` from double freeing memory if `MICROPY_PORT_DEINIT_FUNC` is defined and the function tries to free memory already freed by `gc_sweep_all` Signed-off-by: Carlosgg <carlosgilglez@gmail.com>
|
I'm not sure this is the right thing to do. Once Can you provide a minimal example of the problem you are trying to solve? |
Deinit a So I've found What happens is that lvgl uses micropython garbage collector to allocate/free memory, so at soft-reset Note that moving
This includes the garbage collector I guess? |
Correct. It can't run because the GIL is released.
It sounds like lvgl should be changed so that it doesn't free memory in its deinit function. It should rely on lvgl can also use finalisers, which will always be run as part of |
Ah that was it, I've only needed to reset lvgl root pointers, |
Move
mp_deinitto be called beforegc_sweep_allto preventmp_deinitfrom double freeing memory ifMICROPY_PORT_DEINIT_FUNCis defined and the function tries to free memory already freed bygc_sweep_allSummary
Prevent a core panic on soft-reset caused by "double freeing" memory.
Testing
Tested with esp32 and lvgl/lv_binding_micropython#383
Trade-offs and Alternatives
Probably this PR #16063