Re: More memory bugs


Subject: Re: More memory bugs
From: Mike Nordell (tamlin@algonet.se)
Date: Tue Mar 20 2001 - 01:00:58 CST


Hubert Figuiere wrote:
> According to Dom Lachowicz <cinamod@hotmail.com>:
> >
> > free() isn't guaranteed to work with NULL, and I'd rather not try to
delete
> > (or delete[]) anything that is null. If you'd like to give this a try,
in
>
> delete works with NULL pointers and does nothing. But it is best to check
> the case in case of a broken library that may generate hard to trackdown
> bugs.

To be really correct, it's not a runtime library issue but a compiler issue.
When "delete"-ing a pointer, the compiler has to do something like the
following:

  if (p) {
    p->T::~T();
    operator delete(p);
  }

The runtime library might however be involved in this logic when calling
delete[] on objects with non-trivial destructors.

/Mike



This archive was generated by hypermail 2b25 : Tue Mar 20 2001 - 01:02:28 CST