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

  • From: "Michael Lotz" <mmlr@xxxxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Fri, 12 Sep 2008 14:20:18 +0200

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.

Regards
Michael

Other related posts: