Skip to content

Commit 381cae6

Browse files
committed
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.
1 parent 364be39 commit 381cae6

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

stdlib/public/core/UnsafePointer.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,8 @@ public struct UnsafeMutablePointer<Pointee>: _Pointer {
580580
/// block. The memory must not be initialized or `Pointee` must be a trivial type.
581581
@inlinable
582582
public func deallocate() {
583-
Builtin.deallocRaw(_rawValue, (-1)._builtinWordValue, (-1)._builtinWordValue)
583+
Builtin.deallocRaw(_rawValue, (-1)._builtinWordValue,
584+
Builtin.alignof(Pointee.self))
584585
}
585586

586587
/// Accesses the instance referenced by this pointer.

0 commit comments

Comments
 (0)