[U-Boot] [PATCH] LZMA: Avoid free on null pointer.

Wolfgang Denk wd at denx.de
Mon Dec 6 13:31:53 CET 2010


Dear Luigi Mantellini,

In message <AANLkTi=KQ+zc7yVUe5ssc=wzZuWEcPMYQHq-c-HZ0joa at mail.gmail.com> you wrote:
>
> my pov is different: free should (must) be called only on already
> allocated pointers. I know that free code checks at begin if ptr is
> null or not. Anyway I don't understand why a null pointer check before
> to call free cannot be added to the code... it's safe and follows the
> logical flow of the code.
> 
> I received warning from my debugger during activities on other things,
> and I added this fix to my code to turn-off "possible free on null
> pointer" warning from my debugger.

free(NULL) has a well defined behaviour: "If ptr is NULL, no
operation is performed."

Seems your debugger is over-cautious.  This may be OK for debugging,
but is no good reason to change the code.

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
It is easier to change the specification to fit the program than vice
versa.


More information about the U-Boot mailing list