All of lore.kernel.org
 help / color / mirror / Atom feed
From: "René Scharfe" <rene.scharfe@lsrfire.ath.cx>
To: Felipe Contreras <felipe.contreras@gmail.com>
Cc: git@vger.kernel.org, "Junio C Hamano" <gitster@pobox.com>,
	"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>,
	"Adam Spiers" <git@adamspiers.org>,
	"Ramkumar Ramachandra" <artagnon@gmail.com>
Subject: Re: [PATCH v3 2/2] read-cache: plug a few leaks
Date: Sun, 09 Jun 2013 19:38:39 +0200	[thread overview]
Message-ID: <51B4BD9F.6070107@lsrfire.ath.cx> (raw)
In-Reply-To: <CAMP44s0RqtoP8iHZ+rEqPDKSLxZLESS8qKFhb2vzSd7-mtKreQ@mail.gmail.com>

Am 09.06.2013 04:25, schrieb Felipe Contreras:
> On Sat, Jun 8, 2013 at 9:11 PM, René Scharfe
> <rene.scharfe@lsrfire.ath.cx> wrote:
>> Am 08.06.2013 19:27, schrieb Felipe Contreras:
>>
>>> On Sat, Jun 8, 2013 at 12:22 PM, René Scharfe
>>> <rene.scharfe@lsrfire.ath.cx> wrote:
>>>
>>>> Let's find and fix those leaks by freeing memory in the right places.
>>>> Freeing memory just in case in places where we can show that no leak is
>>>> triggered by our test suite doesn't help.
>>>
>>>
>>> It helps; it prevents leaks. The real culprit is the bogus API, but I
>>> don't see that changing anytime soon, so there are two options when
>>> somebody makes a mistake the API allows; leak or don't leak. And you
>>> seem to prefer the leak, even though it provides absolutely no
>>> advantage.
>>
>> It covers up bugs,
>
> It doesn't. I thought you already silently agreed that nobody would
> ever find that leak, as they haven't found the hundreds of leaks that
> plague Git's code.

Nah, I explained non-silently that leakage was a design decision for 
short-running commands that allocate memory, use it and exit.  Reusing 
such code without freeing allocated memory between runs explicitly turns 
a "good" leak into a "bad" one, as we saw with cherry-pick --stdin.

>> What would be a better API?  Making discard_index free the array is a good
>> first step; what else is bogus?
>
> 'initialized' for starters; it should be renamed to 'loaded' or
> removed, but removing it would require many more changes to make sure
> we don't load twice. Also, when loading cache entries, it might make
> sense to check if there's already entries that have not been
> previously discarded properly.

Adding diagnostics that help find leaks is a good idea.

So, from reading the code, this sequence is OK:

	discard_cache()		// defined starting point
	read_cache()		// reads the cache
	read_cache()		// does nothing

And I guess this one is not OK:

	discard_cache()		// defined starting point
	add_index_entry()	// add single entry
	read_cache()		// currently leaks, should warn/die

Any more sequences that we need to guard against, or counterexamples?

> In the meantime, just in case, the only sane thing to do is free the
> entries rather than leak.

I consider not plugging a leak which we don't know how to trigger with 
existing code even more sane.  Yay, circles! ;-)

> That being said I'm not interested in this patch any more. The patch
> is good yet after three tries and countless arguments it's still not
> applied, nor is there any sign of getting there.

Let's take it step by step: Once the known leak is plugged we can worry 
about the unknown ones.  I'll send small patches.

René

  reply	other threads:[~2013-06-09 17:38 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-07 22:29 [PATCH v3 0/2] cherry-pick: fix memory leaks Felipe Contreras
2013-06-07 22:29 ` [PATCH v3 1/2] unpack-trees: plug a memory leak Felipe Contreras
2013-06-07 22:29 ` [PATCH v3 2/2] read-cache: plug a few leaks Felipe Contreras
2013-06-08 11:32   ` René Scharfe
2013-06-08 12:15     ` Felipe Contreras
2013-06-08 13:22       ` René Scharfe
2013-06-08 14:04         ` Felipe Contreras
2013-06-08 15:56           ` René Scharfe
2013-06-08 16:53             ` Felipe Contreras
2013-06-08 17:22               ` René Scharfe
2013-06-08 17:27                 ` Felipe Contreras
2013-06-09  2:11                   ` René Scharfe
2013-06-09  2:25                     ` Felipe Contreras
2013-06-09 17:38                       ` René Scharfe [this message]
2013-06-09 18:27                         ` Felipe Contreras
2013-06-09 18:49         ` 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=51B4BD9F.6070107@lsrfire.ath.cx \
    --to=rene.scharfe@lsrfire.ath.cx \
    --cc=artagnon@gmail.com \
    --cc=felipe.contreras@gmail.com \
    --cc=git@adamspiers.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=pclouds@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.