]> Cypherpunks repositories - gostls13.git/commitdiff
syscall: release a js.Func object in fsCall
authorHajime Hoshi <hajimehoshi@gmail.com>
Sun, 2 Feb 2020 05:55:29 +0000 (14:55 +0900)
committerHajime Hoshi <hajimehoshi@gmail.com>
Sat, 22 Feb 2020 16:12:46 +0000 (16:12 +0000)
(This is a reland of golang.org/cl/217417.)

A js.Func object in fsCall was created for each call but never
released. This CL fixes this.

Change-Id: Ifc0efb997c9b3e04641839691ccc04de61ef28d6
Reviewed-on: https://go-review.googlesource.com/c/go/+/220537
Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
src/syscall/fs_js.go

index 16d9f58b8c4a48789ea3392107f391274a43885e..c1cac97d91b25578a6c22928693f7ef519c55ff5 100644 (file)
@@ -495,7 +495,7 @@ func fsCall(name string, args ...interface{}) (js.Value, error) {
        }
 
        c := make(chan callResult, 1)
-       jsFS.Call(name, append(args, js.FuncOf(func(this js.Value, args []js.Value) interface{} {
+       f := js.FuncOf(func(this js.Value, args []js.Value) interface{} {
                var res callResult
 
                if len(args) >= 1 { // on Node.js 8, fs.utimes calls the callback without any arguments
@@ -511,7 +511,9 @@ func fsCall(name string, args ...interface{}) (js.Value, error) {
 
                c <- res
                return nil
-       }))...)
+       })
+       defer f.Release()
+       jsFS.Call(name, append(args, f)...)
        res := <-c
        return res.val, res.err
 }