aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Manuel Stoeckl <code@mstoeckl.com>2019-12-23 19:17:06 -0500
committerLibravatar Simon Ser <contact@emersion.fr>2019-12-24 13:03:50 +0100
commit1d483c340d39ca75996729cfc6d5bb2b33cff2be (patch)
treefd475828a21222ca6db05a7600efab274117a6fb
parentLicense wallpapers as CC-0 (diff)
downloadsway-1d483c340d39ca75996729cfc6d5bb2b33cff2be.tar.gz
sway-1d483c340d39ca75996729cfc6d5bb2b33cff2be.tar.zst
sway-1d483c340d39ca75996729cfc6d5bb2b33cff2be.zip
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.)
-rw-r--r--sway/desktop/surface.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/sway/desktop/surface.c b/sway/desktop/surface.c
index 853c403d..35af2870 100644
--- a/sway/desktop/surface.c
+++ b/sway/desktop/surface.c
@@ -11,7 +11,9 @@ void handle_destroy(struct wl_listener *listener, void *data) {
11 surface->wlr_surface->data = NULL; 11 surface->wlr_surface->data = NULL;
12 wl_list_remove(&surface->destroy.link); 12 wl_list_remove(&surface->destroy.link);
13 13
14 wl_event_source_remove(surface->frame_done_timer); 14 if (surface->frame_done_timer) {
15 wl_event_source_remove(surface->frame_done_timer);
16 }
15 17
16 free(surface); 18 free(surface);
17} 19}
@@ -38,4 +40,7 @@ void handle_compositor_new_surface(struct wl_listener *listener, void *data) {
38 40
39 surface->frame_done_timer = wl_event_loop_add_timer(server.wl_event_loop, 41 surface->frame_done_timer = wl_event_loop_add_timer(server.wl_event_loop,
40 surface_frame_done_timer_handler, surface); 42 surface_frame_done_timer_handler, surface);
43 if (!surface->frame_done_timer) {
44 wl_resource_post_no_memory(wlr_surface->resource);
45 }
41} 46}