Skip to content

Commit

Permalink
global: reset global state on shutdown without threading
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pks-t committed Nov 2, 2016
1 parent 59c6c28 commit 038f0e1
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/global.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down

0 comments on commit 038f0e1

Please sign in to comment.