git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: mhagger@alum.mit.edu
Cc: git@vger.kernel.org
Subject: Re: [PATCH 2/2] cmd_fetch_pack(): fix constness problem and memory leak
Date: Sun, 20 May 2012 18:47:03 -0700	[thread overview]
Message-ID: <7vk4069ug8.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <1335955259-15309-3-git-send-email-mhagger@alum.mit.edu> (mhagger@alum.mit.edu's message of "Wed, 2 May 2012 12:40:59 +0200")

mhagger@alum.mit.edu writes:

> I understand that it is not crucial to free memory allocated in a
> cmd_*() function but it is unclear to me whether it is *preferred* to
> let the process clean up take care of things.

Traditionally, the cmd_foo() functions roughly correspond to main() in
other programs, so from that point of view, "it is not crucial to free" is
an understatement. It is not even worth wasting people's time to (1)
decide which way is *preferred* and to (2) churn the code only to match
whichever way.

These cmd_foo() functions, being roughly equivalent to main(), have logic
to interpret the end-user's intentions (i.e. parse_options()), and carry
out that intention.  In the long run, some _other_ parts of the system may
want to do "foo" (whatever that "foo" may be) from inside the process
without forking, and the first step to do so may be to split cmd_foo()
into two, one that does "parse options", and the other that does "foo".
At that point, it starts to matter that we make the part that does "foo"
leak free, especially if such a caller (or callers) can ask to do "foo"
number of times.

If you have a plan to split cmd_fetch_pack() and make other parts of the
system call it, probably restructuring the current separation between
"figure out what refs will be fetched" done in cmd_fetch_pack() and "fetch
these refs in heads[] array" in fetch_pack() into something else (like
"the new caller also wants to read the list of refs from the standard
input, instead of having parse them into head[] array itself"), then
freeing the memory would matter a lot more, and the approach this patch
takes is a first step in the right direction, I would think.

It also seems that some cruft has snuck into this patch, e.g. like this
part,

> -	int i, ret, nr_heads;
> +	int i, ret;

that do not have anything to do with "fix constness" nor "memory leak".

  parent reply	other threads:[~2012-05-21  1:47 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-02 10:40 [PATCH 0/2] Fix some constness errors in fetch-pack mhagger
2012-05-02 10:40 ` [PATCH 1/2] cmd_fetch_pack(): declare dest to be const mhagger
2012-05-02 10:40 ` [PATCH 2/2] cmd_fetch_pack(): fix constness problem and memory leak mhagger
2012-05-02 11:14   ` Nguyen Thai Ngoc Duy
2012-05-02 13:35     ` Michael Haggerty
2012-05-02 14:38       ` [PATCH 0/3] Fix some constness errors in fetch-pack and parseopt conversion Nguyễn Thái Ngọc Duy
2012-05-02 14:38         ` [PATCH 1/3] cmd_fetch_pack(): declare dest to be const Nguyễn Thái Ngọc Duy
2012-05-02 14:38         ` [PATCH 2/3] fetch-pack: use parse_options() Nguyễn Thái Ngọc Duy
2012-05-02 14:38         ` [PATCH 3/3] cmd_fetch_pack(): fix constness problem and memory leak Nguyễn Thái Ngọc Duy
2012-05-02 17:14     ` [PATCH 2/2] " Junio C Hamano
2012-05-21  1:47   ` Junio C Hamano [this message]
2012-05-21  8:13     ` Michael Haggerty
2012-05-19 14:05 ` [PATCH 0/2] Fix some constness errors in fetch-pack Michael Haggerty

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=7vk4069ug8.fsf@alter.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=mhagger@alum.mit.edu \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).