@@ -180,6 +180,20 @@ func tinRuntimeDir() string {
180180 return filepath .Join (filepath .Dir (ex ), "runtime" )
181181}
182182
183+ // valgrindNssSuppressionsPath returns the path to the glibc-nss
184+ // suppressions file shipped alongside the tin binary, or "" when it
185+ // can't be located. Used by --valgrind to silence the linker-level
186+ // reachable blocks from getaddrinfo's lazy dlopen of nss / resolv
187+ // modules.
188+ func valgrindNssSuppressionsPath () string {
189+ p := filepath .Join (tinRuntimeDir (), "valgrind-glibc-nss.supp" )
190+ if _ , err := os .Stat (p ); err != nil {
191+ return ""
192+ }
193+
194+ return p
195+ }
196+
183197// stdlibDirForDirectives returns the effective stdlib path for $TIN_STDLIB expansion.
184198// Uses override if provided; otherwise falls back to <execDir>/stdlib.
185199func stdlibDirForDirectives (override string ) string {
@@ -2670,14 +2684,25 @@ func validateMemcheck(memcheck string) {
26702684func memcheckCmd (memcheck , binary string , binArgs ... string ) * exec.Cmd {
26712685 switch memcheck {
26722686 case "valgrind" :
2673- args := append ( []string {
2687+ vgArgs := []string {
26742688 "--error-exitcode=1" ,
26752689 "--leak-check=full" ,
26762690 "--errors-for-leak-kinds=all" ,
2677- binary ,
2678- }, binArgs ... )
2691+ }
2692+ // Suppress glibc's lazy nss/resolver dlopen bookkeeping: the
2693+ // first getaddrinfo() in a process loads libnss_*/libresolv via
2694+ // __libc_dlopen_mode -> _dl_open and keeps those mappings live
2695+ // until exit, which valgrind reports as "still reachable". The
2696+ // suppression file at runtime/valgrind-glibc-nss.supp anchors
2697+ // each rule at `_dl_open` so real leaks elsewhere still surface.
2698+ if suppPath := valgrindNssSuppressionsPath (); suppPath != "" {
2699+ vgArgs = append (vgArgs , "--suppressions=" + suppPath )
2700+ }
2701+
2702+ vgArgs = append (vgArgs , binary )
2703+ vgArgs = append (vgArgs , binArgs ... )
26792704
2680- return wrapExec ("valgrind" , args ... )
2705+ return wrapExec ("valgrind" , vgArgs ... )
26812706 case "leaks" :
26822707 args := append ([]string {"--atExit" , "--" , binary }, binArgs ... )
26832708
0 commit comments