diff options
author | Anurag Gupta <anugupta@microsoft.com> | 2014-05-06 12:16:24 -0700 |
---|---|---|
committer | Anurag Gupta <anugupta@microsoft.com> | 2014-05-06 12:16:24 -0700 |
commit | 001befcdd5a208a046e0196e3fec7b16041cfe14 (patch) | |
tree | b8ee090f90ce37f7661852093a2bd3a80922ef6e /src/global.c | |
parent | d2c16e9ac4921e94eb5db972e6b8452d71a623fc (diff) | |
download | libgit2-001befcdd5a208a046e0196e3fec7b16041cfe14.tar.gz |
Fix the issues in git__on_shutdown
Diffstat (limited to 'src/global.c')
-rw-r--r-- | src/global.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/global.c b/src/global.c index 15baf1eb8..a64dce9ef 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)) + if (git__shutdown_callbacks[pos - 1]) { + git__shutdown_callbacks[pos - 1](); + git__shutdown_callbacks[pos - 1] = NULL; + } + } /** |