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

  • From: Fredrik Modéen <fredrik@xxxxxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Fri, 12 Sep 2008 15:34:16 +0200 (CEST)

> 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.
Had to look up std::nothrow
http://www.informit.com/guides/content.aspx?g=cplusplus&seqNum=170

need we write it like this?

//standard C++ code
#include <new> //required for nothrow new

CWindow p;
p = new(std::nothrow) DerivedWind;
if (!p) //fine now
{
 cout<<"allocation failure!"
 exit(1);
}

>
> Regards
> Michael
>
>


-- 
MVH
Fredrik Modéen


Other related posts: