From: Aki Tuomi Date: Mon, 13 Mar 2023 12:07:00 +0000 (+0200) Subject: lib: fd-util - Try to read link from procfs to see which file leaked X-Git-Tag: 2.4.0~2913 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f0b430eed8537d0ee2148934a3238e949943d5bf;p=thirdparty%2Fdovecot%2Fcore.git lib: fd-util - Try to read link from procfs to see which file leaked Makes it easier to determine why the leak occured. --- diff --git a/src/lib/fd-util.c b/src/lib/fd-util.c index 01315bc417..e5b689c4c1 100644 --- a/src/lib/fd-util.c +++ b/src/lib/fd-util.c @@ -2,6 +2,7 @@ #include "lib.h" #include "net.h" +#include "path-util.h" #include #include @@ -63,6 +64,12 @@ void fd_debug_verify_leaks(int first_fd, int last_fd) } if (fstat(fd, &st) == 0) { + const char *error; + const char *fname; + if (t_readlink(t_strdup_printf("/proc/self/fd/%d", fd), + &fname, &error) < 0) + fname = t_strdup_printf("", error); + #ifdef __APPLE__ /* OSX workaround: gettimeofday() calls shm_open() internally and the fd won't get closed on exec. @@ -72,14 +79,14 @@ void fd_debug_verify_leaks(int first_fd, int last_fd) continue; #endif #ifdef HAVE_SYS_SYSMACROS_H - i_error("Leaked file fd %d: dev %s.%s inode %s", - fd, dec2str(major(st.st_dev)), + i_error("Leaked file %s: fd %d dev %s.%s inode %s", + fname, fd, dec2str(major(st.st_dev)), dec2str(minor(st.st_dev)), dec2str(st.st_ino)); leaks = TRUE; continue; #else - i_error("Leaked file fd %d: dev %s inode %s", - fd, dec2str(st.st_dev), + i_error("Leaked file %s: fd %d dev %s inode %s", + fname, fd, dec2str(st.st_dev), dec2str(st.st_ino)); leaks = TRUE; continue;