[x265] [PATCH] Fix SEI buffer memory leaks
Pavan Tarun Chakka Venkata
pavan.tarun at multicorewareinc.com
Fri Dec 13 11:44:21 UTC 2024
>From c64bccd79a63ec3e7a3fdeeaa21656730695dd2b Mon Sep 17 00:00:00 2001
From: Min Chen <chenm003 at 163.com>
Date: Thu, 28 Nov 2024 16:09:28 -0800
Subject: [PATCH 1/3] Fix SEI buffer memory leaks
---
source/encoder/encoder.cpp | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/source/encoder/encoder.cpp b/source/encoder/encoder.cpp
index 2e65cb1a9..e3285bbae 100644
--- a/source/encoder/encoder.cpp
+++ b/source/encoder/encoder.cpp
@@ -1082,6 +1082,16 @@ void Encoder::copyUserSEIMessages(Frame *frame,
const x265_picture* pic_in)
}
int numPayloads = pic_in->userSEI.numPayloads + toneMapPayload +
userPayload;
+
+ // TODO: we may reuse buffer if become smaller than exist buffer
+ if (frame->m_userSEI.payloads && numPayloads !=
frame->m_userSEI.numPayloads)
+ {
+ for (int i = 0; i < frame->m_userSEI.numPayloads; i++)
+ delete[] frame->m_userSEI.payloads[i].payload;
+ delete[] frame->m_userSEI.payloads;
+ frame->m_userSEI.payloads = NULL;
+ }
+
frame->m_userSEI.numPayloads = numPayloads;
if (frame->m_userSEI.numPayloads)
@@ -1102,6 +1112,12 @@ void Encoder::copyUserSEIMessages(Frame *frame,
const x265_picture* pic_in)
else
input = pic_in->userSEI.payloads[i];
+ // TODO: condition may improve, because buffer size may change
from big to small, but never back to original allocate size
+ if (frame->m_userSEI.payloads[i].payload &&
frame->m_userSEI.payloads[i].payloadSize < input.payloadSize)
+ {
+ delete[] frame->m_userSEI.payloads[i].payload;
+ frame->m_userSEI.payloads[i].payload = NULL;
+ }
if (!frame->m_userSEI.payloads[i].payload)
frame->m_userSEI.payloads[i].payload = new
uint8_t[input.payloadSize];
memcpy(frame->m_userSEI.payloads[i].payload, input.payload,
input.payloadSize);
--
2.35.1.windows.2
On Fri, Dec 13, 2024 at 8:03 AM Pavan Tarun Chakka Venkata <
pavan.tarun at multicorewareinc.com> wrote:
> From c64bccd79a63ec3e7a3fdeeaa21656730695dd2b Mon Sep 17 00:00:00 2001
> From: Test <test at test.com>
> Date: Thu, 28 Nov 2024 16:09:28 -0800
> Subject: [PATCH 1/3] Fix SEI buffer memory leaks
>
> ---
> source/encoder/encoder.cpp | 16 ++++++++++++++++
> 1 file changed, 16 insertions(+)
>
> diff --git a/source/encoder/encoder.cpp b/source/encoder/encoder.cpp
> index 2e65cb1a9..e3285bbae 100644
> --- a/source/encoder/encoder.cpp
> +++ b/source/encoder/encoder.cpp
> @@ -1082,6 +1082,16 @@ void Encoder::copyUserSEIMessages(Frame *frame,
> const x265_picture* pic_in)
> }
>
> int numPayloads = pic_in->userSEI.numPayloads + toneMapPayload +
> userPayload;
> +
> + // TODO: we may reuse buffer if become smaller than exist buffer
> + if (frame->m_userSEI.payloads && numPayloads !=
> frame->m_userSEI.numPayloads)
> + {
> + for (int i = 0; i < frame->m_userSEI.numPayloads; i++)
> + delete[] frame->m_userSEI.payloads[i].payload;
> + delete[] frame->m_userSEI.payloads;
> + frame->m_userSEI.payloads = NULL;
> + }
> +
> frame->m_userSEI.numPayloads = numPayloads;
>
> if (frame->m_userSEI.numPayloads)
> @@ -1102,6 +1112,12 @@ void Encoder::copyUserSEIMessages(Frame *frame,
> const x265_picture* pic_in)
> else
> input = pic_in->userSEI.payloads[i];
>
> + // TODO: condition may improve, because buffer size may
> change from big to small, but never back to original allocate size
> + if (frame->m_userSEI.payloads[i].payload &&
> frame->m_userSEI.payloads[i].payloadSize < input.payloadSize)
> + {
> + delete[] frame->m_userSEI.payloads[i].payload;
> + frame->m_userSEI.payloads[i].payload = NULL;
> + }
> if (!frame->m_userSEI.payloads[i].payload)
> frame->m_userSEI.payloads[i].payload = new
> uint8_t[input.payloadSize];
> memcpy(frame->m_userSEI.payloads[i].payload, input.payload,
> input.payloadSize);
> --
> 2.35.1.windows.2
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20241213/4545e3c0/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Fix-SEI-buffer-memory-leaks.patch
Type: application/octet-stream
Size: 1958 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20241213/4545e3c0/attachment.obj>
More information about the x265-devel
mailing list