Debian Codegraph @

src/util/allocators/win32_leakcheck.c

raw
1 /*
2 * Copyright (C) the libgit2 contributors. All rights reserved.
3 *
4 * This file is part of libgit2, distributed under the GNU GPL v2 with
5 * a Linking Exception. For full terms see the included COPYING file.
6 */
7
8 #include "win32_leakcheck.h"
9
10 #if defined(GIT_WIN32_LEAKCHECK)
11
12 #include "win32/w32_leakcheck.h"
13
14 static void *leakcheck_malloc(size_t len, const char *file, int line)
15 {
16 void *ptr = _malloc_dbg(len, _NORMAL_BLOCK, git_win32_leakcheck_stacktrace(1,file), line);
17 if (!ptr) git_error_set_oom();
18 return ptr;
19 }
20
21 static void *leakcheck_realloc(void *ptr, size_t size, const char *file, int line)
22 {
23 void *new_ptr = _realloc_dbg(ptr, size, _NORMAL_BLOCK, git_win32_leakcheck_stacktrace(1,file), line);
24 if (!new_ptr) git_error_set_oom();
25 return new_ptr;
26 }
27
28 static void leakcheck_free(void *ptr)
29 {
30 free(ptr);
31 }
32
33 int git_win32_leakcheck_init_allocator(git_allocator *allocator)
34 {
35 allocator->gmalloc = leakcheck_malloc;
36 allocator->grealloc = leakcheck_realloc;
37 allocator->gfree = leakcheck_free;
38 return 0;
39 }
40
41 #else
42
43 int git_win32_leakcheck_init_allocator(git_allocator *allocator)
44 {
45 GIT_UNUSED(allocator);
46 git_error_set(GIT_EINVALID, "leakcheck memory allocator not available");
47 return -1;
48 }
49
50 #endif