napperley
12/09/2021, 4:25 AMtmpArena.clear()
Alexander Shabalin [JB]
12/09/2021, 9:37 AMtmpArena.clear()
line isn't present, then two buttons with "Ok" and "Cancel" are displayed; and if tmpArena.clear()
is present right after the call to lv_msgbox_create
then two buttons are still displayed, but the first one doesn't have any text.Alexander Shabalin [JB]
12/09/2021, 10:05 AMlv_msgbox_create
just stores the contents of the btn_txts
pointer without copying its contents and then accesses it during drawing (1 2 3). So, if the memory behind btn_txts
pointer is freed before msgbox
is gone, use-after-free happens. This means, you cannot call tmpArena.clear()
until msgbox
is closed.napperley
12/09/2021, 10:10 PMtmpArena.clear()
line into the body of messageBoxCallback
function, and the issue doesn't occur 😄 . Was expecting a segmentation fault with the use after free issue. Quite unexpected that the program would continue to run.Alexander Shabalin [JB]
12/10/2021, 12:38 AMWas expecting a segmentation fault with the use after free issue.Segmentation fault is literally the best case scenario of use-after-free. Generally speaking, after use-after-free the program may behave in an entirely unpredictable fashion. If at all possible, try to use valgrind's memcheck when you suspect use-after-free or similar invalid memory access issues. The usage is quite straightforward:
valgrind --leak-check=no <path to the executable>
. Fair warning: it considerably slows down the execution.