From 4930468c6ca8fc3791d43f20584598e2d038146c Mon Sep 17 00:00:00 2001 From: Einav Rivni Date: Sun, 6 Nov 2022 11:28:06 +0200 Subject: [PATCH] use copy instead of append to avoid memory leak --- codecs/h265_packet.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/codecs/h265_packet.go b/codecs/h265_packet.go index 340d077..c9eafa2 100644 --- a/codecs/h265_packet.go +++ b/codecs/h265_packet.go @@ -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 { } @@ -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 }