git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: git@vger.kernel.org
Subject: [RFC/PATCH 0/6] build argv_array into run-command
Date: Thu, 15 May 2014 04:29:44 -0400	[thread overview]
Message-ID: <20140515082943.GA26473@sigill.intra.peff.net> (raw)

The memory ownership of the "argv" array of a "struct child_process" can
be tricky. The child_process does not own the memory, but it must remain
valid until finish_command runs. That's easy for cases where we call
start_command and finish_command in the same function: you can use a
local array variable, or use an argv_array and cleanup afterwards.

But it's easy to screw up in cases where you want to start a command in
one function and finish it in another, either by pointing to invalid
storage during finish_command, or by leaking dynamically allocated
memory.

This series sticks an argv_array inside the "struct child_process",
which we clean up automatically.  Because some callers might not want to
use it, it's optional. If you provide "argv", we use that, and
otherwise fall back to the internal array.

The first commit below does that. The second fixes an uninitialized
memory access. 3, 4, and 5 plug memory leaks. 6 is just a cleanup for
consistency with the changes in 4 and 5.

And in 2, 3, and 5 we are introducing argv_array into new spots, which
simplifies the code and gets rid of magic numbers.

  [1/6]: run-command: store an optional argv_array
  [2/6]: run_column_filter: use argv_array
  [3/6]: git_connect: use argv_array
  [4/6]: get_helper: use run-command's internal argv_array
  [5/6]: get_exporter: use argv_array
  [6/6]: get_importer: use run-command's internal argv_array

-Peff

             reply	other threads:[~2014-05-15  8:29 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-15  8:29 Jeff King [this message]
2014-05-15  8:33 ` [PATCH 1/6] run-command: store an optional argv_array Jeff King
2014-05-15  8:33 ` [PATCH 2/6] run_column_filter: use argv_array Jeff King
2014-05-15  8:34 ` [PATCH 3/6] git_connect: " Jeff King
2014-05-15  8:34 ` [PATCH 4/6] get_helper: use run-command's internal argv_array Jeff King
2014-05-15  8:34 ` [PATCH 5/6] get_exporter: use argv_array Jeff King
2014-05-15  8:35 ` [PATCH 6/6] get_importer: use run-command's internal argv_array Jeff King
2014-05-15  8:41 ` [PATCH 7/6] argv-array: drop "detach" code Jeff King
2014-05-15 16:48 ` [RFC/PATCH 0/6] build argv_array into run-command Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140515082943.GA26473@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).