You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Henrique Mendonça (JIRA)" <ji...@apache.org> on 2013/11/28 15:20:39 UTC

[jira] [Updated] (THRIFT-2275) Fix memory leak in golang compact_protocol.

     [ https://issues.apache.org/jira/browse/THRIFT-2275?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henrique Mendonça updated THRIFT-2275:
--------------------------------------

    Component/s: Go - Library

> Fix memory leak in golang compact_protocol.
> -------------------------------------------
>
>                 Key: THRIFT-2275
>                 URL: https://issues.apache.org/jira/browse/THRIFT-2275
>             Project: Thrift
>          Issue Type: Bug
>          Components: Go - Library
>         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)