[Libreoffice] [PUSHED, partial] Remove NULL checks from delete

Michael Meeks michael.meeks at suse.com
Thu Nov 17 02:16:15 PST 2011


On Wed, 2011-11-16 at 21:05 -0500, Andrew Douglas Pitonyak wrote:
> >> I would feel safer if pointers were set to NULL (or nullptr if we
> >> support C++11) since it is not safe to delete a pointer twice.
> > ?, convert all delete to e.g. DELETEZ, i.e. delete foo, foo = NULL ?
> > Wouldn't be a fan of that, c++ is the language that it is, need to live
> > with that and not try and make it something that it isn't.
>
> Setting a pointer to NULL after deleting the contents of the pointer is 
> safe so that if you go to delete it again it is not a problem.

	Sure, it would be somewhat safer for some minority of cases. However
the DELETEZ macro looks hyper-ugly in the code and makes it less
readable. Hopefully we mostly delete things in destructors - where
DELETEZ is a waste of time - we can have our (sadly) custom allocator
wipe or invalidate the memory post delete in a single line of code if we
want to (actually we should prolly do that as an easy-hack if it is not
there already ;-).

	If we have a bug whereby something is deleted in-the code without being
re-assigned, and where NULL is a valid value, then we could fix those
with a DELETEZ construct, but - finding those places (that don't already
have a subsequent assignment) is prolly more exciting :-) In theory some
code analysis framework could help find those guys.

	Does that give more detail ?

	Anyhow, thanks for your nice code cleanup ! it's nice to see.

	All the best,

		Michael.

-- 
michael.meeks at suse.com  <><, Pseudo Engineer, itinerant idiot



More information about the LibreOffice mailing list