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

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 
[[email protected]] on behalf of 
Wayne Stambaugh [[email protected]]
Sent: 31 March 2015 15:11
To: [email protected]
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.
_______________________________________________
Mailing list: https://launchpad.net/~kicad-developers
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~kicad-developers
More help   : https://help.launchpad.net/ListHelp

Reply via email to