fix: 可能发生资源泄漏,在 for 循环中调用 defer

This commit is contained in:
tsosunchia
2023-12-08 16:16:38 +08:00
parent 5c4aa0c2de
commit ef0631fdab

View File

@@ -340,18 +340,15 @@ func testFile(paramsFastTrace ParamsFastTrace, tm bool) {
if err != nil {
return
}
defer func(fp *os.File) {
err := fp.Close()
if err != nil {
log.Fatal(err)
}
}(fp)
log.SetOutput(fp)
log.SetFlags(0)
log.Printf("『%s』\n", ip.Desc)
log.Printf("traceroute to %s, %d hops max, %d byte packets\n", ip.Ip, paramsFastTrace.MaxHops, paramsFastTrace.PktSize)
conf.RealtimePrinter = tracelog.RealtimePrinter
err = fp.Close()
if err != nil {
log.Fatal(err)
}
} else {
conf.RealtimePrinter = printer.RealtimePrinter
}