修复encrypt.Conn释放内存,导致的潜在panic问题.
This commit is contained in:
@ -2,6 +2,7 @@ package encrypt
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/cipher"
|
"crypto/cipher"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
@ -33,15 +34,23 @@ func NewConn(c net.Conn, method, password string) (conn net.Conn, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
func (s *Conn) Read(b []byte) (n int, err error) {
|
func (s *Conn) Read(b []byte) (n int, err error) {
|
||||||
|
if s.r == nil {
|
||||||
|
return 0, fmt.Errorf("use of closed connection")
|
||||||
|
}
|
||||||
return s.r.Read(b)
|
return s.r.Read(b)
|
||||||
}
|
}
|
||||||
func (s *Conn) Write(b []byte) (n int, err error) {
|
func (s *Conn) Write(b []byte) (n int, err error) {
|
||||||
|
if s.w == nil {
|
||||||
|
return 0, fmt.Errorf("use of closed connection")
|
||||||
|
}
|
||||||
return s.w.Write(b)
|
return s.w.Write(b)
|
||||||
}
|
}
|
||||||
func (s *Conn) Close() (err error) {
|
func (s *Conn) Close() (err error) {
|
||||||
err = s.Conn.Close()
|
if s.Cipher != nil {
|
||||||
s.Cipher = nil
|
err = s.Conn.Close()
|
||||||
s.r = nil
|
s.Cipher = nil
|
||||||
s.w = nil
|
s.r = nil
|
||||||
return err
|
s.w = nil
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user