From ca5f5db2a1fe91dad539434c9d9b72c8044f7add Mon Sep 17 00:00:00 2001 From: kihamo Date: Wed, 16 Oct 2019 16:58:30 +0300 Subject: [PATCH] #1 panic in xmeye --- providers/xmeye/connection.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/providers/xmeye/connection.go b/providers/xmeye/connection.go index 9da8b1e1..37e5a5d1 100644 --- a/providers/xmeye/connection.go +++ b/providers/xmeye/connection.go @@ -9,11 +9,11 @@ import ( type connection struct { protocol.Conn - sync.Mutex - _ [4]byte sessionID uint32 sequenceNumber uint32 + + lock sync.Mutex } func (c *connection) SessionID() uint32 { @@ -23,7 +23,7 @@ func (c *connection) SessionID() uint32 { func (c *connection) SessionIDAsString() (id string) { session := Uint32(c.SessionID()) - if b, err := session.MarshalJSON(); err != nil { + if b, err := session.MarshalJSON(); err == nil { id = string(b) } @@ -43,8 +43,8 @@ func (c *connection) InSequenceNumber() { } func (c *connection) send(packet *packet) error { - c.Lock() - defer c.Unlock() + c.lock.Lock() + defer c.lock.Unlock() packet.SessionID = c.SessionID() packet.SequenceNumber = c.SequenceNumber() @@ -59,8 +59,8 @@ func (c *connection) send(packet *packet) error { } func (c *connection) receive() (*packet, error) { - c.Lock() - defer c.Unlock() + c.lock.Lock() + defer c.lock.Unlock() head := make([]byte, 0x14) // read head if _, err := c.Conn.Read(head); err != nil {