Summary: | --log-file=FILE leads to apparent fd leak ("Open file descriptor 3: $LOGFILE") | ||
---|---|---|---|
Product: | [Developer tools] valgrind | Reporter: | Daniel Richard G. <skunk> |
Component: | memcheck | Assignee: | Julian Seward <jseward> |
Status: | RESOLVED FIXED | ||
Severity: | normal | CC: | ahajkova, mark, martinp.dipaola |
Priority: | NOR | ||
Version: | 3.8.0 | ||
Target Milestone: | --- | ||
Platform: | Compiled Sources | ||
OS: | Linux | ||
See Also: |
https://bugs.kde.org/show_bug.cgi?id=488379 https://bugs.kde.org/show_bug.cgi?id=202770 |
||
Latest Commit: | Version Fixed In: | ||
Sentry Crash Report: |
Description
Daniel Richard G.
2012-12-13 21:49:58 UTC
I can confirm the bug in the latest version of valgrind (commit 7f1127140). There is one catch if you want to reproduce it with the test suite: to make the output reproducible the tests close all the inherited file descriptors which sadly, hides the bug. To reproduce it, pick the test file "none/tests/fdleak_pipe.c" and comment out the macro "CLOSE_INHERITED_FDS". and recompile with "make check". Execute: ./vg-in-place --track-fds=yes --log-file=foo.log none/tests/fdleak_pipe cat foo.log This is the output that I've got: ==19349== Memcheck, a memory error detector ==19349== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. ==19349== Using Valgrind-3.19.0.GIT and LibVEX; rerun with -h for copyright info ==19349== Command: none/tests/fdleak_pipe ==19349== Parent PID: 19347 ==19349== ==19349== ==19349== FILE DESCRIPTORS: 6 open (3 std) at exit. ==19349== Open file descriptor 5: ==19349== at 0x4967C57: pipe (syscall-template.S:78) ==19349== by 0x10916F: main (fdleak_pipe.c:10) ==19349== ==19349== Open file descriptor 4: ==19349== at 0x4967C57: pipe (syscall-template.S:78) ==19349== by 0x10916F: main (fdleak_pipe.c:10) ==19349== ==19349== Open file descriptor 3: /home/user/forks/valgrind/foo.log ==19349== <inherited from parent> ==19349== ==19349== ==19349== HEAP SUMMARY: ==19349== in use at exit: 0 bytes in 0 blocks ==19349== total heap usage: 0 allocs, 0 frees, 0 bytes allocated ==19349== ==19349== All heap blocks were freed -- no leaks are possible ==19349== ==19349== For lists of detected and suppressed errors, rerun with: -s ==19349== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) commit fbd7596f8342f0b0fbbe088d960da839a8bdb839 Author: Mark Wielaard <mark@klomp.org> Date: Sun Jun 16 21:23:08 2024 +0200 Don't leave fds created with --log-file, --xml-file or --log-socket open prepare_sink_fd and prepare_sink_socket will create a new file descriptor for the output sink. finalize_sink_fd then copies the fd to the safe range, so it doesn't conflict with any application fds. If we created the original fd ourselves, it was a VgLogTo_File or VgLogTo_Socket, not VgLogTo_Fd, finalize_sink_fd should close it. Also close socket when connecting fails in VG_(connect_via_socket). Add a testcase for --log-file and --xml-file which prints output to /dev/stderr https://bugs.kde.org/show_bug.cgi?id=202770 https://bugs.kde.org/show_bug.cgi?id=311655 https://bugs.kde.org/show_bug.cgi?id=488379 Co-authored-by: Alexandra Hájková <ahajkova@redhat.com |