all: fix more resource leaks found by staticmajor

Updates #5706

Signed-off-by: Emmanuel T Odeke <emmanuel@orijtech.com>
This commit is contained in:
Emmanuel T Odeke
2022-09-27 00:37:27 +02:00
committed by Brad Fitzpatrick
parent 614a24763b
commit 680f8d9793
7 changed files with 45 additions and 3 deletions

View File

@@ -187,7 +187,12 @@ func buildWasm(dev bool) ([]byte, error) {
return nil, fmt.Errorf("Cannot create main.wasm output file: %w", err)
}
outputPath := outputFile.Name()
defer os.Remove(outputPath)
// Running defer (*os.File).Close() in defer order before os.Remove
// because on some systems like Windows, it is possible for os.Remove
// to fail for unclosed files.
defer outputFile.Close()
args := []string{"build", "-tags", "tailscale_go,osusergo,netgo,nethttpomithttp2,omitidna,omitpemdecrypt"}
if !dev {