POV-Ray : Newsgroups : povray.beta-test : v3.8 attempted load of radiosity file core dumps. : Re: v3.8 attempted load of radiosity file core dumps. Server Time
20 Apr 2024 10:56:13 EDT (-0400)
  Re: v3.8 attempted load of radiosity file core dumps.  
From: William F Pokorny
Date: 7 Feb 2021 08:57:47
Message: <601ff1db@news.povray.org>
On 2/7/21 7:34 AM, Le_Forgeron wrote:
> Le 06/02/2021 à 21:11, William F Pokorny a écrit :
...
> 
> Beware of leakage when opening fails.
> 
> I wonder if the change should not be a two-level check:
> 1. is the object != nullptr (as previous) ( if (fd != nullptr) )
> 2. is the read/open not in fail state ( if (*fd) )
> 
> The "delete fd;" being outside the second block.
> 
> The first block handle memory failure (or not, "new" would throw, and
> that is not catched locally).
> 
> So actually, I think your change of the test is correct, BUT the "delete
> fd;" must be moved outside the block too.
> 

Thank you! :-)

Just checked a delete of a null pointer is safe and it appears it is. To 
confirm, what I now have is:

IStream* fd = NewIStream(inputFile, POV_File_Data_RCA);
if (*fd)
{
...
}
delete fd;

Bill P.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.