Skip to content

Commit 20db2a4

Browse files
eecksteinmeg-gupta
authored andcommitted
stdlib: add a missing fixLifetime in withVaList
If this function is inlined, the optimizer can shrink the lifetime of the `args` parameter. This would deallocate the passed arguments (e.g. `NSString`s) before the are used in the closure.
1 parent 9d3b2dd commit 20db2a4

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

stdlib/public/core/VarArgs.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@ public func withVaList<R>(_ args: [CVarArg],
159159
for a in args {
160160
builder.append(a)
161161
}
162-
return _withVaList(builder, body)
162+
let result = _withVaList(builder, body)
163+
_fixLifetime(args)
164+
return result
163165
}
164166

165167
/// Invoke `body` with a C `va_list` argument derived from `builder`.

0 commit comments

Comments
 (0)