[haiku-development] Re: object on the hype, using it as parameter and then use delete

  • From: "Stephan Assmus" <superstippi@xxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Fri, 12 Sep 2008 17:05:43 +0200

-------- Original-Nachricht --------
> Datum: Fri, 12 Sep 2008 14:20:18 +0200
> Von: "Michael Lotz" <mmlr@xxxxxxxx>
> An: haiku-development@xxxxxxxxxxxxx
> Betreff: [haiku-development] Re: object on the hype, using it as parameter 
> and then use delete

> On Fri, 12 Sep 2008 13:56:21 +0200 (CEST), Fredrik Modéen wrote
> > this are how it's setup to work, it's only part of it but it showas what
> > i'm talkning about.
> >
> > ...
> >
> > void
> > IconView::_SetIcon(BBitmap* mini)
> > {
> >  BAppFileInfo info();
> >  if (mini != NULL || force)
> >   info.SetIconForType(fType.Type(), mini, B_MINI_ICON);
> > }
> 
> In that case you would just track down what SetIconForType() does. If it
> copies the bitmap, then you're fine. Otherwise this is probably a false
> positive.
> 
> It seems that you are not subscribed to the commits mailing list. Please
> make
> sure you are subscribed, as we are sometimes replying to commits there
> like I
> did for your change in r27438:
> 
> https://lists.berlios.de/pipermail/haiku-commits/2008-September/016893.html
> 
> You make the same assumption that new cannot fail in r27448 which I find a
> bad
> idea. You could say that it is true that new cannot return NULL, since it
> should actually throw an error and not return NULL. However this is not a
> reason to strip the NULL checks, but to make new into new(std::nothrow)
> which
> actually returns NULL on a failed allocation (which can always happen). I
> thought we had the general consensus that we use new(std::nothrow) and
> always
> check the result, but I'm not sure how the other see it.

Well, if the code catches the exception somewhere, then it is allowed to use 
just "new". If it does not catch the exception anywhere, it must use "new 
std::nothrow" and check for NULL. Similarily, if it checks for NULL, but uses 
plain "new", that is bogus of course. We used to have a lot of code like that 
but have done a good job of cleaning it up in recent years. In the case at 
hand, we should just use "new std::nothrow".

Best regards,
-Stephan


Other related posts: