[libcxx] r291743 - [libc++] Pair _aligned_malloc with _aligned_free

Shoaib Meenai via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 11 22:22:36 PST 2017


Author: smeenai
Date: Thu Jan 12 00:22:36 2017
New Revision: 291743

URL: http://llvm.org/viewvc/llvm-project?rev=291743&view=rev
Log:
[libc++] Pair _aligned_malloc with _aligned_free

Attempting to pair an `_aligned_malloc` with a regular free causes heap
corruption. Pairing with `_aligned_free` is required instead.

Makes the following libc++ tests pass on Windows:

```
std/language.support/support.dynamic/new.delete/new.delete.array/new_align_val_t.pass.cpp
std/language.support/support.dynamic/new.delete/new.delete.array/new_align_val_t_nothrow.pass.cpp
std/language.support/support.dynamic/new.delete/new.delete.single/new_align_val_t.pass.cpp
std/language.support/support.dynamic/new.delete/new.delete.single/new_align_val_t_nothrow.pass.cpp
```

Differential Revision: https://reviews.llvm.org/D28512

Modified:
    libcxx/trunk/src/new.cpp

Modified: libcxx/trunk/src/new.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/new.cpp?rev=291743&r1=291742&r2=291743&view=diff
==============================================================================
--- libcxx/trunk/src/new.cpp (original)
+++ libcxx/trunk/src/new.cpp Thu Jan 12 00:22:36 2017
@@ -198,7 +198,11 @@ void
 operator delete(void* ptr, std::align_val_t) _NOEXCEPT
 {
     if (ptr)
+#if defined(_LIBCPP_MSVCRT)
+        ::_aligned_free(ptr);
+#else
         ::free(ptr);
+#endif
 }
 
 _LIBCPP_WEAK




More information about the cfe-commits mailing list