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

Re: [PATCH] receive-pack: plug minor memory leak in unpack()

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 13, 2014, 19:08 UTC
Message-ID
<xmqq1tqb4wkm.fsf@gitster.dls.corp.google.com>
In-Reply-To
<20141012015321.GA15272@peff.net>
Jeff King <peff@peff.net> writes:
Show 8 quoted lines
> On Sat, Oct 11, 2014 at 01:00:16PM +0200, René Scharfe wrote:
>
>> The argv_array used in unpack() is never freed.  Instead of adding
>> explicit calls to argv_array_clear() use the args member of struct
>> child_process and let run_command() and friends clean up for us.
>
> Looks good. I notice that the recently added prepare_push_cert_sha1 uses
> an argv_array to create the child_process.env, and we leak the result.

You're right. finish_command() runs argv_array_clear() on cmd->args, but does not care about cmd->env so anybody that use the (optional) "use these environment variable settings while running the command" would leak unless the caller takes care of it.

> I wonder if run-command should provide a managed env array similar
> to the "args" array.
I took a look at a few of them:
 - setup_pager() uses a static set of environment variables that are
   not built with argv_array(); should be easy to convert, though.
 - wt_status_print_submodule_summary() does use two argv_arrays, for
   env and argv.  It can use the managed "args" today, and with such
   a change it can also use the managed "envs".
 - receive-pack.c::prepare_push_cert_sha1() would benefit from
   managed "envs".
 - http-backend.c::run_service() would benefit from managed "envs".
 - daemon.c::handle() uses a static set of environment variables
   that are not built with argv_array().  Same for argv.
It shouldn't be too hard to catch and convert all of them.
Previous: Jeff KingNext: Jeff King
Message 3 of 10 in “receive-pack: plug minor memory leak in unpack()”
  1. receive-pack: plug minor memory leak in unpack()René Scharfe, Oct 11, 2014
  2. Jeff KingOct 12, 2014
  3. Junio C HamanoOct 13, 2014
  4. Jeff KingOct 14, 2014
  5. René ScharfeOct 19, 2014
  6. Jeff KingOct 20, 2014
  7. 1/2 run-command: add env_array, an optional argv_array for envRené Scharfe, Oct 19, 2014
  8. 2/2 use env_array member of struct child_processRené Scharfe, Oct 19, 2014
  9. Jeff KingOct 20, 2014
  10. René ScharfeNov 9, 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.