From fb75120a392b846153d4eb9d6d3fde96a6d7b602 Mon Sep 17 00:00:00 2001 From: Sebastian Keller Date: Wed, 6 Jul 2022 19:34:23 +0200 Subject: [PATCH] shell/app: Fix small memory leak in get_pids() The iterator was pointing to NULL when going out of scope, leading to autofree not clearing the list. ==300183== 32 bytes in 2 blocks are definitely lost in loss record 14,798 of 38,939 ==300183== at 0x484586F: malloc (vg_replace_malloc.c:381) ==300183== by 0x4D7D980: g_malloc (gmem.c:127) ==300183== by 0x4D95AB3: g_slice_alloc (gslice.c:1074) ==300183== by 0x4D96D96: g_slist_prepend (gslist.c:282) ==300183== by 0x487854F: shell_app_get_windows (shell-app.c:794) ==300183== by 0x48791A1: shell_app_get_pids (shell-app.c:1201) ==300183== by 0x488B293: shell_window_tracker_get_app_from_pid (shell-window-tracker.c:702) ==300183== by 0x488B632: get_app_from_window_pid (shell-window-tracker.c:370) ==300183== by 0x488B632: get_app_for_window (shell-window-tracker.c:436) ==300183== by 0x488B632: track_window (shell-window-tracker.c:549) ==300183== by 0x4CDBB75: g_cclosure_marshal_VOID__OBJECTv (gmarshal.c:1910) ==300183== by 0x4CD8BE9: _g_closure_invoke_va (gclosure.c:893) ==300183== by 0x4CF2A28: g_signal_emit_valist (gsignal.c:3406) ==300183== by 0x4CF2C2C: g_signal_emit (gsignal.c:3553) Part-of: --- src/shell-app.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/shell-app.c b/src/shell-app.c index 96fe31bff..5c38a9c8d 100644 --- a/src/shell-app.c +++ b/src/shell-app.c @@ -1195,10 +1195,12 @@ GSList * shell_app_get_pids (ShellApp *app) { GSList *result; - g_autoptr (GSList) iter = NULL; + g_autoptr (GSList) windows = NULL; + GSList *iter; result = NULL; - for (iter = shell_app_get_windows (app); iter; iter = iter->next) + windows = shell_app_get_windows (app); + for (iter = windows; iter; iter = iter->next) { MetaWindow *window = iter->data; pid_t pid = meta_window_get_pid (window);