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

Crash due to memory issue while using whole optimization

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Duplicate
    • Component/s: Compiler
    • Environment:

      macOS Sierra 10.12.4 (16E195)
      Xcode 8.3.1 (8E1000a)
      Apple Swift version 3.1 (swiftlang-802.0.51 clang-802.0.41)
      Target: x86_64-apple-macosx10.9

      Description

      Problem:

      Application crashed in randomly placed due to using flatMap with structs and using whole optimization:

              let directions = self.data.forecast?.flatMap { forecast -> Direction? in
                  guard let date = forecast.date else {
                      return nil
                  }
                  
                  let rotation = forecast.direction?.radians ?? 0
                  return Direction(date: date, rotationInRadians: rotation)
              }
      

      Address Sanitizer shows double free problem on second iteration at this line:

                  return WeatherChartWindDirection(date: date, rotationInRadians: rotation)
      
      ==75521==ERROR: AddressSanitizer: heap-use-after-free on address 0x60400006c260 at pc 0x00010a628740 bp 0x7fff555d74b0 sp 0x7fff555d74a8
      WRITE of size 8 at 0x60400006c260 thread T0
      

      Test project to repeat issue is attached

      Workaround:

      Turn off whole optimization.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned
              Reporter:
              alekite Alexander Burakov
              Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: