[PATCH 1/2] compositor: fix a memory leak of struct process_info

Ryo Munakata ryomnktml at gmail.com
Fri Feb 20 08:07:37 PST 2015


Cleanup functions of weston clients are never called
after wl_display_run(), so that some of process_info of clients will not be freed.

Signed-off-by: Ryo Munakata <ryomnktml at gmail.com>
---
 src/compositor.c | 24 +++++++++++++++++++++---
 src/compositor.h |  1 +
 2 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/src/compositor.c b/src/compositor.c
index 7085053..e4b5f5a 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -303,8 +303,8 @@ child_client_exec(int sockfd, const char *path)
 			path);
 }
 
-WL_EXPORT struct wl_client *
-weston_client_launch(struct weston_compositor *compositor,
+static struct wl_client *
+weston_client_launch_impl(struct weston_compositor *compositor,
 		     struct weston_process *proc,
 		     const char *path,
 		     weston_process_cleanup_func_t cleanup)
@@ -354,6 +354,16 @@ weston_client_launch(struct weston_compositor *compositor,
 	return client;
 }
 
+WL_EXPORT struct wl_client *
+weston_client_launch(struct weston_compositor *compositor,
+		     struct weston_process *proc,
+		     const char *path,
+		     weston_process_cleanup_func_t cleanup)
+{
+	proc->managed = false;
+	return weston_client_launch_impl(compositor, proc, path, cleanup);
+}
+
 struct process_info {
 	struct weston_process proc;
 	char *path;
@@ -398,7 +408,8 @@ weston_client_start(struct weston_compositor *compositor, const char *path)
 	if (!pinfo->path)
 		goto out_free;
 
-	client = weston_client_launch(compositor, &pinfo->proc, path,
+	pinfo->proc.managed = true;
+	client = weston_client_launch_impl(compositor, &pinfo->proc, path,
 				      process_handle_sigchld);
 	if (!client)
 		goto out_str;
@@ -4841,6 +4852,7 @@ int main(int argc, char *argv[])
 	struct wl_client *primary_client;
 	struct wl_listener primary_client_destroyed;
 	struct weston_seat *seat;
+	struct weston_process *p, *p_next;
 
 	const struct weston_option core_options[] = {
 		{ WESTON_OPTION_STRING, "backend", 'B', &backend },
@@ -5012,6 +5024,12 @@ out:
 	/* prevent further rendering while shutting down */
 	ec->state = WESTON_COMPOSITOR_OFFSCREEN;
 
+	wl_list_for_each_safe(p, p_next, &child_process_list, link) {
+		wl_list_remove(&p->link);
+		if (p->managed)
+			p->cleanup(p, 0);
+	}
+
 	wl_signal_emit(&ec->destroy_signal, ec);
 
 	weston_compositor_xkb_destroy(ec);
diff --git a/src/compositor.h b/src/compositor.h
index 47b6036..f1b630f 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -1398,6 +1398,7 @@ struct weston_process {
 	pid_t pid;
 	weston_process_cleanup_func_t cleanup;
 	struct wl_list link;
+	bool managed;
 };
 
 struct wl_client *
-- 
2.3.0



More information about the wayland-devel mailing list