From a105e0e36356fe3743975054e07318a93ec9bcb4 Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Thu, 21 May 2020 16:44:47 +0200 Subject: [PATCH] core: fix error handling in main The error handling at the `error:` label tears down the whole state. Thus, the state needs to be fully initialized in order for the tear down to succeed. Currently, if e.g. `sd_bus_open_user()` fails, a `segfault` is triggered by the tear down. This commit adds individual tear down code that only touches stuff that until that point was successfully initialized. --- src/core/main.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/core/main.c b/src/core/main.c index 6421b17..b86e79a 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -70,14 +70,15 @@ int main(int argc, char *argv[]) { ret = sd_bus_open_user(&bus); if (ret < 0) { logprint(ERROR, "dbus: failed to connect to user bus: %s", strerror(-ret)); - goto error; + return EXIT_FAILURE; } logprint(DEBUG, "dbus: connected"); struct wl_display *wl_display = wl_display_connect(NULL); if (!wl_display) { logprint(ERROR, "wayland: failed to connect to display"); - goto error; + sd_bus_unref(bus); + return EXIT_FAILURE; } logprint(DEBUG, "wlroots: wl_display connected"); @@ -85,7 +86,9 @@ int main(int argc, char *argv[]) { struct pw_loop *pw_loop = pw_loop_new(NULL); if (!pw_loop) { logprint(ERROR, "pipewire: failed to create loop"); - goto error; + wl_display_disconnect(wl_display); + sd_bus_unref(bus); + return EXIT_FAILURE; } logprint(DEBUG, "pipewire: pw_loop created");