Uploaded image for project: 'Swift'
  1. Swift
  2. SR-15527

Crash with unused unowned reference to deinited object

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Medium
    • Resolution: Done
    • Component/s: swift
    • Labels:
      None
    • Environment:

      macOS 11.6, Xcode 13.1, Swift version 5.5.1 (swiftlang-1300.0.31.4 clang-1300.0.29.6) & Apple Swift version 5.6-dev (LLVM 27222cde774bd6b, Swift 17f1cf92973d2c1) I

      Description

      I’m seeing a crash when releasing an object containing an unowned reference to an already-release object.

      In the sample code attached, the unowned reference: unowned var parent? = nil is set to self in setArgParents, where self is guaranteed to be valid. parent is never read or otherwise used by the sample code anywhere.

      Is the mere existence of an unowned reference not allowed? Or is only not allowed to use it after the referenced object is deinited?

      Notes:
      Compiling the project in debug mode will not crash.
      Compiling the project in release mode with Disable Safety Checks to Yes will not crash.
      Using the development snapshot toolchain Apple Swift version 5.6-dev (LLVM 27222cde774bd6b, Swift 17f1cf92973d2c1) I see the crash regardless of Disable Safety Checks settings.
      Manually setting the child node’s parent to nil before removing the last strong reference to child node in flatten avoids the crash, also, in the ifdef’d out version of flatten()

      (Apple feedback reported to FB9782558)

      Expected output:
      (vector(X,1),vector((Y,2),1))
      vector((X,Y,2),(1,1))

      Observet output:
      (vector(X,1),vector((Y,2),1))
      UnownedReferenceCrash(4984,0x1000d3d40) malloc: Non-aligned pointer 0x16fdff2d8 being freed

      Additional discussion can be found at https://forums.swift.org/t/trying-to-understand-an-unowned-reference-crash/53704 (I’ve included everything I think relevent_ here in the bug report.)

       

        Attachments

          Activity

            People

            Assignee:
            d066z Dogghie Haroldh
            Reporter:
            Ron Avitzur Ron Avitzur
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: