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

Constant strings cannot be deallocated: file Foundation/NSCFString.swift, line 118

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Done
    • Component/s: Foundation
    • Labels:
    • Environment:

      Linux w/ Swift 4

      Description

      I have a block of code throwing this fatal error, that seems to require a larger setup to occur.

      import Foundation
      
      func default_components(bucket: String, key: String? = nil, query_items: [URLQueryItem] = []) -> URLComponents {
          var components = URLComponents()
          components.scheme = "https"
          components.host = "endpoint"
          components.path = key == nil ? "/\(bucket)" : "/\(bucket)/\(key!)"
          components.queryItems = query_items
      
          return components
      }
      
      func list_objects(in bucket: String, prefix: String = "", marker: String = "", delimiter: String = "", max_keys: Int = 1000) -> URLRequest {
          var components = default_components(bucket: bucket)
          components.queryItems?.append(URLQueryItem(name: "prefix", value: prefix))
          components.queryItems?.append(URLQueryItem(name: "max-keys", value: String(max_keys))) // I think this is the line that crashes. But reducing further than this somehow eliminates the crash
          components.queryItems?.append(URLQueryItem(name: "marker", value: marker))
          components.queryItems?.append(URLQueryItem(name: "delimiter", value: delimiter))
      
      
          let headers: [String: String] = [
              "Date": "\(Date())",
          ]
      
          var request = URLRequest(url: components.url!, timeoutInterval: 60)
          request.httpMethod = "GET"
          for (key, value) in headers {
              request.addValue(value, forHTTPHeaderField: key)
          }
      
          return request
      }
      
      list_objects(
          in: "bucket",
          marker: ""
      )
      

      Something about the `components.queryItems?.append(URLQueryItem(name: "max-keys", value: String(max_keys)))` part is causing this to trip, but I can't isolate it further than this. But the above block seems to reproduce reliably for me.

      Fatal error: Constant strings cannot be deallocated: file Foundation/NSCFString.swift, line 118
      Process 12600 stopped
      * thread #1, name = 'repl_swift', stop reason = signal SIGILL: illegal instruction operand
          frame #0: 0x00007ffff7b2a800 libswiftCore.so`function signature specialization <preserving fragile attribute, Arg[1] = Exploded> of Swift._assertionFailure(Swift.StaticString, Swift.String, file: Swift.StaticString, line: Swift.UInt, flags: Swift.UInt32) -> Swift.Never + 144
      libswiftCore.so`function signature specialization <preserving fragile attribute, Arg[1] = Exploded> of Swift._assertionFailure(Swift.StaticString, Swift.String, file: Swift.StaticString, line: Swift.UInt, flags: Swift.UInt32) -> Swift.Never:
      ->  0x7ffff7b2a800 <+144>: ud2    
          0x7ffff7b2a802:        nopw   %cs:(%rax,%rax)
      libswiftCore.so`function signature specialization <preserving fragile attribute, Arg[0] = Exploded, Arg[1] = Dead> of static Swift.Unicode.hashASCII(Swift.UnsafeBufferPointer<Swift.UInt8>) -> Swift.Int:
          0x7ffff7b2a810 <+0>:   pushq  %rbp
          0x7ffff7b2a811 <+1>:   movq   %rsp, %rbp
      Target 0: (repl_swift) stopped.
      Execution interrupted. Enter code to recover and continue.
      Enter LLDB commands to investigate (type :help for assistance.)
      
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                p_thompson Paul Thompson
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: