Skip to content

Commit

Permalink
修复encrypt.Conn释放内存,导致的潜在panic问题.
Browse files Browse the repository at this point in the history
  • Loading branch information
snail007 committed Sep 21, 2018
1 parent 1ab07c8 commit 20761d2
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions core/lib/transport/encrypt/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package encrypt

import (
"crypto/cipher"
"fmt"
"io"
"net"

Expand Down Expand Up @@ -33,15 +34,23 @@ func NewConn(c net.Conn, method, password string) (conn net.Conn, err error) {
return
}
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)
}
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)
}
func (s *Conn) Close() (err error) {
err = s.Conn.Close()
s.Cipher = nil
s.r = nil
s.w = nil
return err
if s.Cipher != nil {
err = s.Conn.Close()
s.Cipher = nil
s.r = nil
s.w = nil
}
return
}

0 comments on commit 20761d2

Please sign in to comment.