diff options
| author | Russell Belfer <rb@github.com> | 2013-09-11 12:45:20 -0700 |
|---|---|---|
| committer | Russell Belfer <rb@github.com> | 2013-09-17 09:31:45 -0700 |
| commit | a3aa5f4d5dcbe038f1d1c5ff40eed29d27953fbe (patch) | |
| tree | 6ef7a6b5bdfc26e10279c2629f58036f4025f199 /src/fileops.c | |
| parent | e7d0ced2192c5efeea6d9f5667d366891010b86a (diff) | |
| download | libgit2-a3aa5f4d5dcbe038f1d1c5ff40eed29d27953fbe.tar.gz | |
Add simple global shutdown hooks
Increasingly there are a number of components that want to do some
cleanup at global shutdown time (at least if there are not going
to be memory leaks). This creates a very simple system of shutdown
hooks that will be invoked by git_threads_shutdown. Right now, the
maximum number of hooks is hardcoded, but since adding a hook is
not a public API, it should be fine and I thought it was better to
start off with really simple code.
Diffstat (limited to 'src/fileops.c')
| -rw-r--r-- | src/fileops.c | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/fileops.c b/src/fileops.c index 126d45f26..3b271e6f6 100644 --- a/src/fileops.c +++ b/src/fileops.c @@ -6,6 +6,7 @@ */ #include "common.h" #include "fileops.h" +#include "global.h" #include <ctype.h> #if GIT_WIN32 #include "win32/findfile.h" @@ -635,6 +636,13 @@ static git_futils_dirs_guess_cb git_futils__dir_guess[GIT_FUTILS_DIR__MAX] = { git_futils_guess_xdg_dirs, }; +static void git_futils_dirs_global_shutdown(void) +{ + int i; + for (i = 0; i < GIT_FUTILS_DIR__MAX; ++i) + git_buf_free(&git_futils__dirs[i]); +} + int git_futils_dirs_global_init(void) { git_futils_dir_t i; @@ -644,6 +652,8 @@ int git_futils_dirs_global_init(void) for (i = 0; !error && i < GIT_FUTILS_DIR__MAX; i++) error = git_futils_dirs_get(&path, i); + git__on_shutdown(git_futils_dirs_global_shutdown); + return error; } @@ -726,13 +736,6 @@ int git_futils_dirs_set(git_futils_dir_t which, const char *search_path) return git_buf_oom(&git_futils__dirs[which]) ? -1 : 0; } -void git_futils_dirs_free(void) -{ - int i; - for (i = 0; i < GIT_FUTILS_DIR__MAX; ++i) - git_buf_free(&git_futils__dirs[i]); -} - static int git_futils_find_in_dirlist( git_buf *path, const char *name, git_futils_dir_t which, const char *label) { |
