]> Cypherpunks repositories - gostls13.git/commitdiff
internal/poll: avoid memory leak in Writev
authortaoyuanyuan <linuxty@gmail.com>
Sun, 19 May 2019 23:23:04 +0000 (23:23 +0000)
committerIan Lance Taylor <iant@golang.org>
Mon, 20 May 2019 01:53:24 +0000 (01:53 +0000)
The chunks that were referenced by fd.iovecs would not be GC.

Change-Id: I7bfcb91a3fef57a4a1861168e9cd3ab55ce1334e
GitHub-Last-Rev: e0b7f68447441fd89ed1a6e8aa37e2084fd863b2
GitHub-Pull-Request: golang/go#32138
Reviewed-on: https://go-review.googlesource.com/c/go/+/178037
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/internal/poll/writev.go

index a48a38be0846d27fc3766b07374c267b984c2655..6050d1f6423ba7ac9f1df9ecfd9b47c6c594999c 100644 (file)
@@ -64,6 +64,9 @@ func (fd *FD) Writev(v *[][]byte) (int64, error) {
                TestHookDidWritev(int(wrote))
                n += int64(wrote)
                consume(v, int64(wrote))
+               for i := range iovecs {
+                       iovecs[i] = syscall.Iovec{}
+               }
                if err != nil {
                        if err.(syscall.Errno) == syscall.EAGAIN {
                                if err = fd.pd.waitWrite(fd.isFile); err == nil {