git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nicolas Morey-Chaisemartin <devel-git@morey-chaisemartin.com>
To: Junio C Hamano <gitster@pobox.com>, git@vger.kernel.org
Subject: [PATCH] grep: Fix race condition in delta_base_cache
Date: Tue, 30 Aug 2011 15:45:38 +0200	[thread overview]
Message-ID: <4E5CE982.7080200@morey-chaisemartin.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 825 bytes --]


When running large git grep (ie: git grep regexp $(git rev-list --all)), glibc error sometimes occur:
*** glibc detected *** git: double free or corruption (!prev): 0x00000000010abdf0 ***

According to gdb the problem originate from release_delta_cash (sha1_file.c:1703)
		free(ent->data);

>From my analysis it seems that git grep threads do acquire lock before calling read_sha1_file but not before calling
read_object_with_reference who ends up calling read_sha1_file too.

Adding the lock around read_object_with_reference seems to fix the issue for me.
I've ran git grep about a dozen time and seen no more error while
it usually happened half the time before.

Signed-off-by: Nicolas Morey-Chaisemartin <nicolas@morey-chaisemartin.com>
---
 builtin/grep.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)



[-- Attachment #2: 0001-grep-Fix-race-condition-in-delta_base_cache.patch --]
[-- Type: text/x-patch, Size: 465 bytes --]

diff --git a/builtin/grep.c b/builtin/grep.c
index 1c359c2..56398d5 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -598,8 +598,10 @@ static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec,
 		struct strbuf base;
 		int hit, len;
 
+		read_sha1_lock();
 		data = read_object_with_reference(obj->sha1, tree_type,
 						  &size, NULL);
+		read_sha1_unlock();
 		if (!data)
 			die(_("unable to read tree (%s)"), sha1_to_hex(obj->sha1));
 


             reply	other threads:[~2011-08-30 22:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-30 13:45 Nicolas Morey-Chaisemartin [this message]
2011-08-31  1:59 ` [PATCH] grep: Fix race condition in delta_base_cache Jeff King
2011-08-31  6:32   ` Nicolas Morey-Chaisemartin
2011-08-31 19:13   ` Nicolas Morey-Chaisemartin

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=4E5CE982.7080200@morey-chaisemartin.com \
    --to=devel-git@morey-chaisemartin.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.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).