← Back to team overview

kicad-developers team mailing list archive

Re: Bug fixing and Coverity scan errors.

 

On 3/31/2015 9:36 AM, Mário Luzeiro wrote:
> Hi Wayne,
> 
> I usually find in other c++ projects something like this:
> 
> template <typename T> inline void SAFE_DELETE(T& p)						{ delete p; (p) = NULL; } 
> Random example: https://github.com/envi/imagepitcher/blob/master/imagepitcher/macro.h

wxWidgets provides this in wxDELETE defined in wx/defs.h.  Yes, there
are many undocumented features in wxWidgets.  Do not assume that if it's
not in the wxWidgets documentation that it doesn't exist.

> 
> http://www.cplusplus.com/reference/new/operator%20delete[]/
> "If this is a null-pointer, the function does nothing."
> 
> So since there is no problem to delete a null pointer. this template only assures that the pointer is setting it to null.
> 
> 
> Other question:
> How can we debug memory leaks in KiCad? I never did it before in any other place, is there any way in KiCad project?
> 
> Mario Luzeiro
> 
> ________________________________________
> From: Kicad-developers [kicad-developers-bounces+mrluzeiro=ua.pt@xxxxxxxxxxxxxxxxxxx] on behalf of Wayne Stambaugh [stambaughw@xxxxxxxxx]
> Sent: 31 March 2015 15:11
> To: kicad-developers@xxxxxxxxxxxxxxxxxxx
> Subject: Re: [Kicad-developers] Bug fixing and Coverity scan errors.
> 
>> That should be desirable to set it to NULL.
>> I am not a C++ expert but, are we missing a "safe delete" thing to use in KiCad?
> 
> What do you mean by "safe" delete?  It's always the responsibility of
> the programmer to know when it's safe to delete an object created on the
> heap.  C++ cannot know when it's safe to delete an object.  If you mean
> automatic heap deletion, you can use the C++ auto_ptr or Boost smart_ptr
> templates.  Using them requires some understanding.  Otherwise, they can
> be just as unsafe as delete.
> 


References