Skip to content

Commit

Permalink
grep: take the read-lock when adding a submodule
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Martin Ågren <[email protected]>
Acked-by: Brandon Williams <[email protected]>
Reviewed-by: Jeff King <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
Martin Ågren authored and gitster committed Nov 2, 2017
1 parent f9ee2fc commit 9560e62
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions builtin/grep.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 9560e62

Please sign in to comment.