Browse Source

Note that Buffer.Unmarshal does NOT reset the destination protobuf.

When repeatedly Unmarshalling into the same destination, this can cause a memory leak.
PiperOrigin-RevId: 135304939
notcarl 9 years ago
parent
commit
1976b9edad
1 changed files with 2 additions and 0 deletions
  1. 2 0
      proto/decode.go

+ 2 - 0
proto/decode.go

@@ -340,6 +340,8 @@ func (p *Buffer) DecodeGroup(pb Message) error {
 // Buffer and places the decoded result in pb.  If the struct
 // Buffer and places the decoded result in pb.  If the struct
 // underlying pb does not match the data in the buffer, the results can be
 // underlying pb does not match the data in the buffer, the results can be
 // unpredictable.
 // unpredictable.
+//
+// Unlike proto.Unmarshal, this does not reset pb before starting to unmarshal.
 func (p *Buffer) Unmarshal(pb Message) error {
 func (p *Buffer) Unmarshal(pb Message) error {
 	// If the object can unmarshal itself, let it.
 	// If the object can unmarshal itself, let it.
 	if u, ok := pb.(Unmarshaler); ok {
 	if u, ok := pb.(Unmarshaler); ok {