]> git.proxmox.com Git - libgit2.git/commitdiff
Fix the issues in git_shutdown
authorAnurag Gupta <anugupta@microsoft.com>
Tue, 6 May 2014 20:33:47 +0000 (13:33 -0700)
committerAnurag Gupta <anugupta@microsoft.com>
Tue, 6 May 2014 20:41:07 +0000 (13:41 -0700)
1) Call to git_shutdown results in setting git__n_shutdown_callbacks
to -1. Next call to git__on_shutdown results in ABW (Array Bound Write)
for array git__shutdown_callbacks. In the current Implementation,
git_atomic_dec is called git__n_shutdown_callbacks + 1 times. I have
modified it to a for loop so that it is more readable. It would not
set git__n_shutdown_callbacks to a negative number and reset the
elements of git__shutdown_callbacks to NULL.

2) In function git_sysdir_get, shutdown function is registered only if
git_sysdir__dirs_shutdown_set is set to 0. However, after this variable
is set to 1, it is never reset to 0. If git_sysdir_global_init is
called again from synchronized_threads_init it does not register
shutdown function for this subsystem.

src/global.c

index a64dce9ef3abbc44f337854d83d36e24c3d75948..4dfdcf43859e38920839370435fe6ab28937c326 100644 (file)
@@ -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();
+       }
 
 }