win32: crtdbg: provide independent `free` function Currently, the `git__free` function is being defined in a single place, only, disregarding whether we use our standard allocators or the crtdbg allocators. This makes it a bit harder to convert our code base to use pluggable allocators, and furthermore makes the border between our two allocators a bit more blurry. Implement a separate `git__crtdbg__free` function for the crtdbg allocator in order to completely separate both allocator implementations.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
diff --git a/src/util.h b/src/util.h
index 67ae4ef..5b1354c 100644
--- a/src/util.h
+++ b/src/util.h
@@ -79,6 +79,7 @@
#define git__realloc(ptr, size) git__crtdbg__realloc(ptr, size, __FILE__, __LINE__)
#define git__reallocarray(ptr, nelem, elsize) git__crtdbg__reallocarray(ptr, nelem, elsize, __FILE__, __LINE__)
#define git__mallocarray(nelem, elsize) git__crtdbg__mallocarray(nelem, elsize, __FILE__, __LINE__)
+#define git__free git__crtdbg__free
#else
@@ -169,13 +170,13 @@ GIT_INLINE(void *) git__mallocarray(size_t nelem, size_t elsize)
return git__reallocarray(NULL, nelem, elsize);
}
-#endif /* !MSVC_CTRDBG */
-
GIT_INLINE(void) git__free(void *ptr)
{
free(ptr);
}
+#endif /* !MSVC_CTRDBG */
+
#define STRCMP_CASESELECT(IGNORE_CASE, STR1, STR2) \
((IGNORE_CASE) ? strcasecmp((STR1), (STR2)) : strcmp((STR1), (STR2)))
diff --git a/src/win32/w32_crtdbg_stacktrace.c b/src/win32/w32_crtdbg_stacktrace.c
index e26766a..6164fed 100644
--- a/src/win32/w32_crtdbg_stacktrace.c
+++ b/src/win32/w32_crtdbg_stacktrace.c
@@ -145,6 +145,11 @@ void *git__crtdbg__mallocarray(size_t nelem, size_t elsize, const char *file, in
return git__crtdbg__reallocarray(NULL, nelem, elsize, file, line);
}
+void git__crtdbg__free(void *ptr)
+{
+ free(ptr);
+}
+
/**
* Compare function for bsearch on g_cs_index table.
*/
@@ -415,4 +420,5 @@ const char *git_win32__crtdbg_stacktrace(int skip, const char *file)
return result;
}
+
#endif
diff --git a/src/win32/w32_crtdbg_stacktrace.h b/src/win32/w32_crtdbg_stacktrace.h
index 5527d6c..f70891a 100644
--- a/src/win32/w32_crtdbg_stacktrace.h
+++ b/src/win32/w32_crtdbg_stacktrace.h
@@ -105,6 +105,7 @@ char *git__crtdbg__substrdup(const char *start, size_t n, const char *file, int
void *git__crtdbg__realloc(void *ptr, size_t size, const char *file, int line);
void *git__crtdbg__reallocarray(void *ptr, size_t nelem, size_t elsize, const char *file, int line);
void *git__crtdbg__mallocarray(size_t nelem, size_t elsize, const char *file, int line);
+void *git__crtdbg__free(void *ptr);
#endif
#endif