From bc1d4414b22ae744148536419ff1bc64eb577bfc Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 27 Nov 2025 12:47:08 +0100 Subject: [PATCH] memanalyze: tell if the same desriptor is returned again If a previous socket() got a certain file descriptor and there was no close in between, this indicates something is seriously wrong. --- tests/memanalyze.pl | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/memanalyze.pl b/tests/memanalyze.pl index 2b38e5e8a4..a51e0795cb 100755 --- a/tests/memanalyze.pl +++ b/tests/memanalyze.pl @@ -304,6 +304,10 @@ while(<$fileh>) { $function = $3; if($function =~ /socket\(\) = (\d*)/) { + my $fd = $1; + if($filedes{$fd}) { + print "Suspicious: socket() returns same descriptor *again* ($fd). Last created at ".$getfile{$fd}."\n"; + } $filedes{$1}=1; $getfile{$1}="$source:$linenum"; $openfile++; @@ -323,10 +327,15 @@ while(<$fileh>) { $openfile++; } elsif($function =~ /sclose\((\d*)\)/) { - if($filedes{$1} != 1) { + my $fd = $1; + if($filedes{$fd} != 1) { print "Close without open: $line\n"; } else { + if($trace) { + printf("CLOSE($fd) at $source:$linenum, created at ". + $getfile{$1}."\n"); + } $filedes{$1}=0; # closed now $openfile--; }