summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Kåre Alsaker <john.kare.alsaker@gmail.com>2012-10-16 20:32:19 +0200
committerKristian Høgsberg <krh@bitplanet.net>2012-10-17 16:46:15 -0400
commit0a6fabecd7f2b15cb320414d37f29a007f6e171a (patch)
tree1019e23376e38d118964b809c945562660c936bd
parent009d452432dd3550d2db0d931dc39769939f3ddf (diff)
wayland-server: Fix up error handling with client creation.
-rw-r--r--src/wayland-server.c41
1 files changed, 26 insertions, 15 deletions
diff --git a/src/wayland-server.c b/src/wayland-server.c
index 41560f2..acbab9a 100644
--- a/src/wayland-server.c
+++ b/src/wayland-server.c
@@ -341,33 +341,41 @@ wl_client_create(struct wl_display *display, int fd)
WL_EVENT_READABLE,
wl_client_connection_data, client);
+ if (!client->source)
+ goto err_client;
+
len = sizeof client->ucred;
if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED,
- &client->ucred, &len) < 0) {
- free(client);
- return NULL;
- }
+ &client->ucred, &len) < 0)
+ goto err_source;
client->connection = wl_connection_create(fd);
- if (client->connection == NULL) {
- free(client);
- return NULL;
- }
+ if (client->connection == NULL)
+ goto err_source;
wl_map_init(&client->objects);
- if (wl_map_insert_at(&client->objects, 0, NULL) < 0) {
- wl_map_release(&client->objects);
- free(client);
- return NULL;
- }
+ if (wl_map_insert_at(&client->objects, 0, NULL) < 0)
+ goto err_map;
wl_signal_init(&client->destroy_signal);
bind_display(client, display, 1, 1);
+ if (!client->display_resource)
+ goto err_map;
+
wl_list_insert(display->client_list.prev, &client->link);
return client;
+
+err_map:
+ wl_map_release(&client->objects);
+ wl_connection_destroy(client->connection);
+err_source:
+ wl_event_source_remove(client->source);
+err_client:
+ free(client);
+ return NULL;
}
WL_EXPORT void
@@ -1058,7 +1066,9 @@ bind_display(struct wl_client *client,
client->display_resource =
wl_client_add_object(client, &wl_display_interface,
&display_interface, id, display);
- client->display_resource->destroy = destroy_client_display_resource;
+
+ if(client->display_resource)
+ client->display_resource->destroy = destroy_client_display_resource;
}
WL_EXPORT struct wl_display *
@@ -1230,7 +1240,8 @@ socket_data(int fd, uint32_t mask, void *data)
if (client_fd < 0)
wl_log("failed to accept: %m\n");
else
- wl_client_create(display, client_fd);
+ if (!wl_client_create(display, client_fd))
+ close(client_fd);
return 1;
}