Skip to content

Use uninitialized dealloc in swift_deallocError #19059

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

Merged
merged 1 commit into from
Sep 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion stdlib/public/runtime/ErrorObjectNative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ swift::swift_allocError(const swift::Metadata *type,
void
swift::swift_deallocError(SwiftError *error, const Metadata *type) {
auto sizeAndAlign = _getErrorAllocatedSizeAndAlignmentMask(type);
swift_deallocObject(error, sizeAndAlign.first, sizeAndAlign.second);
swift_deallocUninitializedObject(error, sizeAndAlign.first, sizeAndAlign.second);
}

void
Expand Down
20 changes: 20 additions & 0 deletions test/stdlib/Error.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,5 +160,25 @@ ErrorTests.test("unsigned raw value") {
expectEqual(-1, negOne._code)
}

ErrorTests.test("test dealloc empty error box") {
struct Foo<T>: Error { let value: T }

func makeFoo<T>() throws -> Foo<T> {
throw Foo(value: "makeFoo throw error")
}

func makeError<T>(of: T.Type) throws -> Error {
return try makeFoo() as Foo<T>
}

do {
_ = try makeError(of: Int.self)
} catch let foo as Foo<String> {
expectEqual(foo.value, "makeFoo throw error")
} catch {
expectUnreachableCatch(error)
}
}

runAllTests()