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.
This commit is contained in:
Daniel Stenberg 2025-11-27 12:47:08 +01:00
parent c7ca9ba1ac
commit bc1d4414b2
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2

View file

@ -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--;
}