[neon/backports-focal/xdg-desktop-portal/Neon/unstable] src: request: Close file descriptors attached to the request

Bastien Nocera null at kde.org
Wed Jan 13 06:32:43 GMT 2021


Git commit ec05419a1647a9203d23c85d9770ae82a6e58167 by Bastien Nocera.
Committed on 20/07/2020 at 14:12.
Pushed by ash into branch 'Neon/unstable'.

request: Close file descriptors attached to the request

Track whether there are any opened file descriptors attached to the
request and close them when we unexport the request.

M  +8    -0    src/request.c

https://invent.kde.org/neon/backports-focal/xdg-desktop-portal/commit/ec05419a1647a9203d23c85d9770ae82a6e58167

diff --git a/src/request.c b/src/request.c
index 650d8ee..d21dbf5 100644
--- a/src/request.c
+++ b/src/request.c
@@ -355,6 +355,8 @@ request_init_invocation (GDBusMethodInvocation *invocation, XdpAppInfo *app_info
   request->sender = g_strdup (g_dbus_method_invocation_get_sender (invocation));
   request->app_info = xdp_app_info_ref (app_info);
 
+  g_object_set_data (G_OBJECT (request), "fd", GINT_TO_POINTER (-1));
+
   token = get_token (invocation);
   sender = g_strdup (request->sender + 1);
   for (i = 0; sender[i]; i++)
@@ -415,6 +417,12 @@ request_export (Request *request,
 void
 request_unexport (Request *request)
 {
+  int fd;
+
+  fd = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (request), "fd"));
+  if (fd != -1)
+    close (fd);
+
   request->exported = FALSE;
   g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (request));
   g_object_unref (request);



More information about the Neon-commits mailing list