Commit 76fa877f authored by Jeromy Johnson's avatar Jeromy Johnson Committed by GitHub

Merge pull request #10 from libp2p/fix/mem-leak

be more careful about holding onto things forever
parents d26dd414 995821d3
......@@ -82,7 +82,6 @@ func (s *secureSession) RemotePublicKey() ci.PubKey {
// Close closes the secure session
func (s *secureSession) Close() error {
s.cancel()
s.handshakeMu.Lock()
defer s.handshakeMu.Unlock()
if s.secure == nil {
......
......@@ -41,8 +41,7 @@ const nonceSize = 16
// secureSession encapsulates all the parameters needed for encrypting
// and decrypting traffic from an insecure channel.
type secureSession struct {
ctx context.Context
cancel context.CancelFunc
ctx context.Context
secure msgio.ReadWriteCloser
insecure io.ReadWriteCloser
......@@ -72,7 +71,6 @@ func (s *secureSession) Loggable() map[string]interface{} {
func newSecureSession(ctx context.Context, local peer.ID, key ci.PrivKey, insecure io.ReadWriteCloser) (*secureSession, error) {
s := &secureSession{localPeer: local, localKey: key}
s.ctx, s.cancel = context.WithCancel(ctx)
switch {
case s.localPeer == "":
......@@ -110,6 +108,7 @@ func (s *secureSession) Handshake() error {
// keys, IDs, and initiate communication, assigning all necessary params.
// requires the duplex channel to be a msgio.ReadWriter (for framed messaging)
func (s *secureSession) runHandshake() error {
defer func() { s.ctx = nil }() // clear to save memory
ctx, cancel := context.WithTimeout(s.ctx, HandshakeTimeout) // remove
defer cancel()
......
......@@ -82,4 +82,6 @@ func TestBasicETMStream(t *testing.T) {
if string(before) != string(msg) {
t.Fatal("got wrong message")
}
r.Close()
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment