valgrind.pm 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. use File::Basename;
  23. sub valgrindparse {
  24. my ($srcdir, # the dir in which the runtests script resides
  25. $sslenabled,
  26. $file) = @_;
  27. my $leak;
  28. my $invalidread;
  29. my $uninitedvar;
  30. my $error;
  31. my $partial;
  32. my $us;
  33. my @o;
  34. my $bt=0;
  35. my $nssinit=0;
  36. open(VAL, "<$file");
  37. while(<VAL>) {
  38. if($bt) {
  39. # back trace parsing
  40. if($_ =~ /^==(\d+)== *(at|by) 0x([0-9A-F]+): (.*)/) {
  41. my $w = $4;
  42. if($w =~ /(.*) \(([^:]*):(\d+)/) {
  43. my ($func, $source, $line)=($1, $2, $3);
  44. my $sourcename = basename($source);
  45. if(-f "$srcdir/../src/$sourcename" ||
  46. -f "$srcdir/../lib/$sourcename") {
  47. # this is our source
  48. # print "$func() at $source:$line\n";
  49. $us++;
  50. } #else {print "Not our source: $func, $source, $line\n";}
  51. }
  52. # the memory leakage within NSS_InitContext is not a bug of curl
  53. if($w =~ /NSS_InitContext/) {
  54. $nssinit++;
  55. }
  56. }
  57. else {
  58. if($us and not $nssinit) {
  59. # the stack trace included source details about us
  60. $error++;
  61. if($leak) {
  62. push @o, "\n Leaked $leak bytes\n";
  63. }
  64. if($invalidread) {
  65. push @o, "\n Read $invalidread invalid bytes\n";
  66. }
  67. if($uninitedvar) {
  68. push @o, "\n Conditional jump or move depends on uninitialised value(s)\n";
  69. }
  70. }
  71. $bt = 0; # no more backtrace
  72. $us = 0;
  73. $nssinit = 0;
  74. }
  75. }
  76. else {
  77. if($_ =~ /(\d+) bytes in (\d+) blocks are definitely lost/) {
  78. $leak = $1;
  79. if($leak) {
  80. $error++;
  81. }
  82. $bt = 1;
  83. }
  84. elsif($_ =~ /Invalid read of size (\d+)/) {
  85. $invalidread = $1;
  86. $error++;
  87. $bt = 1;
  88. }
  89. elsif($_ =~ /Conditional jump or move/) {
  90. # If we require SSL, this test case most probaly makes
  91. # us use OpenSSL. OpenSSL produces numerous valgrind
  92. # errors of this kind, rendering it impossible for us to
  93. # detect (valid) reports on actual curl or libcurl code.
  94. if(!$sslenabled) {
  95. $uninitedvar = 1;
  96. $error++;
  97. $bt = 1;
  98. }
  99. else {
  100. $partial=1;
  101. }
  102. }
  103. }
  104. }
  105. close(VAL);
  106. return @o;
  107. }
  108. 1;