git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/1] cat-file: fix a memory leak in cat_one_file

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Nov 27, 2014, 06:18 UTC
Message-ID
<CAPig+cSnOc42msPYsBSv+PTgFsDyBqeL7yhSutuRQUkezpTdmw@mail.gmail.com>
In-Reply-To
<20141127002417.GT6527@google.com>
On Wed, Nov 26, 2014 at 7:24 PM, Jonathan Nieder <jrnieder@gmail.com> wrote:
Show 15 quoted lines
> 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.

Previous: Jonathan Nieder
Message 3 of 3 in “cat-file: fix a memory leak in cat_one_file”
  1. 1/1 cat-file: fix a memory leak in cat_one_fileAlexander Kuleshov, Nov 26, 2014
  2. Jonathan NiederNov 27, 2014
  3. Eric SunshineNov 27, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.