From 9560e6245a1a0b7483a57d7018e5b7a852fdba62 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Martin=20=C3=85gren?= Date: Wed, 1 Nov 2017 21:45:06 +0100 Subject: [PATCH] grep: take the read-lock when adding a submodule MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit With --recurse-submodules, we add each submodule that we encounter to the list of alternate object databases. With threading, our changes to the list are not protected against races. Indeed, ThreadSanitizer reports a race when we call `add_to_alternates_memory()` around the same time that another thread is reading in the list through `read_sha1_file()`. Take the grep read-lock while adding the submodule. The lock is used to serialize uses of non-thread-safe parts of Git's API, including `read_sha1_file()`. Helped-by: Brandon Williams Signed-off-by: Martin Ågren Acked-by: Brandon Williams Reviewed-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/grep.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/builtin/grep.c b/builtin/grep.c index cd0e51f3c0..6946cf4bbc 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -431,7 +431,9 @@ static int grep_submodule(struct grep_opt *opt, struct repository *superproject, * store is no longer global and instead is a member of the repository * object. */ + grep_read_lock(); add_to_alternates_memory(submodule.objectdir); + grep_read_unlock(); if (oid) { struct object *object; -- 2.47.1