]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
_dbus_check_fdleaks_leave: Try to describe what the leaked fd is
authorSimon McVittie <smcv@collabora.com>
Tue, 10 Dec 2024 13:54:00 +0000 (13:54 +0000)
committerSimon McVittie <smcv@collabora.com>
Wed, 11 Dec 2024 12:48:37 +0000 (12:48 +0000)
Similar to ebf487ef, but in a different situation.

Signed-off-by: Simon McVittie <smcv@collabora.com>
test/test-utils.c

index 05df7b955508b8e768fb93eeb03eb3ebdd7fad75..0ce557fc035c9e71e9c52a5cf247bfde6955ca56 100644 (file)
@@ -606,6 +606,9 @@ _dbus_check_fdleaks_leave (DBusInitialFDs *fds,
 
       while ((de = readdir(d)))
         {
+          char description[256] = { 0 };
+          char proc_self_fd[256] = { 0 };
+          size_t description_length = sizeof (description) - 1;
           long l;
           char *e = NULL;
           int fd;
@@ -635,7 +638,17 @@ _dbus_check_fdleaks_leave (DBusInitialFDs *fds,
           if (FD_ISSET (fd, &fds->set))
             continue;
 
-          _dbus_test_fatal ("file descriptor %i leaked in %s.", fd, context);
+          snprintf (proc_self_fd, sizeof (proc_self_fd) - 1,
+                    "/proc/self/fd/%ld", l);
+          proc_self_fd[sizeof (proc_self_fd) - 1] = '\0';
+
+          if (readlink (proc_self_fd, description, description_length) <= 0)
+            snprintf (description, sizeof (description) - 1, "(unknown)");
+
+          description[sizeof (description) - 1] = '\0';
+
+          _dbus_test_fatal ("file descriptor %i \"%s\" leaked in %s.",
+                            fd, description, context);
         }
 
       closedir (d);