diff --git a/connection_impl.go b/connection_impl.go index 2fd7a4ae..5236977b 100644 --- a/connection_impl.go +++ b/connection_impl.go @@ -354,9 +354,9 @@ func (c *connection) initFinalizer() { c.stop(flushing) // stop the finalizing state to prevent conn.fill function to be performed c.stop(finalizing) + freeop(c.operator) c.netFD.Close() c.closeBuffer() - freeop(c.operator) return nil }) } diff --git a/nocopy_linkbuffer.go b/nocopy_linkbuffer.go index d091099f..83b0e6c3 100644 --- a/nocopy_linkbuffer.go +++ b/nocopy_linkbuffer.go @@ -668,6 +668,8 @@ func (b *LinkBuffer) recalLen(delta int) (length int) { // Nodes with size <= 0 are marked as readonly, which means the node.buf is not allocated by this mcache. func newLinkBufferNode(size int) *linkBufferNode { var node = linkedPool.Get().(*linkBufferNode) + // reset node offset + node.off, node.malloc, node.refer, node.readonly = 0, 0, 1, false if size <= 0 { node.readonly = true return node @@ -754,14 +756,11 @@ func (node *linkBufferNode) Release() (err error) { } // release self if atomic.AddInt32(&node.refer, -1) == 0 { - node.off, node.malloc, node.refer, node.origin, node.next = 0, 0, 1, nil, nil // readonly nodes cannot recycle node.buf, other node.buf are recycled to mcache. - if node.readonly { - node.readonly = false - } else { + if !node.readonly { free(node.buf) } - node.buf = nil + node.buf, node.origin, node.next = nil, nil, nil linkedPool.Put(node) } return nil diff --git a/nocopy_linkbuffer_race.go b/nocopy_linkbuffer_race.go index bd42dc23..b80c6be9 100644 --- a/nocopy_linkbuffer_race.go +++ b/nocopy_linkbuffer_race.go @@ -717,6 +717,8 @@ func (b *LinkBuffer) recalLen(delta int) (length int) { // Nodes with size <= 0 are marked as readonly, which means the node.buf is not allocated by this mcache. func newLinkBufferNode(size int) *linkBufferNode { var node = linkedPool.Get().(*linkBufferNode) + // reset node offset + node.off, node.malloc, node.refer, node.readonly = 0, 0, 1, false if size <= 0 { node.readonly = true return node @@ -803,14 +805,11 @@ func (node *linkBufferNode) Release() (err error) { } // release self if atomic.AddInt32(&node.refer, -1) == 0 { - node.off, node.malloc, node.refer, node.origin, node.next = 0, 0, 1, nil, nil // readonly nodes cannot recycle node.buf, other node.buf are recycled to mcache. - if node.readonly { - node.readonly = false - } else { + if !node.readonly { free(node.buf) } - node.buf = nil + node.buf, node.origin, node.next = nil, nil, nil linkedPool.Put(node) } return nil diff --git a/nocopy_linkbuffer_test.go b/nocopy_linkbuffer_test.go index 8c79e70b..9af49fb6 100644 --- a/nocopy_linkbuffer_test.go +++ b/nocopy_linkbuffer_test.go @@ -316,7 +316,6 @@ func TestLinkBufferRefer(t *testing.T) { MustNil(t, err) MustTrue(t, rbuf.head != node1) MustTrue(t, buf.head == node2) - Equal(t, node1.Len(), 0) err = buf.Release() MustNil(t, err)