From: Eric Sunshine Date: Thu, 27 Nov 2014 06:18:30 GMT Subject: Re: [PATCH 1/1] cat-file: fix a memory leak in cat_one_file Message-ID: In-Reply-To: <20141127002417.GT6527@google.com> On Wed, Nov 26, 2014 at 7:24 PM, Jonathan Nieder wrote: > Alexander Kuleshov wrote: > [...] >> +++ b/builtin/cat-file.c >> @@ -68,9 +69,14 @@ static int cat_one_file(int opt, const char >> + buf_must_free = 1; >> + >> - if (!buf) >> + if (!buf) { >> + free(buf); >> die("Cannot read object %s", obj_name); > > Is this free() needed? The program die()s right afterward, which > would free all memory automatically as part of exiting. Tools like > valgrind would understand that nothing is wrong since buf is still > reachable through the stack. Moreover, 'buf' can only be NULL inside the conditional, so the free() is pointless.