diff options
| author | Edward Thomson <ethomson@edwardthomson.com> | 2018-10-21 09:52:32 +0100 |
|---|---|---|
| committer | Edward Thomson <ethomson@edwardthomson.com> | 2018-10-21 13:14:47 +0100 |
| commit | 305e801acb2b13dca4e08ad00c638c22337c25bf (patch) | |
| tree | bc5987b5534181b4c70756436ac2a779527a0398 /src/alloc.c | |
| parent | 671b2446b7805089cbc9dad9db216d13938b1393 (diff) | |
| download | libgit2-305e801acb2b13dca4e08ad00c638c22337c25bf.tar.gz | |
util: allow callers to reset custom allocators
Provide a utility to reset custom allocators back to their default.
This is particularly useful for testing.
Diffstat (limited to 'src/alloc.c')
| -rw-r--r-- | src/alloc.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/alloc.c b/src/alloc.c index d4e6f1ebd..0cac457d4 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -15,6 +15,15 @@ git_allocator git__allocator; +static int setup_default_allocator(void) +{ +#if defined(GIT_MSVC_CRTDBG) + return git_win32_crtdbg_init_allocator(&git__allocator); +#else + return git_stdalloc_init_allocator(&git__allocator); +#endif +} + int git_allocator_global_init(void) { /* @@ -24,15 +33,14 @@ int git_allocator_global_init(void) if (git__allocator.gmalloc != NULL) return 0; -#if defined(GIT_MSVC_CRTDBG) - return git_win32_crtdbg_init_allocator(&git__allocator); -#else - return git_stdalloc_init_allocator(&git__allocator); -#endif + return setup_default_allocator(); } int git_allocator_setup(git_allocator *allocator) { + if (!allocator) + return setup_default_allocator(); + memcpy(&git__allocator, allocator, sizeof(*allocator)); return 0; } |
