diff options
author | Russell Belfer <rb@github.com> | 2014-05-06 16:11:03 -0700 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2014-05-06 16:11:03 -0700 |
commit | ed476c236b8328c31acb150ee69eaf00c821b9e3 (patch) | |
tree | e1bb4dcb9e7d08a2f90af51e582b41531728c43a | |
parent | 1051100025c1075fa1b7f003dad7db086791b583 (diff) | |
parent | 0bf5430dc77c69d2b2d27a771b584b17cedb97ec (diff) | |
download | libgit2-ed476c236b8328c31acb150ee69eaf00c821b9e3.tar.gz |
Merge pull request #2329 from anuraggup/fix_git_shutdown
Fix the issues in git_shutdown
-rw-r--r-- | src/global.c | 10 | ||||
-rw-r--r-- | src/sysdir.c | 2 |
2 files changed, 8 insertions, 4 deletions
diff --git a/src/global.c b/src/global.c index 15baf1eb8..4dfdcf438 100644 --- a/src/global.c +++ b/src/global.c @@ -23,7 +23,7 @@ static git_atomic git__n_inits; void git__on_shutdown(git_global_shutdown_fn callback) { int count = git_atomic_inc(&git__n_shutdown_callbacks); - assert(count <= MAX_SHUTDOWN_CB); + assert(count <= MAX_SHUTDOWN_CB && count > 0); git__shutdown_callbacks[count - 1] = callback; } @@ -31,10 +31,12 @@ static void git__shutdown(void) { int pos; - while ((pos = git_atomic_dec(&git__n_shutdown_callbacks)) >= 0) { - if (git__shutdown_callbacks[pos]) - git__shutdown_callbacks[pos](); + for (pos = git_atomic_get(&git__n_shutdown_callbacks); pos > 0; pos = git_atomic_dec(&git__n_shutdown_callbacks)) { + git_global_shutdown_fn cb = git__swap(git__shutdown_callbacks[pos - 1], NULL); + if (cb != NULL) + cb(); } + } /** diff --git a/src/sysdir.c b/src/sysdir.c index e0c24f3b3..cd94a8b57 100644 --- a/src/sysdir.c +++ b/src/sysdir.c @@ -90,6 +90,8 @@ void git_sysdir_global_shutdown(void) int i; for (i = 0; i < GIT_SYSDIR__MAX; ++i) git_buf_free(&git_sysdir__dirs[i]); + + git_sysdir__dirs_shutdown_set = 0; } static int git_sysdir_check_selector(git_sysdir_t which) |