From: Wolfgang Denk Date: Mon, 06 Dec 2010 13:31:53 +0100 Subject: [U-Boot] [PATCH] LZMA: Avoid free on null pointer. In-Reply-To: References: <1291540724-26513-1-git-send-email-luigi.mantellini@idf-hit.com> <201012060215.36947.vapier@gentoo.org> <201012060357.39766.vapier@gentoo.org> Message-ID: <20101206123153.45445659@gemini.denx.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Dear Luigi Mantellini, In message 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.