summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2016-11-02 08:49:24 +0100
committerPatrick Steinhardt <ps@pks.im>2016-11-02 08:53:52 +0100
commit038f0e1b4cf6333d9835776b72e6bf8fe4975de5 (patch)
tree3077a5df22a329583157d6516891f88433c2c882
parent59c6c2860a573521a96a402f8232127ceb27b0f6 (diff)
downloadlibgit2-038f0e1b4cf6333d9835776b72e6bf8fe4975de5.tar.gz
global: reset global state on shutdown without threading
When threading is not enabled for libgit2, we keep global state in a simple static variable. When libgit2 is shut down, we clean up the global state by freeing the global state's dynamically allocated memory. When libgit2 is built with threading, we additionally free the thread-local storage and thus completely remove the global state. In a non-threaded build, though, we simply leave the global state as-is, which may result in an error upon reinitializing libgit2. Fix the issue by zeroing out the variable on a shutdown, thus returning it to its initial state.
-rw-r--r--src/global.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/global.c b/src/global.c
index de722c7e8..e2ad8fe71 100644
--- a/src/global.c
+++ b/src/global.c
@@ -341,7 +341,7 @@ int git_libgit2_init(void)
{
int ret;
- /* Only init SSL the first time */
+ /* Only init subsystems the first time */
if ((ret = git_atomic_inc(&git__n_inits)) != 1)
return ret;
@@ -359,6 +359,7 @@ int git_libgit2_shutdown(void)
if ((ret = git_atomic_dec(&git__n_inits)) == 0) {
shutdown_common();
git__global_state_cleanup(&__state);
+ memset(&__state, 0, sizeof(__state));
}
return ret;