Skip to content

Commit 9560e62

Browse files
Martin Ågrengitster
authored andcommitted
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 <[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]>
1 parent f9ee2fc commit 9560e62

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

builtin/grep.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,9 @@ static int grep_submodule(struct grep_opt *opt, struct repository *superproject,
431431
* store is no longer global and instead is a member of the repository
432432
* object.
433433
*/
434+
grep_read_lock();
434435
add_to_alternates_memory(submodule.objectdir);
436+
grep_read_unlock();
435437

436438
if (oid) {
437439
struct object *object;

0 commit comments

Comments
 (0)