Skip to content

Commit

Permalink
Fix netkitten memory leak from infinite deferred functions (#4284)
Browse files Browse the repository at this point in the history
  • Loading branch information
tinnywang authored Aug 15, 2024
1 parent fd8cbef commit c9c7482
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions misc/netkitten/netkitten.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@ func main() {
for {
// If given a target, work with it first
var cconn net.Conn
defer func() {
if cconn != nil {
cconn.Close()
}
}()
if target != "" {
var err error
cconn, err = net.Dial("tcp", target)
Expand Down Expand Up @@ -82,6 +77,7 @@ func main() {
conn.Close()
} else if cconn != nil {
io.Copy(os.Stdout, cconn)
cconn.Close()
}

if !*loop {
Expand Down

0 comments on commit c9c7482

Please sign in to comment.