Revert "Update to 7.44.0"
[platform/upstream/curl.git] / tests / memanalyze.pl
index b8f17b5..54117f8 100755 (executable)
@@ -1,4 +1,25 @@
 #!/usr/bin/env perl
+#***************************************************************************
+#                                  _   _ ____  _
+#  Project                     ___| | | |  _ \| |
+#                             / __| | | | |_) | |
+#                            | (__| |_| |  _ <| |___
+#                             \___|\___/|_| \_\_____|
+#
+# Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
+#
+# This software is licensed as described in the file COPYING, which
+# you should have received as part of this distribution. The terms
+# are also available at http://curl.haxx.se/docs/copyright.html.
+#
+# You may opt to use, copy, modify, merge, publish, distribute and/or sell
+# copies of the Software, and permit persons to whom the Software is
+# furnished to do so, under the terms of the COPYING file.
+#
+# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+# KIND, either express or implied.
+#
+###########################################################################
 #
 # Example input:
 #
@@ -10,6 +31,7 @@ my $mallocs=0;
 my $callocs=0;
 my $reallocs=0;
 my $strdups=0;
+my $wcsdups=0;
 my $showlimit;
 
 while(1) {
@@ -117,7 +139,7 @@ while(<FILE>) {
             if($sizeataddr{$addr}>0) {
                 # this means weeeeeirdo
                 print "Mixed debug compile ($source:$linenum at line $lnum), rebuild curl now\n";
-               print "We think $sizeataddr{$addr} bytes are already allocated at that memory address: $addr!\n";
+                print "We think $sizeataddr{$addr} bytes are already allocated at that memory address: $addr!\n";
             }
 
             $sizeataddr{$addr}=$size;
@@ -158,10 +180,8 @@ while(<FILE>) {
 
             $getmem{$addr}="$source:$linenum";
         }
-        elsif($function =~ /realloc\(0x([0-9a-f]*), (\d*)\) = 0x([0-9a-f]*)/) {
-            $oldaddr = $1;
-            $newsize = $2;
-            $newaddr = $3;
+        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) {
@@ -178,7 +198,7 @@ while(<FILE>) {
 
             newtotal($totalmem);
             $reallocs++;
-            
+
             $getmem{$oldaddr}="";
             $getmem{$newaddr}="$source:$linenum";
         }
@@ -194,16 +214,35 @@ while(<FILE>) {
             $totalmem += $size;
 
             if($trace) {
-                printf("STRDUP: $size bytes at %s, makes totally: %d bytes\n", 
+                printf("STRDUP: $size bytes at %s, makes totally: %d bytes\n",
                        $getmem{$addr}, $totalmem);
             }
 
             newtotal($totalmem);
             $strdups++;
         }
+        elsif($function =~ /wcsdup\(0x([0-9a-f]*)\) \((\d*)\) = 0x([0-9a-f]*)/) {
+            # wcsdup(a5b50) (8) = df7c0
+
+            $dup = $1;
+            $size = $2;
+            $addr = $3;
+            $getmem{$addr}="$source:$linenum";
+            $sizeataddr{$addr}=$size;
+
+            $totalmem += $size;
+
+            if($trace) {
+                printf("WCSDUP: $size bytes at %s, makes totally: %d bytes\n",
+                       $getmem{$addr}, $totalmem);
+            }
+
+            newtotal($totalmem);
+            $wcsdups++;
+        }
         else {
             print "Not recognized input line: $function\n";
-        }        
+        }
     }
     # FD url.c:1282 socket() = 5
     elsif($_ =~ /^FD ([^ ]*):(\d*) (.*)/) {
@@ -217,6 +256,14 @@ while(<FILE>) {
             $getfile{$1}="$source:$linenum";
             $openfile++;
         }
+        elsif($function =~ /socketpair\(\) = (\d*) (\d*)/) {
+            $filedes{$1}=1;
+            $getfile{$1}="$source:$linenum";
+            $openfile++;
+            $filedes{$2}=1;
+            $getfile{$2}="$source:$linenum";
+            $openfile++;
+        }
         elsif($function =~ /accept\(\) = (\d*)/) {
             $filedes{$1}=1;
             $getfile{$1}="$source:$linenum";
@@ -239,7 +286,7 @@ while(<FILE>) {
         $linenum = $2;
         $function = $3;
 
-        if($function =~ /fopen\(\"([^\"]*)\",\"([^\"]*)\"\) = (\(nil\)|0x([0-9a-f]*))/) {
+        if($function =~ /f[d]*open\(\"(.*)\",\"([^\"]*)\"\) = (\(nil\)|0x([0-9a-f]*))/) {
             if($3 eq "(nil)") {
                 ;
             }
@@ -299,7 +346,7 @@ while(<FILE>) {
                 printf("FREEADDRINFO ($source:$linenum)\n");
             }
         }
-       
+
     }
     else {
         print "Not recognized prefix line: $line\n";
@@ -351,8 +398,9 @@ if($verbose) {
     "Reallocs: $reallocs\n",
     "Callocs: $callocs\n",
     "Strdups:  $strdups\n",
+    "Wcsdups:  $wcsdups\n",
     "Frees: $frees\n",
-    "Allocations: ".($mallocs + $callocs + $reallocs + $strdups)."\n";
+    "Allocations: ".($mallocs + $callocs + $reallocs + $strdups + $wcsdups)."\n";
 
     print "Maximum allocated: $maxmem\n";
 }