-
Notifications
You must be signed in to change notification settings - Fork 28
Open
Description
Let's look at gluecodium/src/test/resources/smoke/basic_types/output/swift/smoke/BasicTypes.swift as an example
gluecodium/gluecodium/src/test/resources/smoke/basic_types/output/swift/smoke/BasicTypes.swift
Line 13 in 17d604a
| smoke_BasicTypes_remove_swift_object_from_wrapper_cache(c_instance) |
deinit {
smoke_BasicTypes_remove_swift_object_from_wrapper_cache(c_instance) <--- HERE
smoke_BasicTypes_release_handle(c_instance)
}
gluecodium/gluecodium/src/test/resources/smoke/basic_types/output/swift/smoke/BasicTypes.swift
Line 101 in 17d604a
| if let swift_pointer = smoke_BasicTypes_get_swift_object_from_wrapper_cache(handle), |
internal func BasicTypes_copyFromCType(_ handle: _baseRef) -> BasicTypes {
if let swift_pointer = smoke_BasicTypes_get_swift_object_from_wrapper_cache(handle), <--- HERE
let re_constructed = Unmanaged<AnyObject>.fromOpaque(swift_pointer).takeUnretainedValue() as? BasicTypes {
return re_constructed
}
- Thread A is just in
deinit, but has not calledsmoke_BasicTypes_remove_swift_object_from_wrapper_cacheyet, we have a dangling pointer to a dead swift object in the cache. - Thread B is just calling
smoke_BasicTypes_get_swift_object_from_wrapper_cacheat the same time and gets the dead swift object - Thread B will crash
To repro, have two threads doing:
while true {
// get some class from native side
let foo = gluecodium.foo()
// call some function on it
foo.bar()
// foo.deinit() will now be called here due to ARC
}
Metadata
Metadata
Assignees
Labels
No labels