Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-9536] UnsafeMutableRawPointer invokes the wrong free function #51986

Closed
compnerd opened this issue Dec 18, 2018 · 4 comments
Closed

[SR-9536] UnsafeMutableRawPointer invokes the wrong free function #51986

compnerd opened this issue Dec 18, 2018 · 4 comments
Assignees
Labels
standard library Area: Standard library umbrella

Comments

@compnerd
Copy link
Collaborator

Previous ID SR-9536
Radar None
Original Reporter @compnerd
Type Sub-task
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Sub-task
Assignee @atrick
Priority Medium

md5: 17f0c1f5303061ada2b9db8c6260b0bf

Parent-Task:

Issue 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.

@compnerd
Copy link
Collaborator Author

CC: @atrick @gottesmm

@atrick
Copy link
Member

atrick commented Dec 20, 2018

I've been working on how to fix this without affecting the ABI at all. I'll post a PR ASAP.

@compnerd
Copy link
Collaborator Author

compnerd commented Jan 2, 2019

@atrick, awesome![]( Thanks for the help)

@compnerd
Copy link
Collaborator Author

compnerd commented Jan 6, 2019

Thanks for the help here @atrick! We should cross-port this to 5.0.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
standard library Area: Standard library umbrella
Projects
None yet
Development

No branches or pull requests

2 participants