mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-23 03:17:43 +00:00
all: fix more resource leaks found by staticmajor
Updates #5706 Signed-off-by: Emmanuel T Odeke <emmanuel@orijtech.com>
This commit is contained in:

committed by
Brad Fitzpatrick

parent
614a24763b
commit
680f8d9793
@@ -88,6 +88,8 @@ func runMonitor(ctx context.Context, loop bool) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer mon.Close()
|
||||
|
||||
mon.RegisterChangeCallback(func(changed bool, st *interfaces.State) {
|
||||
if !changed {
|
||||
log.Printf("Link monitor fired; no change")
|
||||
@@ -162,7 +164,7 @@ func getURL(ctx context.Context, urlStr string) error {
|
||||
return res.Write(os.Stdout)
|
||||
}
|
||||
|
||||
func checkDerp(ctx context.Context, derpRegion string) error {
|
||||
func checkDerp(ctx context.Context, derpRegion string) (err error) {
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", ipn.DefaultControlURL+"/derpmap/default", nil)
|
||||
if err != nil {
|
||||
return fmt.Errorf("create derp map request: %w", err)
|
||||
@@ -201,6 +203,12 @@ func checkDerp(ctx context.Context, derpRegion string) error {
|
||||
|
||||
c1 := derphttp.NewRegionClient(priv1, log.Printf, getRegion)
|
||||
c2 := derphttp.NewRegionClient(priv2, log.Printf, getRegion)
|
||||
defer func() {
|
||||
if err != nil {
|
||||
c1.Close()
|
||||
c2.Close()
|
||||
}
|
||||
}()
|
||||
|
||||
c2.NotePreferred(true) // just to open it
|
||||
|
||||
|
@@ -564,6 +564,8 @@ func tryEngine(logf logger.Logf, linkMon *monitor.Mon, dialer *tsdial.Dialer, na
|
||||
}
|
||||
d, err := dns.NewOSConfigurator(logf, devName)
|
||||
if err != nil {
|
||||
dev.Close()
|
||||
r.Close()
|
||||
return nil, false, fmt.Errorf("dns.NewOSConfigurator: %w", err)
|
||||
}
|
||||
conf.DNS = d
|
||||
|
@@ -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 {
|
||||
|
Reference in New Issue
Block a user