From a9d3dd79f59fbdfb3428fb5ee2043efbc36028e0 Mon Sep 17 00:00:00 2001 From: wangzhuowei Date: Tue, 28 Nov 2023 14:29:18 +0800 Subject: [PATCH] fix: barrier mem leak --- connection_reactor.go | 1 + sys_exec.go | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/connection_reactor.go b/connection_reactor.go index cd5d717c..619c7a15 100644 --- a/connection_reactor.go +++ b/connection_reactor.go @@ -74,6 +74,7 @@ func (c *connection) closeBuffer() { } if c.outputBuffer.Len() == 0 || onConnect != nil || onRequest != nil { c.outputBuffer.Close() + c.outputBarrier.reset() barrierPool.Put(c.outputBarrier) } } diff --git a/sys_exec.go b/sys_exec.go index 1c8e40e4..965aa968 100644 --- a/sys_exec.go +++ b/sys_exec.go @@ -62,6 +62,16 @@ type barrier struct { ivs []syscall.Iovec } +func (b *barrier) reset() { + for i := range b.bs { + b.bs[i] = nil + } + for i := range b.ivs { + b.ivs[i].Base = nil + b.ivs[i].Len = 0 + } +} + // writev wraps the writev system call. func writev(fd int, bs [][]byte, ivs []syscall.Iovec) (n int, err error) { iovLen := iovecs(bs, ivs)