[x265] [PATCH 1/3] Memory Leak Fix: Part 1

Pavan Tarun Chakka Venkata pavan.tarun at multicorewareinc.com
Tue Nov 12 13:18:32 UTC 2024


*Addressed the review comments and rebased on top of MCSTF patches*

>From 526cc183066199d749997246c081d5ad293fca17 Mon Sep 17 00:00:00 2001
From: PavanTarun <pavan.tarun at multicorewareinc.com>
Date: Tue, 12 Nov 2024 09:30:29 +0530
Subject: [PATCH 1/3] Memory Leak Fix: Part 1

---
 source/encoder/api.cpp       | 1 +
 source/encoder/dpb.cpp       | 7 +++++--
 source/encoder/encoder.cpp   | 4 ++++
 source/encoder/encoder.h     | 1 +
 source/encoder/slicetype.cpp | 6 ++++++
 source/x265cli.cpp           | 4 ++++
 6 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/source/encoder/api.cpp b/source/encoder/api.cpp
index 9d8650008..5d2a951e5 100644
--- a/source/encoder/api.cpp
+++ b/source/encoder/api.cpp
@@ -222,6 +222,7 @@ x265_encoder *x265_encoder_open(x265_param *p)
     }

     encoder->m_latestParam = latestParam;
+    encoder->m_zoneParam = zoneParam;
     x265_copy_params(latestParam, param);
     if (encoder->m_aborted)
         goto fail;
diff --git a/source/encoder/dpb.cpp b/source/encoder/dpb.cpp
index 69f821aee..c5bb10bf2 100644
--- a/source/encoder/dpb.cpp
+++ b/source/encoder/dpb.cpp
@@ -53,8 +53,11 @@ DPB::~DPB()
         FrameData* next = m_frameDataFreeList->m_freeListNext;
         m_frameDataFreeList->destroy();

-        m_frameDataFreeList->m_reconPic[0]->destroy();
-        delete m_frameDataFreeList->m_reconPic[0];
+        for (int i = 0; i < !!m_frameDataFreeList->m_param->bEnableSCC +
1; i++)
+        {
+            m_frameDataFreeList->m_reconPic[i]->destroy();
+            delete m_frameDataFreeList->m_reconPic[i];
+        }

         delete m_frameDataFreeList;
         m_frameDataFreeList = next;
diff --git a/source/encoder/encoder.cpp b/source/encoder/encoder.cpp
index 09f58c62a..d2893345d 100644
--- a/source/encoder/encoder.cpp
+++ b/source/encoder/encoder.cpp
@@ -949,6 +949,10 @@ void Encoder::destroy()

         PARAM_NS::x265_param_free(m_latestParam);
     }
+
+    if (m_zoneParam != NULL && m_zoneParam != m_param)
+        PARAM_NS::x265_param_free(m_zoneParam);
+
     if (m_analysisFileIn)
         fclose(m_analysisFileIn);

diff --git a/source/encoder/encoder.h b/source/encoder/encoder.h
index af216942b..7de34c353 100644
--- a/source/encoder/encoder.h
+++ b/source/encoder/encoder.h
@@ -208,6 +208,7 @@ public:
     FILE*              m_naluFile;
     x265_param*        m_param;
     x265_param*        m_latestParam;     // Holds latest param during a
reconfigure
+    x265_param*        m_zoneParam;
     RateControl*       m_rateControl;
     Lookahead*         m_lookahead;
     AdaptiveFrameDuplication* m_dupBuffer[DUP_BUFFER];      // picture
buffer of size 2
diff --git a/source/encoder/slicetype.cpp b/source/encoder/slicetype.cpp
index abc687ef4..695fd90df 100644
--- a/source/encoder/slicetype.cpp
+++ b/source/encoder/slicetype.cpp
@@ -1178,6 +1178,12 @@ void Lookahead::destroy()
         delete[] m_metld;
     }

+    X265_FREE(m_accHistDiffRunningAvgCb[0]);
+    X265_FREE(m_accHistDiffRunningAvgCb);
+    X265_FREE(m_accHistDiffRunningAvgCr[0]);
+    X265_FREE(m_accHistDiffRunningAvgCr);
+    X265_FREE(m_accHistDiffRunningAvg[0]);
+    X265_FREE(m_accHistDiffRunningAvg);
     X265_FREE(m_scratch);
     delete [] m_tld;
     if (m_param->lookaheadThreads > 0)
diff --git a/source/x265cli.cpp b/source/x265cli.cpp
index 53a47e340..12df761cc 100755
--- a/source/x265cli.cpp
+++ b/source/x265cli.cpp
@@ -474,6 +474,10 @@ namespace X265_NS {
         if (dolbyVisionRpu)
             fclose(dolbyVisionRpu);
         dolbyVisionRpu = NULL;
+#if ENABLE_MULTIVIEW
+        if (multiViewConfig)
+            fclose(multiViewConfig);
+#endif
         if (output)
             output->release();
         output = NULL;
-- 
2.41.0.windows.1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20241112/2ae2f830/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Memory-Leak-Fix-Part-1.patch
Type: application/octet-stream
Size: 3674 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20241112/2ae2f830/attachment.obj>


More information about the x265-devel mailing list