git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] grep: Fix race condition in delta_base_cache

From
Nicolas Morey-Chaisemartin <devel-git@morey-chaisemartin.com>
Date
Aug 30, 2011, 13:45 UTC
Message-ID
<4E5CE982.7080200@morey-chaisemartin.com>

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(-)
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));
 
Next: Jeff King
Message 1 of 4 in “grep: Fix race condition in delta_base_cache”
  1. grep: Fix race condition in delta_base_cacheNicolas Morey-Chaisemartin, Aug 30, 2011
  2. Jeff KingAug 31, 2011
  3. Nicolas Morey-ChaisemartinAug 31, 2011
  4. Nicolas Morey-ChaisemartinAug 31, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.