From 09402100946e6892ebd1e75773eb390cdd7f28ab Mon Sep 17 00:00:00 2001 From: Paul Cristian Sarbu Date: Fri, 12 May 2023 13:14:26 +0200 Subject: memcheck: fix race in libgit2... ...caused by incorrectly setting and resetting the library internal state and the misuse of pthreads in libgit2. Normally, git_libgit2_init and git_libgit2_shutdown should span the life of a worker thread in order to be safely used. However, due to an incorrect implementation of libgit2's threadstate with pthreads, on unix systems there is a race condition. Until the use of pthread_key_t is corrected in libgit2, we need to apply a workaround by always ensuring that the main thread is the first thread reaching the GitContext constructor. --- src/buildtool/file_system/git_context.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/buildtool/file_system/git_context.cpp') diff --git a/src/buildtool/file_system/git_context.cpp b/src/buildtool/file_system/git_context.cpp index 04d4498d..084e9d58 100644 --- a/src/buildtool/file_system/git_context.cpp +++ b/src/buildtool/file_system/git_context.cpp @@ -15,6 +15,7 @@ #include "src/buildtool/file_system/git_context.hpp" #include "src/buildtool/logging/logger.hpp" +#include "src/utils/cpp/gsl.hpp" extern "C" { #include @@ -34,4 +35,9 @@ GitContext::~GitContext() noexcept { git_libgit2_shutdown(); } #endif -} \ No newline at end of file +} + +void GitContext::Create() noexcept { + static GitContext git_state{}; + Expects(git_state.initialized_); +} -- cgit v1.2.3