|
From: Tom H. <th...@cy...> - 2004-10-27 10:25:48
|
In message <417...@sh...>
Dimitri Papadopoulos-Orfanos <pap...@sh...> wrote:
> 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[]?
An even better question would be "where was it supposed to be freed".
Tom
--
Tom Hughes (th...@cy...)
Software Engineer, Cyberscience Corporation
http://www.cyberscience.com/
|