grep: take the read-lock when adding a submodule
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 <bmwill@google.com> Signed-off-by: Martin Ågren <martin.agren@gmail.com> Acked-by: Brandon Williams <bmwill@google.com> Reviewed-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
f9ee2fcdfa
commit
9560e6245a
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user