An VG_fork() creates a pipe between parent and child to syncronize the
two processes. The parent wants to register the child pid before the
child can run. This is done in register_sigchld_ignore.
Make sure both the parent and the child close both the read and write
file descriptors so none leak.
https://bugs.kde.org/show_bug.cgi?id=479661
(cherry picked from commit
1263471efdf8405cb0f1a767c6af73bf2eaf7160)
202770 open fd at exit --log-socket=127.0.0.1:1500 with --track-fds=yes
311655 --log-file=FILE leads to apparent fd leak
453044 gbserver_tests failures in aarch64
+479661 Valgrind leaks file descriptors
486180 [MIPS] 'VexGuestArchState' has no member named 'guest_IP_AT_SYSCALL'
486293 memccpy false positives
486569 linux inotify_init syscall wrapper missing POST entry in syscall_table
return;
if (pid == 0) {
+ /* We are the child, close writing fd that we don't use. */
+ VG_(close)(fds[1]);
/* Before proceeding, ensure parent has recorded child PID in map
of SIGCHLD to ignore */
while (child_wait == 1)
}
}
+ /* Now close reading fd. */
VG_(close)(fds[0]);
return;
}
ht_sigchld_ignore = VG_(HT_construct)("ht.sigchld.ignore");
VG_(HT_add_node)(ht_sigchld_ignore, n);
+ /* We are the parent process, close read fd that we don't use. */
+ VG_(close)(fds[0]);
+
child_wait = 0;
if (VG_(write)(fds[1], &child_wait, sizeof(Int)) <= 0)
VG_(message)(Vg_DebugMsg,
"warning: Unable to record PID of internal process (write)\n");
+ /* Now close writing fd. */
VG_(close)(fds[1]);
}
threadederrno.vgtest \
timestamp.stderr.exp timestamp.vgtest \
tls.vgtest tls.stderr.exp tls.stdout.exp \
+ track-fds-exec-children.vgtest track-fds-exec-children.stderr.exp \
unit_debuglog.stderr.exp unit_debuglog.vgtest \
vgprintf.stderr.exp vgprintf.vgtest \
vgprintf_nvalgrind.stderr.exp vgprintf_nvalgrind.vgtest \
tls \
tls.so \
tls2.so \
+ track-fds-exec-children \
unit_debuglog \
valgrind_cpp_test \
vgprintf \
else
tls2_so_LDFLAGS = -shared
endif
+track_fds_exec_children_SOURCES = track-fds-exec-children.c
vgprintf_nvalgrind_SOURCES = vgprintf.c
vgprintf_nvalgrind_CFLAGS = ${AM_CFLAGS} -DNVALGRIND
--- /dev/null
+#include <unistd.h>
+#include <sys/wait.h>
+
+int main()
+{
+ pid_t pid = fork ();
+ if (pid == 0)
+ execlp("true", "true", NULL);
+
+ // Wait till true succeeds
+ wait (NULL);
+ return 0;
+}
--- /dev/null
+env: DEBUGINFOD_URLS=file:/dev/null
+prog: track-fds-exec-children
+vgopts: -q --track-fds=yes --trace-children=yes