From a609fdaea77a857ce924ecd1fc1891e85688e059 Mon Sep 17 00:00:00 2001 From: Ludovico de Nittis Date: Mon, 5 Oct 2020 12:13:36 +0200 Subject: [PATCH] flatpak-spawn: Close the file descriptors when are not needed anymore g_unix_fd_list_append() duplicates the given FD, so we need to close our copy, otherwise it might be left indefinitely open. Also, as soon as we send them over D-Bus, we need to unref the FD list to avoid keeping them open. Signed-off-by: Ludovico de Nittis --- src/flatpak-spawn.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/flatpak-spawn.c b/src/flatpak-spawn.c index 3e68a3f..592308a 100644 --- a/src/flatpak-spawn.c +++ b/src/flatpak-spawn.c @@ -520,6 +520,8 @@ add_paths_to_variant (GVariantBuilder *builder, GUnixFDList *fd_list, const GStr g_printerr ("Failed to add fd to list for %s: %s\n", paths[i], error->message); return FALSE; } + /* The GUnixFdList keeps a duplicate, so we should release the original */ + close (path_fd); g_variant_builder_add (builder, "h", handle); } @@ -711,6 +713,8 @@ main (int argc, g_printerr ("Can't append fd: %s\n", error->message); return 1; } + /* The GUnixFdList keeps a duplicate, so we should release the original */ + close (fd); g_variant_builder_add (fd_builder, "{uh}", fd, handle); } @@ -933,6 +937,10 @@ main (int argc, g_debug ("child_pid: %d", child_pid); + /* Release our reference to the fds, so that only the copy we sent over + * D-Bus remains open */ + g_clear_object (&fd_list); + loop = g_main_loop_new (NULL, FALSE); g_signal_connect (session_bus, "closed", G_CALLBACK (session_bus_closed_cb), loop);