[PATCH weston 4/4] compositor-drm: Use drm_destroy to clean up during init

Daniel Stone daniel at fooishbar.org
Mon Jun 18 11:10:33 PDT 2012


If we fail initialisation for any reason, use drm_destroy to clean up
rather than just returning NULL, so we don't leave people stranded at a
dead TTY that not even chvt can switch away from.

Signed-off-by: Daniel Stone <daniel at fooishbar.org>
---
 src/compositor-drm.c |   12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/compositor-drm.c b/src/compositor-drm.c
index d1715c6..6ffff1f 100644
--- a/src/compositor-drm.c
+++ b/src/compositor-drm.c
@@ -1783,6 +1783,7 @@ drm_compositor_create(struct wl_display *display,
 	ec->udev = udev_new();
 	if (ec->udev == NULL) {
 		weston_log("failed to initialize udev context\n");
+		drm_destroy(&ec->base);
 		return NULL;
 	}
 
@@ -1790,7 +1791,7 @@ drm_compositor_create(struct wl_display *display,
 	ec->tty = tty_create(&ec->base, vt_func, tty);
 	if (!ec->tty) {
 		weston_log("failed to initialize tty\n");
-		free(ec);
+		drm_destroy(&ec->base);
 		return NULL;
 	}
 
@@ -1816,11 +1817,13 @@ drm_compositor_create(struct wl_display *display,
 
 	if (drm_device == NULL) {
 		weston_log("no drm device found\n");
+		drm_destroy(&ec->base);
 		return NULL;
 	}
 
 	if (init_egl(ec, drm_device) < 0) {
 		weston_log("failed to initialize egl\n");
+		drm_destroy(&ec->base);
 		return NULL;
 	}
 
@@ -1832,8 +1835,10 @@ drm_compositor_create(struct wl_display *display,
 
 	/* Can't init base class until we have a current egl context */
 	if (weston_compositor_init(&ec->base, display, argc, argv,
-				   config_file) < 0)
+				   config_file) < 0) {
+		drm_destroy(&ec->base);
 		return NULL;
+	}
 
 	for (key = KEY_F1; key < KEY_F9; key++)
 		weston_compositor_add_key_binding(&ec->base, key,
@@ -1845,6 +1850,7 @@ drm_compositor_create(struct wl_display *display,
 
 	if (create_outputs(ec, connector, drm_device) < 0) {
 		weston_log("failed to create output for %s\n", path);
+		drm_destroy(&ec->base);
 		return NULL;
 	}
 
@@ -1862,6 +1868,7 @@ drm_compositor_create(struct wl_display *display,
 	ec->udev_monitor = udev_monitor_new_from_netlink(ec->udev, "udev");
 	if (ec->udev_monitor == NULL) {
 		weston_log("failed to intialize udev monitor\n");
+		drm_destroy(&ec->base);
 		return NULL;
 	}
 	udev_monitor_filter_add_match_subsystem_devtype(ec->udev_monitor,
@@ -1873,6 +1880,7 @@ drm_compositor_create(struct wl_display *display,
 
 	if (udev_monitor_enable_receiving(ec->udev_monitor) < 0) {
 		weston_log("failed to enable udev-monitor receiving\n");
+		drm_destroy(&ec->base);
 		return NULL;
 	}
 
-- 
1.7.10



More information about the wayland-devel mailing list