base: pair AlignedAlloc with AlignedFree
The previous CL introduced a bug on Windows, where
memory returned by _aligned_malloc() must be freed
by _aligned_free() not just free().
Since we are here, I am introducing a AlignedUniquePtr<T>
that makes the paring less error-prone.
Bug: 205302474
Bug: crbug.com/1269359
Change-Id: I4582ed0005233537ca0009434165673a7e14a76b
diff --git a/src/base/utils.cc b/src/base/utils.cc
index c080388..b5d3d3c 100644
--- a/src/base/utils.cc
+++ b/src/base/utils.cc
@@ -258,5 +258,13 @@
return res;
}
+void AlignedFree(void* ptr) {
+#if PERFETTO_BUILDFLAG(PERFETTO_OS_WIN)
+ _aligned_free(ptr); // MSDN says it is fine to pass nullptr.
+#else
+ free(ptr);
+#endif
+}
+
} // namespace base
} // namespace perfetto