Re: Unsafe C++ memory allocation with new operator

From: Robert Collins <robertc@dont-contact.us>
Date: Sun, 09 Jan 2005 11:08:24 +1100

On Sat, 2005-01-08 at 19:06 +0100, Serassio Guido wrote:
> Hi,
>
> I have found that the current C++ memory allocation with the new operator
> sometimes could be not safe:
>
> Currently memory allocation is done using xmalloc(), see include/SquidNew.h.

We could change to xcalloc, but actually the right thing to do is to
make a constructor for the object that will initialize any fields that
need to be, to 0.

I.e.
class RemovalPolicySettings
{
  public:
   RemovalPolicySettings() : args (NULL);
   char *args;
};

using calloc will result in double-work a lot of the time.

What you are actually seeing here is a bug on my part. Naughty-rob.

Rob

Received on Sat Jan 08 2005 - 17:09:12 MST

This archive was generated by hypermail pre-2.1.9 : Tue Feb 01 2005 - 12:00:02 MST