From: Viktor Szakats Date: Mon, 28 Jul 2025 07:49:21 +0000 (+0200) Subject: memanalyze: fix warnings X-Git-Tag: curl-8_16_0~361 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9a68a86ea3626d5175d9dc9b521c969d80b7771d;p=thirdparty%2Fcurl.git memanalyze: fix warnings Also fix possibly missing reallocated memory from 'Total allocated': ``` Use of uninitialized value $size in addition (+) at tests/memanalyze.pl line 240, <$fileh> line 4. ``` Ref: https://github.com/curl/curl/actions/runs/16565283280/job/46843800711?pr=18049#step:39:3834 Ref: https://github.com/curl/curl/actions/runs/16556860012/job/46819517495?pr=17927#step:39:156 Follow-up to fc98a630cfb27dd097b31b57aa59fb578b390063 #18048 Follow-up to 2ec54556d4e3f3ab551b5298adab0c703d85a463 #17877 Closes #18049 --- diff --git a/tests/memanalyze.pl b/tests/memanalyze.pl index e1eaf0c947..f0ebd7fbaf 100755 --- a/tests/memanalyze.pl +++ b/tests/memanalyze.pl @@ -29,6 +29,9 @@ # MEM mprintf.c:1103 realloc(e5718, 64) = e6118 # MEM sendf.c:232 free(f6520) +use strict; +use warnings; + my $mallocs=0; my $callocs=0; my $reallocs=0; @@ -60,15 +63,15 @@ while(@ARGV) { } } -my $memsum; # the total number of memory allocated over the lifetime -my $maxmem; # the high water mark +my $memsum = 0; # the total number of memory allocated over the lifetime +my $maxmem = 0; # the high water mark sub newtotal { my ($newtot)=@_; # count a max here if($newtot > $maxmem) { - $maxmem= $newtot; + $maxmem = $newtot; } } @@ -199,7 +202,7 @@ while(<$fileh>) { my $arg1 = $1; my $arg2 = $2; - if($sizeataddr{$addr}>0) { + if($sizeataddr{$addr} && $sizeataddr{$addr}>0) { # this means weeeeeirdo print "Mixed debug compile, rebuild curl now\n"; } @@ -221,14 +224,20 @@ while(<$fileh>) { elsif($function =~ /realloc\((\(nil\)|0x([0-9a-f]*)), (\d*)\) = 0x([0-9a-f]*)/) { my ($oldaddr, $newsize, $newaddr) = ($2, $3, $4); - $totalmem -= $sizeataddr{$oldaddr}; - if($trace) { - printf("REALLOC: %d less bytes and ", $sizeataddr{$oldaddr}); + if($oldaddr) { + my $oldsize = $sizeataddr{$oldaddr} ? $sizeataddr{$oldaddr} : 0; + + $totalmem -= $oldsize; + if($trace) { + printf("REALLOC: %d less bytes and ", $oldsize); + } + $sizeataddr{$oldaddr}=0; + + $getmem{$oldaddr}=""; } - $sizeataddr{$oldaddr}=0; $totalmem += $newsize; - $memsum += $size; + $memsum += $newsize; $sizeataddr{$newaddr}=$newsize; if($trace) { @@ -238,7 +247,6 @@ while(<$fileh>) { newtotal($totalmem); $reallocs++; - $getmem{$oldaddr}=""; $getmem{$newaddr}="$source:$linenum"; } elsif($function =~ /strdup\(0x([0-9a-f]*)\) \((\d*)\) = 0x([0-9a-f]*)/) {