------- Additional Comments From arturas at inf dot unibz dot it 2005-02-18
18:25 -------
Subject: Re: hash_map leak memory
Hi Pinskia,
I think I made a mistake including the code.
Here's the code:
--------------------------------- a.cc ---------------------------------
#include <vector>
#include <iostream>
#undef __DEPRECATED
#include <hash_map.h>
class Eqstr {
public:
bool operator()(const char* s1, const char* s2) const {
if (strcmp(s1, s2) == 0)
return true;
else
return false;
}
};
using std::vector;
using std::cout;
using std::endl;
main () {
hash_map<const char*, int *, hash<const char*>, Eqstr> signatures;
hash_map<const char*, int *, hash<const char*>, Eqstr>::iterator it;
char *str;
int *pi, j;
char qgram[4];
qgram[0] = qgram[1] = qgram[2] = 'a';
qgram[3] = 0;
vector< char * > p;
while (strcmp( qgram, "zzz" ) != 0) {
str = new char [4];
strcpy( str, qgram );
pi = new int [1];
signatures[str] = pi;
//scanning thourgh all strings from aaa to zzz
if (qgram[2] != 'z')
qgram[2]++;
else {
qgram[2] = 'a';
if (qgram[1] != 'z')
qgram[1]++;
else {
qgram[1] = 'a';
qgram[0]++;
}
}
}
for (it = signatures.begin(); it != signatures.end(); it++) {
p.push_back( (char *)it->first );
delete[] it->second;
}
for (j = 0; j < p.size(); j++)
delete[] (p[j]);
}
---------------------------------------------------------------------
memory leak was obtain in the following way:
$ g++ -g a.cc
$ LeakTracer/LeakCheck ./a.out
$ LeakCheck ./a.out # (From http://www.andreasen.org/LeakTracer/)
$ [EMAIL PROTECTED]:/tmp$ ~/edit/LeakTracer/leak-analyze ./a.out
Gathered 56 (1 unique) points of data.
(gdb)
#-- Leak: counted 56x / total Size: 296360
No source file for address 0x400a9a5b.
I've played a little with __builtin_return_address to retrieve the place
of the leak. It seems that it is line 127 of stl_vector.h file.
Should I also upload the file?
Thanks,
arturas
On Fri, Feb 18, 2005 at 06:18:01PM -0000, pinskia at gcc dot gnu dot org wrote:
>
> ------- Additional Comments From pinskia at gcc dot gnu dot org 2005-02-18
> 18:18 -------
> (In reply to comment #0)
> > Compile the code, rerun command, I included in the description
>
> I don't see any.
>
> --
>
>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20062
>
> ------- You are receiving this mail because: -------
> You reported the bug, or are watching the reporter.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20062