Fix netns fd leak in ListenNetworkNamespace

This commit is contained in:
Heng lu 2026-03-08 23:57:15 -04:00 committed by 世界
parent 1d388547ee
commit 2ba896c5ac
No known key found for this signature in database
GPG key ID: CD109927C34A63C4

View file

@ -151,6 +151,7 @@ func ListenNetworkNamespace[T any](nameOrPath string, block func() (T, error)) (
if err != nil {
return common.DefaultValue[T](), E.Cause(err, "get current netns")
}
defer currentNs.Close()
defer netns.Set(currentNs)
var targetNs netns.NsHandle
if strings.HasPrefix(nameOrPath, "/") {