ttrpc: return buffers to pool

Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
Stephen J Day 2017-11-29 21:32:38 -08:00
parent 8f839f204c
commit 5859cd7b45
No known key found for this signature in database
GPG Key ID: 67B3DED84EDC823F
2 changed files with 3 additions and 0 deletions

View File

@ -206,5 +206,6 @@ func (c *Client) recv(resp *Response, msg *message) error {
return errors.New("unkown message type received") return errors.New("unkown message type received")
} }
defer c.channel.putmbuf(msg.p)
return proto.Unmarshal(msg.p, resp) return proto.Unmarshal(msg.p, resp)
} }

View File

@ -325,11 +325,13 @@ func (c *serverConn) run(sctx context.Context) {
var req Request var req Request
if err := c.server.codec.Unmarshal(p, &req); err != nil { if err := c.server.codec.Unmarshal(p, &req); err != nil {
ch.putmbuf(p)
if !sendImmediate(mh.StreamID, status.Newf(codes.InvalidArgument, "unmarshal request error: %v", err)) { if !sendImmediate(mh.StreamID, status.Newf(codes.InvalidArgument, "unmarshal request error: %v", err)) {
return return
} }
continue continue
} }
ch.putmbuf(p)
if mh.StreamID%2 != 1 { if mh.StreamID%2 != 1 {
// enforce odd client initiated identifiers. // enforce odd client initiated identifiers.