Skip to content

[SR-6398] Constant strings cannot be deallocated: file Foundation/NSCFString.swift, line 118 #4053

Closed
@swift-ci

Description

@swift-ci
Previous ID SR-6398
Radar None
Original Reporter p_thompson (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Linux w/ Swift 4

Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug, RunTimeCrash
Assignee None
Priority Medium

md5: 8f4158106464e25abf1dd3e4e488841a

is duplicated by:

  • SR-6422 Encountering "Constant strings cannot be deallocated" in Linux foundation

Issue 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 #&#8203;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.)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions