Bug 488379 - --track-fds=yes generates errors that cannot be suppressed for valgrind internal --xml-file=
Summary: --track-fds=yes generates errors that cannot be suppressed for valgrind inter...
Status: RESOLVED FIXED
Alias: None
Product: valgrind
Classification: Developer tools
Component: memcheck (show other bugs)
Version: 3.23.0
Platform: Other Other
: NOR normal
Target Milestone: ---
Assignee: Julian Seward
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-06-11 18:53 UTC by Arnaud Desitter
Modified: 2024-06-17 16:02 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
Don't leave fds created with --log-file, --xml-file or --log-socket open (6.47 KB, text/plain)
2024-06-16 19:25 UTC, Mark Wielaard
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Arnaud Desitter 2024-06-11 18:53:33 UTC
Using valgrind 3.23 built from source on Linux:

$ /usr/local/bin/valgrind --version
valgrind-3.23.0
# testing /usr/bin/true without --track-fds=yes
$  /usr/local/bin/valgrind --xml=yes --xml-file=xxx --gen-suppressions=all --error-exitcode=111 /usr/bin/true && echo ok || echo fail
ok
# testing /usr/bin/true with --track-fds=yes
$  /usr/local/bin/valgrind --track-fds=yes --xml=yes --xml-file=xxx --gen-suppressions=all --error-exitcode=111 /usr/bin/true && echo ok || echo fail
==21042== (No origin, error cannot be suppressed)
==21042== (No origin, error cannot be suppressed)
==21042== (No origin, error cannot be suppressed)
==21042== (No origin, error cannot be suppressed)
==21042== (No origin, error cannot be suppressed)
==21042== (No origin, error cannot be suppressed)
==21042== (No origin, error cannot be suppressed)
==21042== (No origin, error cannot be suppressed)
==21042== (No origin, error cannot be suppressed)
==21042== (No origin, error cannot be suppressed)
fail

xxx contains most notably:
<error>
  <unique>0x4</unique>
  <tid>1</tid>
  <threadname>true</threadname>
  <kind>FdNotClosed</kind>
  <fd>3</fd>
  <path>.../xxx</path>
  <what>Open file descriptor 3: ../xxx</what>
</error>

This relates to the file opened by valgrind itself.
So using "--track-fds=yes --xml=yes --xml-file=xxx --error-exitcode=111" results in a non zero error code returned.
There is no way I can see to suppress the error using a suppression file. 
"--gen-suppressions=all" results in "==xxxx== (No origin, error cannot be suppressed)"

The new feature added in valgrind 3.23 by https://bugs.kde.org/show_bug.cgi?id=328563 does not work properly when using "--xml=yes --xml-file=filename" and "--error-exitcode=non-zero-error-code".
Comment 1 Mark Wielaard 2024-06-11 21:53:44 UTC
yes, --track-fds obviously should ignore the --xml-file=xxx file descriptors.
Thanks for reporting. Will investigate.
Comment 2 Mark Wielaard 2024-06-13 13:44:07 UTC
This is probably the same underlying issues as bug #311655
Comment 3 Mark Wielaard 2024-06-16 19:25:07 UTC
Created attachment 170559 [details]
Don't leave fds created with --log-file, --xml-file or  --log-socket open

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
Comment 4 Mark Wielaard 2024-06-17 16:02:51 UTC
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