bolin huang created THRIFT-2275:
-----------------------------------

             Summary: Fix memory leak in golang compact_protocol.
                 Key: THRIFT-2275
                 URL: https://issues.apache.org/jira/browse/THRIFT-2275
             Project: Thrift
          Issue Type: Bug
         Environment: os x 10.9 
            Reporter: bolin huang
             Fix For: 1.0


After a long time running go program base on compact protocol, I found that the 
memory is just increase and never drop. After using go tool pprof to check the 
memory usage, I found in `ReadStructBegin` it push `lastFieldId` to the slice 
p.lastField. But in `ReadStructEnd`, it just assign the last element in 
`p.lastField` to `lastFieldId` and do not pop the last element.
So the length of `p.lastField` is just increasing...
To fix the bug,we need to pop the last element as the patch shows below:

diff --git a/lib/go/thrift/compact_protocol.go 
b/lib/go/thrift/compact_protocol.go
index 74d36d0..f89fc2f 100644
--- a/lib/go/thrift/compact_protocol.go
+++ b/lib/go/thrift/compact_protocol.go
@@ -352,6 +352,7 @@ func (p *TCompactProtocol) ReadStructBegin() (name string, 
err error) {
 func (p *TCompactProtocol) ReadStructEnd() error {
        // consume the last field we read off the wire.
        p.lastFieldId = p.lastField[len(p.lastField)-1]
+       p.lastField = p.lastField[:len(p.lastField)-1]
        return nil
 }




--
This message was sent by Atlassian JIRA
(v6.1#6144)

Reply via email to