git.vger.kernel.org archive mirror
 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: Sat, 08 Jun 2013 19:22:17 +0200	[thread overview]
Message-ID: <51B36849.3030608@lsrfire.ath.cx> (raw)
In-Reply-To: <CAMP44s3UYCX+DzgnErB=0GdD3w5k2GkNKjv46ZA_NVHm1Z0YLQ@mail.gmail.com>

Am 08.06.2013 18:53, schrieb Felipe Contreras:
> On Sat, Jun 8, 2013 at 10:56 AM, René Scharfe
> <rene.scharfe@lsrfire.ath.cx> wrote:
>> Am 08.06.2013 16:04, schrieb Felipe Contreras:
>>
>>> On Sat, Jun 8, 2013 at 8:22 AM, René Scharfe
>>> <rene.scharfe@lsrfire.ath.cx> wrote:
>>>>
>>>> Am 08.06.2013 14:15, schrieb Felipe Contreras:
>>>
>>>
>>>>> Why leave it out? If somebody makes the mistake of doing the above
>>>>> sequence, would you prefer that we leak?
>>>>
>>>>
>>>> Leaking is better than silently cleaning up after a buggy caller because
>>>> it
>>>> still allows the underlying bug to be found.
>>>
>>>
>>> No, it doesn't. The pointer is replaced and forever lost. How is
>>> leaking memory helping anyone to find the bug?
>>
>> Valgrind can tell you where leaked memory was allocated, but not if you free
>> it in the "wrong" place.
>
> It is the correct place to free it. And nobody will ever find it with
> valgrind, just like nobody has ever tracked down the hundreds of leaks
> in Git that happen reliably 100% of the time, much less the ones that
> happen rarely.

We could argue about freeing it here or adding a discard_index call 
somewhere else (which seems more natural to me) once we had a call 
sequence that actually causes such a leak.  The test suite contains 
none, so I'd say we need more tests first.

Lots of the existing leaks were not worth plugging because the process 
would end right after freeing the memory.  Leaving clean-up to the OS 
was a conscious design choice, simplifying the code.

When such code is reused in a library or run multiple times while it was 
originally meant to be run only a single time (like with cherry-pick 
--stdin) the original assumption doesn't hold any more and we have a 
problem.

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.

René

  reply	other threads:[~2013-06-08 17:22 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 [this message]
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
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=51B36849.3030608@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 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).