Uploaded image for project: 'Swift'
  1. Swift
  2. SR-9116 Windows Support
  3. SR-9536

UnsafeMutableRawPointer invokes the wrong free function

    XMLWordPrintable

    Details

    • Type: Sub-task
    • Status: Resolved
    • Priority: Medium
    • Resolution: Done
    • Component/s: Standard Library
    • Labels:
      None

      Description

      `UnsafeMutableRawPointer.deallocate` invokes `Builtin.deallocRaw` with -1 for the alignment mask.  This gets lowered to a call to `swift_slowDealloc`.  This will inspect the alignment and select between invoking `free` and `AlignedFree`.  This happens to work on macOS and Linux as you invoke `free` on both `malloc` results as well as `posix_memalign` results.  However, on Windows, this is not the case.  We need to match the `malloc` with `free` and `_aligned_alloc` with `_aligned_free`.  Since we do not preserve the memory alignment, we end up invoking the wrong `free` function with the memory.

        Attachments

          Activity

            People

            • Assignee:
              atrick Andrew Trick
              Reporter:
              compnerd Saleem Abdulrasool
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: