Skip to content

Commit

Permalink
Merge pull request #583 from matheusd/fix-transport-double-release
Browse files Browse the repository at this point in the history
transport: Fix double release instances of {in,out}goingMsg
  • Loading branch information
lthibault committed Aug 14, 2024
2 parents e51721e + df83d72 commit 5f525fa
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions rpc/transport/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (s *transport) RecvMessage() (IncomingMessage, error) {
return nil, err
}

return incomingMsg(rmsg), nil
return &incomingMsg{message: rmsg}, nil
}

// Close closes the underlying ReadWriteCloser. It is not safe to call
Expand Down Expand Up @@ -219,6 +219,7 @@ type outgoingMsg struct {

func (o *outgoingMsg) Release() {
if m := o.message.Message(); !o.released && m != nil {
o.released = true
m.Release()
}
}
Expand All @@ -235,14 +236,18 @@ func (o *outgoingMsg) Send() error {
panic("call to Send() after call to Release()")
}

type incomingMsg rpccp.Message
type incomingMsg struct {
message rpccp.Message
released bool
}

func (i incomingMsg) Message() rpccp.Message {
return rpccp.Message(i)
func (i *incomingMsg) Message() rpccp.Message {
return i.message
}

func (i incomingMsg) Release() {
if m := i.Message().Message(); m != nil {
func (i *incomingMsg) Release() {
if m := i.Message().Message(); !i.released && m != nil {
i.released = true
m.Release()
}
}

0 comments on commit 5f525fa

Please sign in to comment.