|
From: Jeroen N. W. <jn...@xs...> - 2004-10-27 10:25:56
|
Stephan,
Does the MyClass destructor free(_buf)?
Jeroen.
> -----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
> 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 someth=
ing
> 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)
> (../MyClass.cc:650)
> =3D=3D12311=3D=3D by 0x80847FF: MyClass::append(char const *, unsign=
ed int
> =3D=3D12311=3D=3D by 0x8084723: MyClass::append(MyClass const &) (..=
/MyClass.cc
>
> What should be lost there? Does it refer to the mem area being abandone=
d
> when
> 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
> 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
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.2.4 (GNU/Linux)
>
> iD8DBQFBf3I0bv5p9h9J588RAtXgAJ0fAiWYxa6fMhmTOidrVIN65iyRxACgp/SU
> MAVHyX15zHwyD/8gY3i2Qr4=3D
> =3DzQbv
> -----END PGP SIGNATURE-----
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by:
> Sybase ASE Linux Express Edition - download now for FREE
> LinuxWorld Reader's Choice Award Winner for best database on Linux.
> http://ads.osdn.com/?ad_idU88&alloc_id=12065&op=CCk
> _______________________________________________
> Valgrind-users mailing list
> Val...@li...
> https://lists.sourceforge.net/lists/listinfo/valgrind-users
>
>
|