Skip to content

Commit 8cb5775

Browse files
nmoreygitster
authored andcommitted
grep: Fix race condition in delta_base_cache
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5b594f4 commit 8cb5775

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

builtin-grep.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,8 +632,12 @@ static int grep_object(struct grep_opt *opt, const char **paths,
632632
void *data;
633633
unsigned long size;
634634
int hit;
635+
636+
read_sha1_lock();
635637
data = read_object_with_reference(obj->sha1, tree_type,
636638
&size, NULL);
639+
read_sha1_unlock();
640+
637641
if (!data)
638642
die("unable to read tree (%s)", sha1_to_hex(obj->sha1));
639643
init_tree_desc(&tree, data, size);

0 commit comments

Comments
 (0)