[PATCH 2/2] Handle OOM with signal events
Kristian Høgsberg
hoegsberg at gmail.com
Fri May 9 14:24:17 PDT 2014
On Fri, May 09, 2014 at 04:03:52PM +0200, Hardening wrote:
> 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));
We set all entries of signals[4], and they're going to be valid
signal source pointers or NULL if the allocation fails. No need to memset.
> 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])
We can just add the if condition to the existing loop, no need to
iterate in reverse.
Kristian
> + wl_event_source_remove(signals[i-1]);
> + }
>
> weston_compositor_xkb_destroy(ec);
>
> --
> 1.8.1.2
>
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel
More information about the wayland-devel
mailing list