smb: fix TCP connection leak when connection setup fails - fixes #9678

If revealing the password, creating the Kerberos client or the SMB
handshake failed after the TCP connection was established, the
connection was never closed.
This commit is contained in:
Nick Craig-Wood
2026-07-30 17:48:54 +01:00
parent 76d1adb7a6
commit 74f9f182aa
+7 -1
View File
@@ -21,12 +21,18 @@ import (
// initiates the SMB handshake, and then sets up a Client.
//
// The context is only used for establishing the connection, not after.
func (f *Fs) dial(ctx context.Context, network, addr string) (*conn, error) {
func (f *Fs) dial(ctx context.Context, network, addr string) (c *conn, err error) {
dialer := fshttp.NewDialer(ctx)
tconn, err := dialer.DialContext(ctx, network, addr)
if err != nil {
return nil, err
}
// Close tconn it if any of the remaining setup fails.
defer func() {
if err != nil {
_ = tconn.Close()
}
}()
pass := ""
if f.opt.Pass != "" {