close opened fd if an error occur.
---
src/wayland-server.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/src/wayland-server.c b/src/wayland-server.c
index 3c162d4..ce7bbff 100644
--- a/src/wayland-server.c
+++ b/src/wayland-server.c
@@ -1119,23 +1119,28 @@ _wl_display_add_socket(struct wl_display *display,
struct wl_socket *s)
size = offsetof (struct sockaddr_un, sun_path) +
strlen(s->addr.sun_path);
if (bind(s->fd, (struct sockaddr *) &s->addr, size) < 0) {
wl_log("bind() failed with error: %m\n");
- return -1;
+ goto err;
}
if (listen(s->fd, 1) < 0) {
wl_log("listen() failed with error: %m\n");
- return -1;
+ goto err;
}
s->source = wl_event_loop_add_fd(display->loop, s->fd,
WL_EVENT_READABLE,
socket_data, display);
- if (s->source == NULL) {
- return -1;
- }
+ if (s->source == NULL)
+ goto err;
wl_list_insert(display->socket_list.prev, &s->link);
return 0;
+
+err:
+ close(s->fd);
+ s->fd = -1;
+
+ return -1;
}
WL_EXPORT const char *
--
2.0.4
_______________________________________________
wayland-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/wayland-devel