summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPekka Paalanen <ppaalanen@gmail.com>2011-12-22 16:52:37 +0200
committerKristian Høgsberg <krh@bitplanet.net>2011-12-22 10:40:39 -0500
commitaad1e190588a0edc5a39a9feba534e7a6d4532d4 (patch)
tree8275666d52e265c983dcf5ba1a8def5cb6af308a /src
parent1f58d155da09f66dc1eaaafafddae3312e71704f (diff)
server: destroy the socket event source on display destroy
On wl_display_add_socket(), the listening socket fd is added to the event loop. However, wl_event_source object is not stored and hence cannot be freed, resulting in a minor leak. Store wl_event_source pointer in struct wl_socket so we can track it, and destroy it on wl_display_destroy(). The event loop itself must be destroyed after destroying the event sources linked to it. Fixes a Valgrind reported memory leak. Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/wayland-server.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/wayland-server.c b/src/wayland-server.c
index 87e4ed5..415173b 100644
--- a/src/wayland-server.c
+++ b/src/wayland-server.c
@@ -51,6 +51,7 @@ struct wl_socket {
struct sockaddr_un addr;
char lock_addr[113];
struct wl_list link;
+ struct wl_event_source *source;
};
struct wl_client {
@@ -667,14 +668,15 @@ wl_display_destroy(struct wl_display *display)
struct wl_socket *s, *next;
struct wl_global *global, *gnext;
- wl_event_loop_destroy(display->loop);
wl_list_for_each_safe(s, next, &display->socket_list, link) {
+ wl_event_source_remove(s->source);
close(s->fd);
unlink(s->addr.sun_path);
close(s->fd_lock);
unlink(s->lock_addr);
free(s);
}
+ wl_event_loop_destroy(display->loop);
wl_list_for_each_safe(global, gnext, &display->global_list, link)
free(global);
@@ -858,9 +860,10 @@ wl_display_add_socket(struct wl_display *display, const char *name)
return -1;
}
- if (wl_event_loop_add_fd(display->loop, s->fd,
- WL_EVENT_READABLE,
- socket_data, display) == NULL) {
+ s->source = wl_event_loop_add_fd(display->loop, s->fd,
+ WL_EVENT_READABLE,
+ socket_data, display);
+ if (s->source == NULL) {
close(s->fd);
unlink(s->addr.sun_path);
free(s);