Print

Print


I have to agree that the if should not be added. It just complicates the
code for no good reason. (In fact in the past that if on 64 bit machines
could have caused the object not to be deleted).

On Wed, 22 Sep 2004, Jacek Becla wrote:

> Hi Gregory
>
> Not really. C++ guarantees that operator delete checks its argument for
> null-ness. If the argument is 0, the delete expression has no effect. In
> other words, deleting a null pointer is a safe (yet useless) operation.
> There is no need to check the pointer for null-ness before passing it to
> delete.
>
> Jacek
>
>
>
>
> Gregory J. Sharp wrote:
>
> > Folks,
> >
> > The following change might also be a suitable form of defensive
> > programming:
> >
> > in XrdXr/XrdXrClientWorker.cc in the destructor, it would be
> > comforting to change:
> >
> >   delete xrootd;  xrootd  = 0;
> >   delete errInfo; errInfo = 0;
> > to
> >   if (xrootd) { delete xrootd;  xrootd  = 0; }
> >   if (errInfo) { delete errInfo; errInfo = 0; }
> >
> > and, totally free of charge, the trailing ; on the following line can
> > go away.
> >
> > --
> > Gregory J. Sharp                   email: [log in to unmask]
> > Wilson Synchrotron Laboratory      url:
> > http://www.lepp.cornell.edu/~gregor
> > Dryden Rd                          ph:  +1 607 255 4882
> > Ithaca, NY 14853                   fax: +1 607 255 8062
> >
>

--
 /------------------------------------+-------------------------\
|Stephen J. Gowdy                     | SLAC, MailStop 34,       |
|http://www.slac.stanford.edu/~gowdy/ | 2575 Sand Hill Road,     |
|http://calendar.yahoo.com/gowdy      | Menlo Park CA 94025, USA |
|EMail: [log in to unmask]       | Tel: +1 650 926 3144     |
 \------------------------------------+-------------------------/