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:
@@ -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 != "" {
|
||||
|
||||
Reference in New Issue
Block a user