|
From: Stephan M. <sm...@gm...> - 2004-10-27 10:02:48
|
=2D----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi,
I became a little bit confused doing memchecks using c++ classes.
One of those classes maintains a mem area which is frequently resized using=
=20
realloc.
The Code segment looks perfectly alright to me...
void MyClass::resize(size_t n) {
char *buf;
if (n >=3D _size) {
if (!(buf =3D (char*)realloc(_buf,n+1)))
throw std::bad_alloc();
_buf =3D buf;
_size =3D n + 1;
}
}
But using this class (a lot, multithreaded) valgrind 2.2.0 shows something=
=20
like this:
=3D12311=3D=3D 309 bytes in 7 blocks are definitely lost in loss record 18 =
of 30
=3D=3D12311=3D=3D at 0x1B903A8B: realloc (vg_replace_malloc.c:197)
=3D=3D12311=3D=3D by 0x8085F2C: MyClass::resize(unsigned int) (../MyClas=
s.cc:650)
=3D=3D12311=3D=3D by 0x80847FF: MyClass::append(char const *, unsigned i=
nt
=3D=3D12311=3D=3D by 0x8084723: MyClass::append(MyClass const &) (../MyC=
lass.cc
What should be lost there? Does it refer to the mem area being abandoned wh=
en=20
realloc() gives a pointer different to _buf?
But it's supposed to be lost, we give it up. Why complain? I don't have to=
=20
free it do I?
Am I mistaken here or is it just a warning to be safely ignored?
System is linux 2.6.9, valgrind 2.2.0, gcc 2.95-3
Greetings...
Stephan
=2D----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
iD8DBQFBf3I0bv5p9h9J588RAtXgAJ0fAiWYxa6fMhmTOidrVIN65iyRxACgp/SU
MAVHyX15zHwyD/8gY3i2Qr4=3D
=3DzQbv
=2D----END PGP SIGNATURE-----
|