From 381cae6df0186e1fc92edad331397ccefcddce4d Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Tue, 20 Nov 2018 13:56:06 -0800 Subject: [PATCH] stdlib: pass along alignment for dealloc Ensure that UnsafeMutablePointer.deallocate has the alignment that was used when invoking UnsafeMutablePointer.allocate. This is required to ensure that the appropriate `free` function is invoked. We would previously fail on Windows as the allocation would use `malloc` and due to the value being `-1`, use `_aligned_free` instead when deallocating. --- stdlib/public/core/UnsafePointer.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stdlib/public/core/UnsafePointer.swift b/stdlib/public/core/UnsafePointer.swift index a5d9bd9e27a98..010377927fcb1 100644 --- a/stdlib/public/core/UnsafePointer.swift +++ b/stdlib/public/core/UnsafePointer.swift @@ -580,7 +580,8 @@ public struct UnsafeMutablePointer: _Pointer { /// block. The memory must not be initialized or `Pointee` must be a trivial type. @inlinable public func deallocate() { - Builtin.deallocRaw(_rawValue, (-1)._builtinWordValue, (-1)._builtinWordValue) + Builtin.deallocRaw(_rawValue, (-1)._builtinWordValue, + Builtin.alignof(Pointee.self)) } /// Accesses the instance referenced by this pointer.