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: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2367>
This commit is contained in:
Sebastian Keller 2022-07-06 19:34:23 +02:00 committed by Marge Bot
parent 9ebde6ca2d
commit fb75120a39

View File

@ -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);