How to check whether a pointer is NULL before allocating more memory space?
<p>I'm using abstract factory design pattern for my project.</p>

<pre><code>CPattern * CObjectA::Create(void)
{
    CPattern *p = new CPattern;
    patternList.push_back (p);
    return *p;
}

//Member variable
CPattern *pat = NULL;

pat = Obj.Create();
</code></pre>

<p>CObjectA will delete the space allocated during destructor. The problem is, if client do this again:</p>

<pre><code>pat = Obj.Create();
</code></pre>

<p>I would have allocated another space and pat points to it. If this is called a few hundred times, I will keep on creating space without disallocating it.</p>

<p>Is there a way to check whether pat is empty before I allocate another space for it?</p>

<p>Thank you for your help!</p>
