Skip to content

Commit 297a710

Browse files
committed
Fix leak due to missing free after a host function call.
1 parent 4dab822 commit 297a710

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

Package.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ let package = Package(
1616
"-Xlinker",
1717
"--export=swjs_call_host_function",
1818
"-Xlinker",
19-
"--export=swjs_prepare_host_function_call"
19+
"--export=swjs_prepare_host_function_call",
20+
"-Xlinker",
21+
"--export=swjs_cleanup_host_function_call"
2022
])
2123
]),
2224
.target(

Runtime/src/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ declare const global: GlobalVariable;
1111

1212
interface SwiftRuntimeExportedFunctions {
1313
swjs_prepare_host_function_call(size: number): pointer;
14+
swjs_cleanup_host_function_call(argv: pointer): void;
1415
swjs_call_host_function(
1516
host_func_id: number,
1617
argv: pointer, argc: number,
@@ -112,6 +113,7 @@ export class SwiftRuntime {
112113
output = result
113114
})
114115
exports.swjs_call_host_function(host_func_id, argv, argc, callback_func_ref)
116+
exports.swjs_cleanup_host_function_call(argv)
115117
return output
116118
}
117119

Sources/JavaScriptKit/JSFunction.swift

+5
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ public func _prepare_host_function_call(_ argc: Int32) -> UnsafeMutableRawPointe
7676
return malloc(Int(argumentSize))!
7777
}
7878

79+
@_cdecl("swjs_cleanup_host_function_call")
80+
public func _cleanup_host_function_call(_ pointer: UnsafeMutableRawPointer) {
81+
free(pointer)
82+
}
83+
7984
@_cdecl("swjs_call_host_function")
8085
public func _call_host_function(
8186
_ hostFuncRef: JavaScriptHostFuncRef,

0 commit comments

Comments
 (0)