Ooops I didn't sent you the latest version of the final patch :)

On Fri, Mar 11, 2011 at 4:54 PM, Iskren Chernev <[email protected]>wrote:

> Some resources were not freed if the create function exited earlier.
>
> I'm not sure how important these patches are. If they are I can make
> another pass on the code to fix similar errors. Also adding warn
> unused result to the creation functions that may fail will help
> spotting all places.
>
> Regards,
> Iskren
>
From a3a12fb522a8376a06c3fd7b81b923e02b1abc34 Mon Sep 17 00:00:00 2001
From: Iskren Chernev <[email protected]>
Date: Fri, 11 Mar 2011 16:59:53 +0200
Subject: [PATCH] Server socket creation error handling.

---
 wayland/wayland-server.c |   41 +++++++++++++++++++++++++++++------------
 1 files changed, 29 insertions(+), 12 deletions(-)

diff --git a/wayland/wayland-server.c b/wayland/wayland-server.c
index faa1e1a..036958f 100644
--- a/wayland/wayland-server.c
+++ b/wayland/wayland-server.c
@@ -659,8 +659,10 @@ wl_display_add_socket(struct wl_display *display, const char *name)
 		return -1;
 
 	s->fd = socket(PF_LOCAL, SOCK_STREAM, 0);
-	if (s->fd < 0)
+	if (s->fd < 0) {
+		free(s);
 		return -1;
+	}
 
 	runtime_dir = getenv("XDG_RUNTIME_DIR");
 	if (runtime_dir == NULL) {
@@ -682,15 +684,27 @@ wl_display_add_socket(struct wl_display *display, const char *name)
 	fprintf(stderr, "using socket %s\n", s->addr.sun_path);
 
 	size = offsetof (struct sockaddr_un, sun_path) + name_size;
-	if (bind(s->fd, (struct sockaddr *) &s->addr, size) < 0)
+	if (bind(s->fd, (struct sockaddr *) &s->addr, size) < 0) {
+		close(s->fd);
+		free(s);
 		return -1;
+	}
 
-	if (listen(s->fd, 1) < 0)
+	if (listen(s->fd, 1) < 0) {
+		close(s->fd);
+		unlink(s->addr.sun_path);
+		free(s);
 		return -1;
+	}
 
-	wl_event_loop_add_fd(display->loop, s->fd,
-			     WL_EVENT_READABLE,
-			     socket_data, display);
+	if (wl_event_loop_add_fd(display->loop, s->fd,
+				 WL_EVENT_READABLE,
+				 socket_data, display) == NULL) {
+		close(s->fd);
+		unlink(s->addr.sun_path);
+		free(s);
+		return -1;
+	}
 	wl_list_insert(display->socket_list.prev, &s->link);
 
 	return 0;
@@ -710,23 +724,26 @@ wl_compositor_init(struct wl_compositor *compositor,
 	compositor->argb_visual.object.interface = &wl_visual_interface;
 	compositor->argb_visual.object.implementation = NULL;
 	wl_display_add_object(display, &compositor->argb_visual.object);
-	wl_display_add_global(display, &compositor->argb_visual.object, NULL);
+	if (wl_display_add_global(display, &compositor->argb_visual.object, NULL))
+		return -1;
 
 	compositor->premultiplied_argb_visual.object.interface =
 		&wl_visual_interface;
 	compositor->premultiplied_argb_visual.object.implementation = NULL;
 	wl_display_add_object(display,
 			      &compositor->premultiplied_argb_visual.object);
-	wl_display_add_global(display,
-			      &compositor->premultiplied_argb_visual.object,
-			      NULL);
+	if (wl_display_add_global(display,
+				  &compositor->premultiplied_argb_visual.object,
+				  NULL))
+		return -1;
 
 	compositor->rgb_visual.object.interface = &wl_visual_interface;
 	compositor->rgb_visual.object.implementation = NULL;
 	wl_display_add_object(display,
 			      &compositor->rgb_visual.object);
-	wl_display_add_global(display,
-			      &compositor->rgb_visual.object, NULL);
+	if (wl_display_add_global(display,
+				  &compositor->rgb_visual.object, NULL))
+		return -1;
 
 	return 0;
 }
-- 
1.7.4

_______________________________________________
wayland-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/wayland-devel

Reply via email to