Skip to content

Fix leak due to missing free after a host function call. #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ let package = Package(
"-Xlinker",
"--export=swjs_call_host_function",
"-Xlinker",
"--export=swjs_prepare_host_function_call"
"--export=swjs_prepare_host_function_call",
"-Xlinker",
"--export=swjs_cleanup_host_function_call"
])
]),
.target(
Expand Down
2 changes: 2 additions & 0 deletions Runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ declare const global: GlobalVariable;

interface SwiftRuntimeExportedFunctions {
swjs_prepare_host_function_call(size: number): pointer;
swjs_cleanup_host_function_call(argv: pointer): void;
swjs_call_host_function(
host_func_id: number,
argv: pointer, argc: number,
Expand Down Expand Up @@ -112,6 +113,7 @@ export class SwiftRuntime {
output = result
})
exports.swjs_call_host_function(host_func_id, argv, argc, callback_func_ref)
exports.swjs_cleanup_host_function_call(argv)
return output
}

Expand Down
5 changes: 5 additions & 0 deletions Sources/JavaScriptKit/JSFunction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ public func _prepare_host_function_call(_ argc: Int32) -> UnsafeMutableRawPointe
return malloc(Int(argumentSize))!
}

@_cdecl("swjs_cleanup_host_function_call")
public func _cleanup_host_function_call(_ pointer: UnsafeMutableRawPointer) {
free(pointer)
}

@_cdecl("swjs_call_host_function")
public func _call_host_function(
_ hostFuncRef: JavaScriptHostFuncRef,
Expand Down