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

Re: [PATCH V2 4/6] wt-status.c: fix a memleak

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Mar 27, 2015, 23:16 UTC
Message-ID
<CAPig+cT8_0+tgcDa4yOPgOLUA8Xtwa26JhMWo84c-J3_bjbTfw@mail.gmail.com>
In-Reply-To
<1427495569-10863-5-git-send-email-sbeller@google.com>
On Fri, Mar 27, 2015 at 6:32 PM, Stefan Beller <sbeller@google.com> wrote:
Show 19 quoted lines
> In any code path of shorten_unambiguous_ref the return value is a
> xstrdup(some string), so it is safe to free the variable `base`
> in any codepath.
>
> Signed-off-by: Stefan Beller <sbeller@google.com>
> ---
>  wt-status.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/wt-status.c b/wt-status.c
> index 853419f..9d2a349 100644
> --- a/wt-status.c
> +++ b/wt-status.c
> @@ -1576,6 +1576,8 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
>
>         color_fprintf(s->fp, header_color, "]");
>         fputc(s->null_termination ? '\0' : '\n', s->fp);
> +
> +       free((char *)base);

There's an early 'return' before this point (at line 1560) which will leak 'base', so this is an unreliable fix. A better solution would be to free(base) immediately after it's final use (before the early 'return').

Show 5 quoted lines
>  }
>
>  void wt_shortstatus_print(struct wt_status *s)
> --
> 2.3.0.81.gc37f363
Previous: Stefan BellerNext: Stefan Beller
Message 7 of 14 in “Memory leaks once again”
  1. 0/6 Memory leaks once againStefan Beller, Mar 27, 2015
  2. 1/6 shallow: fix a memleakStefan Beller, Mar 27, 2015
  3. Eric SunshineMar 27, 2015
  4. 2/6 line-log.c: fix a memleakStefan Beller, Mar 27, 2015
  5. 3/6 line-log.c: fix a memleakStefan Beller, Mar 27, 2015
  6. 4/6 wt-status.c: fix a memleakStefan Beller, Mar 27, 2015
  7. Eric SunshineMar 27, 2015
  8. 5/6 pack-bitmap: fix a memleakStefan Beller, Mar 27, 2015
  9. Eric SunshineMar 27, 2015
  10. Jeff KingMar 31, 2015
  11. 6/6 WIP/RFC/entry.c: fix a memleakStefan Beller, Mar 27, 2015
  12. Eric SunshineMar 27, 2015
  13. Eric SunshineMar 28, 2015
  14. John KeepingMar 28, 2015

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.