Skip to content

Commit

Permalink
use copy instead of append to avoid memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
Einav Rivni committed Nov 6, 2022
1 parent c7c34b5 commit 4930468
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions codecs/h265_packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,7 @@ func (p *H265Payloader) Payload(mtu uint16, payload []byte) [][]byte {
}

// H265SafariPayloader payloads H265 packets
// based on: https://github.com/AlexxIT/Blog/issues/5
type H265SafariPayloader struct {
}

Expand Down Expand Up @@ -1178,12 +1179,18 @@ func (p *H265SafariPayloader) Payload(mtu uint16, payload []byte) [][]byte {
maxSize := int(mtu)

for len(bufferedPayload) > int(mtu) {
payloads = append(payloads, bufferedPayload[:maxSize])
out := make([]byte, maxSize)
copy(out, bufferedPayload[:maxSize])

payloads = append(payloads, out)

// removed processed bytes
bufferedPayload = append([]byte{start}, bufferedPayload[maxSize:]...)
}

payloads = append(payloads, bufferedPayload)
out := make([]byte, len(bufferedPayload))
copy(out, bufferedPayload)

payloads = append(payloads, out)
return payloads
}

0 comments on commit 4930468

Please sign in to comment.