[PATCH 2/2] Handle OOM with signal events

Hardening rdp.effort at gmail.com
Fri May 9 07:03:52 PDT 2014


This patch handles the case where a signal event source can not be created.
---
 src/compositor.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/compositor.c b/src/compositor.c
index 6ad3387..047df8a 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -4197,6 +4197,7 @@ int main(int argc, char *argv[])
 	display = wl_display_create();
 
 	loop = wl_display_get_event_loop(display);
+	memset(signals, 0, sizeof(signals));
 	signals[0] = wl_event_loop_add_signal(loop, SIGTERM, on_term_signal,
 					      display);
 	signals[1] = wl_event_loop_add_signal(loop, SIGINT, on_term_signal,
@@ -4208,6 +4209,9 @@ int main(int argc, char *argv[])
 	signals[3] = wl_event_loop_add_signal(loop, SIGCHLD, sigchld_handler,
 					      NULL);
 
+	if (!signals[0] || !signals[1] || !signals[2] || !signals[3])
+		goto out_signals;
+
 	config = weston_config_parse("weston.ini");
 	if (config != NULL) {
 		weston_log("Using config file '%s'\n",
@@ -4321,8 +4325,11 @@ int main(int argc, char *argv[])
 
 	wl_signal_emit(&ec->destroy_signal, ec);
 
-	for (i = ARRAY_LENGTH(signals); i;)
-		wl_event_source_remove(signals[--i]);
+ out_signals:
+	for (i = ARRAY_LENGTH(signals); i; i--) {
+		if (signals[i-1])
+			wl_event_source_remove(signals[i-1]);
+	}
 
 	weston_compositor_xkb_destroy(ec);
 
-- 
1.8.1.2



More information about the wayland-devel mailing list