Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-2275

Fix memory leak in golang compact_protocol.

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 0.9.2
    • Component/s: Go - Library
    • Labels:
      None
    • Environment:

      os x 10.9

      Description

      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 }

        Attachments

          Activity

            People

            • Assignee:
              jensg Jens Geyer
              Reporter:
              wizardcypress bolin huang
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: