Skip to content

Commit

Permalink
fix panic nil packet buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
Yohan Totting committed Apr 8, 2024
1 parent 13daf98 commit 0ec3c3a
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions packetbuffers.go
Expand Up @@ -156,6 +156,15 @@ Loop:
func (p *packetBuffers) pop(el *list.Element) *rtppool.RetainablePacket {
pkt := el.Value.(*rtppool.RetainablePacket)

if err := pkt.Retain(); err != nil {
// already released
return nil
}

defer func() {
pkt.Release()
}()

// make sure packet is not late
if IsRTPPacketLate(pkt.Header().SequenceNumber, p.lastSequenceNumber) {
glog.Warning("packet cache: packet sequence ", pkt.Header().SequenceNumber, " is too late, last sent was ", p.lastSequenceNumber)
Expand Down Expand Up @@ -286,6 +295,14 @@ func (p *packetBuffers) Pop() *rtppool.RetainablePacket {
}

item := frontElement.Value.(*rtppool.RetainablePacket)
if err := item.Retain(); err != nil {
return nil
}

defer func() {
item.Release()
}()

if IsRTPPacketLate(item.Header().SequenceNumber, p.lastSequenceNumber) {

return p.pop(frontElement)
Expand Down

0 comments on commit 0ec3c3a

Please sign in to comment.