diff options
Diffstat (limited to 'src/alloc.c')
-rw-r--r-- | src/alloc.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/alloc.c b/src/alloc.c index 6972e7b59..9ec90297f 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -8,6 +8,7 @@ #include "alloc.h" #include "runtime.h" +#include "allocators/failalloc.h" #include "allocators/stdalloc.h" #include "allocators/win32_crtdbg.h" @@ -16,7 +17,18 @@ # include "win32/w32_crtdbg_stacktrace.h" #endif -git_allocator git__allocator; +/* Fail any allocation until git_libgit2_init is called. */ +git_allocator git__allocator = { + git_failalloc_malloc, + git_failalloc_calloc, + git_failalloc_strdup, + git_failalloc_strndup, + git_failalloc_substrdup, + git_failalloc_realloc, + git_failalloc_reallocarray, + git_failalloc_mallocarray, + git_failalloc_free +}; static int setup_default_allocator(void) { @@ -49,7 +61,7 @@ int git_allocator_global_init(void) * We don't want to overwrite any allocator which has been set before * the init function is called. */ - if (git__allocator.gmalloc != NULL) + if (git__allocator.gmalloc != git_failalloc_malloc) return 0; return setup_default_allocator(); |