]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
memanalyze: fix warnings
authorViktor Szakats <commit@vsz.me>
Mon, 28 Jul 2025 07:49:21 +0000 (09:49 +0200)
committerViktor Szakats <commit@vsz.me>
Mon, 28 Jul 2025 10:43:02 +0000 (12:43 +0200)
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

tests/memanalyze.pl

index e1eaf0c9472f6d56fed685a8cb4437a8fc84d46d..f0ebd7fbaff0bdd9dc73fe4b0d3a1f6b15c0d033 100755 (executable)
@@ -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]*)/) {