Opened 12 years ago

Last modified 12 years ago

#33745 closed defect

Valgrind fails to show file/line of leak/error — at Initial Version

Reported by: ClintO (Clint O) Owned by: macports-tickets@…
Priority: Normal Milestone:
Component: ports Version: 2.0.4
Keywords: Cc:
Port: valgrind

Description

I have a small piece of C++ software that demonstrates leaks, but for whatever reason I cannot coax the file and line numbers. I used /usr/bin/g++ -g -W -Wall to compile every source. Some sources were generated by flex and bison, but otherwise it's just straightforward C++.

==985== 96 bytes in 4 blocks are definitely lost in loss record 13 of 22 ==985== at 0xB823: malloc (vg_replace_malloc.c:266) ==985== by 0x5768D: operator new(unsigned long) (in /usr/lib/libstdc++.6.0.9.dylib) ==985== by 0x100003BB5: yylex(YYSTYPE*, void*) (in ./re) ==985== by 0x1000016C7: yyparse(Parser*, void*) (in ./re) ==985== by 0x10000291C: main (in ./re)

I attempted to reproduce with the following piece of C++ code, but it works. So, there's some difference between the two cases:

$ cat leak.cpp class Foo {

const char *name; int age;

public:

Foo(const char *name_, int age_) : name(name_), age(age_) {};

};

int main(int argc, char *argv[]) {

Foo *foo = new Foo("foo", 1);

foo = new Foo("bar", 2);

return 0;

} $ g++ -W -Wall -g -o leak leak.cpp leak.cpp:11: warning: unused parameter ‘argc’ leak.cpp:11: warning: unused parameter ‘argv’

$ valgrind --leak-check=full ./leak ==1299== Memcheck, a memory error detector ==1299== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al. ==1299== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info ==1299== Command: ./leak ==1299== ==1299== ==1299== HEAP SUMMARY: ==1299== in use at exit: 2,229 bytes in 34 blocks ==1299== total heap usage: 34 allocs, 0 frees, 2,229 bytes allocated ==1299== ==1299== 16 bytes in 1 blocks are definitely lost in loss record 2 of 10 ==1299== at 0xB823: malloc (vg_replace_malloc.c:266) ==1299== by 0x5768D: operator new(unsigned long) (in /usr/lib/libstdc++.6.0.9.dylib) ==1299== by 0x100000E56: main (leak.cpp:14) ...

Any suggestions you may have would be much appreciated.

Change History (0)

Note: See TracTickets for help on using tickets.