grep: take the read-lock when adding a submodule
authorMartin Ågren <redacted>
Wed, 1 Nov 2017 20:45:06 +0000 (21:45 +0100)
committerJunio C Hamano <redacted>
Thu, 2 Nov 2017 01:58:08 +0000 (10:58 +0900)
commit9560e6245a1a0b7483a57d7018e5b7a852fdba62
treebc9dba86af84553eda04fe6c4008590d744e3c17
parentf9ee2fcdfa05586b6a4476c7aa5f4f0162e48455
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 <redacted>
Signed-off-by: Martin Ågren <redacted>
Acked-by: Brandon Williams <redacted>
Reviewed-by: Jeff King <redacted>
Signed-off-by: Junio C Hamano <redacted>
builtin/grep.c
git clone https://git.99rst.org/PROJECT