Skip to content

Commit

Permalink
WIP: grep: remove racy call to repo_clear()
Browse files Browse the repository at this point in the history
When grepping with --recurse-submodules, grep_submodule() is invoked for
each subrepository to initialize it. At the end of this function,
repo_clear() is called to properly remove the subrepo from memory. When
grepping with threads, however, the call to this function may happen
before the threads have actually finished grepping the subrepo. This
could make Git run into a race condition and possible segmentation
fault. So let's remove the repo_clear() call. This is not the best
solution as it can degrade memory. But to properly handle the subrepo
cleaning, we would need to keep a mapping of subrepos' identifiers to
the number of objects not grepped yet, or something like this.

Signed-off-by: Matheus Tavares <matheus.bernardino@usp.br>
  • Loading branch information
matheustavares committed Aug 19, 2019
1 parent bee4195 commit 2262495
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion builtin/grep.c
Expand Up @@ -482,7 +482,12 @@ static int grep_submodule(struct grep_opt *opt,
hit = grep_cache(&subopt, pathspec, cached);
}

repo_clear(&subrepo);
/*
* NEEDSWORK: The subrepo should be cleaned after use, calling
* repo_clear(&subrepo). It's not possible to do it here, however, as
* threads might still be working on the subrepo's objects.
*/

return hit;
}

Expand Down

0 comments on commit 2262495

Please sign in to comment.