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);
Post a reply to this message