1#***************************************************************************
2#                                  _   _ ____  _
3#  Project                     ___| | | |  _ \| |
4#                             / __| | | | |_) | |
5#                            | (__| |_| |  _ <| |___
6#                             \___|\___/|_| \_\_____|
7#
8# Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al.
9#
10# This software is licensed as described in the file COPYING, which
11# you should have received as part of this distribution. The terms
12# are also available at http://curl.haxx.se/docs/copyright.html.
13#
14# You may opt to use, copy, modify, merge, publish, distribute and/or sell
15# copies of the Software, and permit persons to whom the Software is
16# furnished to do so, under the terms of the COPYING file.
17#
18# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19# KIND, either express or implied.
20#
21###########################################################################
22
23use File::Basename;
24
25sub valgrindparse {
26    my ($srcdir,     # the dir in which the runtests script resides
27        $sslenabled,
28        $file) = @_;
29    my $leak;
30    my $invalidread;
31    my $uninitedvar;
32    my $error;
33    my $partial;
34    my $us;
35
36    my @o;
37
38    my $bt=0;
39    my $nssinit=0;
40
41    open(VAL, "<$file");
42    while(<VAL>) {
43        if($bt) {
44            # back trace parsing
45            if($_ =~ /^==(\d+)== *(at|by) 0x([0-9A-F]+): (.*)/) {
46                my $w = $4;
47                if($w =~ /(.*) \(([^:]*):(\d+)/) {
48                    my ($func, $source, $line)=($1, $2, $3);
49                    my $sourcename = basename($source);
50                    if(-f "$srcdir/../src/$sourcename" ||
51                       -f "$srcdir/../lib/$sourcename") {
52                        # this is our source
53 #                       print "$func() at $source:$line\n";
54                        $us++;
55                    } #else {print "Not our source: $func, $source, $line\n";}
56                }
57
58                # the memory leakage within NSS_InitContext is not a bug of curl
59                if($w =~ /NSS_InitContext/) {
60                    $nssinit++;
61                }
62            }
63            else {
64                if($us and not $nssinit) {
65                    # the stack trace included source details about us
66
67                    $error++;
68                    if($leak) {
69                        push @o, "\n Leaked $leak bytes\n";
70                    }
71                    if($invalidread) {
72                        push @o, "\n Read $invalidread invalid bytes\n";
73                    }
74                    if($uninitedvar) {
75                        push @o, "\n Conditional jump or move depends on uninitialised value(s)\n";
76                    }
77                }
78                $bt = 0; # no more backtrace
79                $us = 0;
80                $nssinit = 0;
81            }
82        }
83        else {
84            if($_ =~ /(\d+) bytes in (\d+) blocks are definitely lost/) {
85                $leak = $1;
86                if($leak) {
87                    $error++;
88                }
89                $bt = 1;
90            }
91            elsif($_ =~ /Invalid read of size (\d+)/) {
92                $invalidread = $1;
93                $error++;
94                $bt = 1;
95            }
96            elsif($_ =~ /Conditional jump or move/) {
97                # If we require SSL, this test case most probaly makes
98                # us use OpenSSL. OpenSSL produces numerous valgrind
99                # errors of this kind, rendering it impossible for us to
100                # detect (valid) reports on actual curl or libcurl code.
101
102                if(!$sslenabled) {
103                    $uninitedvar = 1;
104                    $error++;
105                    $bt = 1;
106                }
107                else {
108                    $partial=1;
109                }
110            }
111        }
112    }
113    close(VAL);
114    return @o;
115}
116
1171;
118