Wayland: destroyed objects and events

Olivier Fourdan ofourdan at redhat.com
Thu Nov 10 17:18:10 UTC 2022


Hi Maxim

On Thu, Nov 10, 2022 at 6:05 PM Maxim Kartashev
<maxim.kartashev at jetbrains.com> wrote:
>
> I was wondering if there's a good way of dealing with events that come from objects that are being concurrently destroyed. The scenario is as follows:
> let's say a callback is created like so
>   wl_frame_callback = wl_surface_frame(wl_surface);
>   payload = malloc(...);
>   wl_callback_add_listener(wl_frame_callback, &wl_frame_callback_listener, payload);
> and soon after that there's
>   wl_surface_destroy(wl_surface);
>   free(payload);
> It seems like if the frame event has already been "scheduled" to be fired at the point of wl_surface_destroy(), it might be actually delivered and the callback defined by wl_frame_callback_listener will get invoked with "payload" being free'ed already.
> Is there a good way to make sure wl_frame_callback will never fire past the point of wl_surface_destroy()?

I guess you could destroy the callback with wl_callback_destroy() so
it won't fire up again?

HTH
Cheers
Olivier



More information about the wakefield-dev mailing list