mirror of
https://github.com/swaywm/sway.git
synced 2024-11-25 09:21:28 +00:00
desktop/surface: Fix crash when timer is NULL
When many surfaces are created, sway can run out of file descriptors, making wl_event_loop_add_timer (which creates a timerfd) fail and return NULL. This patch posts a "no memory" error when that is the case, and only removes the timer if it was created. (Why "no memory"? It is not easy to distinguish between failures due to running out of memory and failures due to running out of file descriptors. Also, using the newer `wl_client_post_implementation_error` function would lead to an increased version requirement for the libwayland-server dependency.)
This commit is contained in:
parent
aa8fe58421
commit
1d483c340d
|
@ -11,7 +11,9 @@ void handle_destroy(struct wl_listener *listener, void *data) {
|
|||
surface->wlr_surface->data = NULL;
|
||||
wl_list_remove(&surface->destroy.link);
|
||||
|
||||
wl_event_source_remove(surface->frame_done_timer);
|
||||
if (surface->frame_done_timer) {
|
||||
wl_event_source_remove(surface->frame_done_timer);
|
||||
}
|
||||
|
||||
free(surface);
|
||||
}
|
||||
|
@ -38,4 +40,7 @@ void handle_compositor_new_surface(struct wl_listener *listener, void *data) {
|
|||
|
||||
surface->frame_done_timer = wl_event_loop_add_timer(server.wl_event_loop,
|
||||
surface_frame_done_timer_handler, surface);
|
||||
if (!surface->frame_done_timer) {
|
||||
wl_resource_post_no_memory(wlr_surface->resource);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue