|
From: Stephan M. <sm...@gm...> - 2004-10-27 10:12:21
|
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Am Mittwoch, 27. Oktober 2004 12:05 schrieb Dimitri Papadopoulos-Orfanos:
> 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 >= _size) {
> > if (!(buf = (char*)realloc(_buf,n+1)))
> > throw std::bad_alloc();
> > _buf = buf;
> > _size = n + 1;
> > }
> > }
>
> How was _buf allocated in the first place? malloc or new[]?
malloc.
Or another realloc, if there were resize events before, which is not unlikely.
Greetings...
Stephan
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
iD8DBQFBf3R8bv5p9h9J588RAu/ZAJ9bpZ7sok4vmjzSMFleiAE8Q6SETACeOy2Q
m90AE79YurGGqvO5Bl7fmZA=
=li7V
-----END PGP SIGNATURE-----
|