Commit 496b0df2ca2a115d2e5a7099f2b8fd6d7409fcb2

Patrick Steinhardt 2018-03-14T10:28:50

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.

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