Skip to content

Commit

Permalink
stdlib: pass along alignment for dealloc
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
compnerd committed Nov 20, 2018
1 parent 364be39 commit 381cae6
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion stdlib/public/core/UnsafePointer.swift
Expand Up @@ -580,7 +580,8 @@ public struct UnsafeMutablePointer<Pointee>: _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.
Expand Down

0 comments on commit 381cae6

Please sign in to comment.