libgit2_shutdown: clear err message on shutdown

Clear the error message on git_libgit2_shutdown for all versions of
the library (no threads and Win32 threads).  Drop the giterr_clear
in clar, as that shouldn't be necessary.
This commit is contained in:
Edward Thomson 2015-03-03 14:10:50 -05:00 committed by Carlos Martín Nieto
parent 3a8b69d13d
commit 83fe60fa1b
2 changed files with 27 additions and 10 deletions

View File

@ -36,16 +36,25 @@ void git__on_shutdown(git_global_shutdown_fn callback)
git__shutdown_callbacks[count - 1] = callback; git__shutdown_callbacks[count - 1] = callback;
} }
static void git__global_state_cleanup(git_global_st *st)
{
if (!st)
return;
git__free(st->error_t.message);
st->error_t.message = NULL;
}
static void git__shutdown(void) static void git__shutdown(void)
{ {
int pos; int pos;
/* Shutdown subsystems that have registered */
for (pos = git_atomic_get(&git__n_shutdown_callbacks); pos > 0; pos = git_atomic_dec(&git__n_shutdown_callbacks)) { 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); git_global_shutdown_fn cb = git__swap(git__shutdown_callbacks[pos - 1], NULL);
if (cb != NULL) if (cb != NULL)
cb(); cb();
} }
} }
#if defined(GIT_THREADS) && defined(GIT_SSL) #if defined(GIT_THREADS) && defined(GIT_SSL)
@ -214,8 +223,14 @@ int git_libgit2_init(void)
static void synchronized_threads_shutdown(void) static void synchronized_threads_shutdown(void)
{ {
void *ptr;
/* Shut down any subsystems that have global state */ /* Shut down any subsystems that have global state */
git__shutdown(); git__shutdown();
ptr = TlsGetValue(_tls_index);
git__global_state_cleanup(ptr);
TlsFree(_tls_index); TlsFree(_tls_index);
git_mutex_free(&git__mwindow_mutex); git_mutex_free(&git__mwindow_mutex);
} }
@ -263,7 +278,7 @@ int init_error = 0;
static void cb__free_status(void *st) static void cb__free_status(void *st)
{ {
giterr_clear(); git__global_state_cleanup(st);
git__free(st); git__free(st);
} }
@ -300,23 +315,23 @@ int git_libgit2_shutdown(void)
pthread_once_t new_once = PTHREAD_ONCE_INIT; pthread_once_t new_once = PTHREAD_ONCE_INIT;
int ret; int ret;
if ((ret = git_atomic_dec(&git__n_inits)) > 0) if ((ret = git_atomic_dec(&git__n_inits)) != 0)
return ret; return ret;
/* Shut down any subsystems that have global state */ /* Shut down any subsystems that have global state */
git__shutdown(); git__shutdown();
giterr_clear();
ptr = pthread_getspecific(_tls_key); ptr = pthread_getspecific(_tls_key);
pthread_setspecific(_tls_key, NULL); pthread_setspecific(_tls_key, NULL);
git__global_state_cleanup(ptr);
git__free(ptr); git__free(ptr);
pthread_key_delete(_tls_key); pthread_key_delete(_tls_key);
git_mutex_free(&git__mwindow_mutex); git_mutex_free(&git__mwindow_mutex);
_once_init = new_once; _once_init = new_once;
return ret; return 0;
} }
git_global_st *git__global_state(void) git_global_st *git__global_state(void)
@ -358,10 +373,13 @@ int git_libgit2_shutdown(void)
int ret; int ret;
/* Shut down any subsystems that have global state */ /* Shut down any subsystems that have global state */
if (ret = git_atomic_dec(&git__n_inits)) if ((ret = git_atomic_dec(&git__n_inits)) != 0)
git__shutdown(); return ret;
return ret; git__shutdown();
git__global_state_cleanup(&__state);
return 0;
} }
git_global_st *git__global_state(void) git_global_st *git__global_state(void)

View File

@ -20,7 +20,6 @@ int main(int argc, char *argv[])
clar_test_shutdown(); clar_test_shutdown();
giterr_clear();
cl_global_trace_disable(); cl_global_trace_disable();
git_libgit2_shutdown(); git_libgit2_shutdown();