diff --git a/src/global.c b/src/global.c index a64dce9ef..4dfdcf438 100644 --- a/src/global.c +++ b/src/global.c @@ -31,11 +31,11 @@ static void git__shutdown(void) { int 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; - } + 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(); + } }