Hi,

Tracking down a crash I am seeing shows that I am effectively calling
FreePool() with a NULL pointer.  The system then ASSERTS and hangs.

I've noticed various seemingly "random" asserts like this before and
suspect it may be related.  Of course, the assert output never helps track
down the culprit, but that's a different issue altogether.

Coming from an environment where I'm able to call malloc() and then free()
with a NULL pointer, my experience told me that I should be able to call
FreePool() with a NULL pointer without worrying about checking the pointer
for NULL first.

However, CoreFreePool() that eventually gets called is explicitly returning
EFI_INVALID_PARAMETER if it is called with NULL.  And FreePool() explicitly
ASSERTs if the return value from CoreFreePool() is not EFI_SUCCESS.

It doesn't strike me as a sensible thing to do.

I think FreePool(NULL) should just return without reporting an error.  I
see a *lot* of calls to FreePool where the pointer isn't first checked for
NULL.  The code path is often simpler, where the code will often return if
the alloc fails, but in my example, I am retrieving an optional variable
which may or may not exist and therefore may or may not allocate memory.

Although systems seems to have got along just fine up to now - the code has
always been like this - I'd like to change it.  Hanging seems unnecessarily
harsh.

What do others think?

Is there a real advantage to hanging on NULL?

Regards,
Ryan.
------------------------------------------------------------------------------
LIMITED TIME SALE - Full Year of Microsoft Training For Just $49.99!
1,500+ hours of tutorials including VisualStudio 2012, Windows 8, SharePoint
2013, SQL 2012, MVC 4, more. BEST VALUE: New Multi-Library Power Pack includes
Mobile, Cloud, Java, and UX Design. Lowest price ever! Ends 9/20/13. 
http://pubads.g.doubleclick.net/gampad/clk?id=58041151&iu=/4140/ostg.clktrk
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel

Reply via email to