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

Pavan Tarun Chakka Venkata pavan.tarun at multicorewareinc.com
Sun Nov 10 05:39:12 UTC 2024


>From 02fc0a108791efac9db52e729dde4987c1c7142f Mon Sep 17 00:00:00 2001
From: PavanTarun <pavan.tarun at multicorewareinc.com>
Date: Sat, 9 Nov 2024 10:20:21 +0530
Subject: [PATCH 1/3] Memory Leak Fix: Part 1

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

diff --git a/source/abrEncApp.cpp b/source/abrEncApp.cpp
index b90c0e560..ebdd3b3ba 100644
--- a/source/abrEncApp.cpp
+++ b/source/abrEncApp.cpp
@@ -919,7 +919,7 @@ ret:
             if (b_ctrl_c)
                 general_log(m_param, NULL, X265_LOG_INFO, "aborted at
input frame %d, output frame %d in %s\n",
                     m_cliopt.seek + inFrameCount,
stats.encodedPictureCount, profileName);
-
+            if(m_param->numaPools)    free((char*)m_param->numaPools);
             api->param_free(m_param);

             X265_FREE(errorBuf);
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 5e715b713..5f784e72b 100644
--- a/source/encoder/encoder.cpp
+++ b/source/encoder/encoder.cpp
@@ -953,9 +953,17 @@ void Encoder::destroy()
     {
         if (m_latestParam->scalingLists != m_param->scalingLists)
             free((char*)m_latestParam->scalingLists);
+        if (m_latestParam->numaPools != m_param->numaPools)
+            free((char*)m_latestParam->numaPools);

         PARAM_NS::x265_param_free(m_latestParam);
     }
+    if (m_zoneParam != NULL && m_zoneParam != m_param) {
+        if (m_zoneParam->numaPools != m_param->numaPools)
+            free((char*)m_zoneParam->numaPools);
+
+        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 f50f783d0..6289779e7 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 8bbac8244..046cf1596 100644
--- a/source/encoder/slicetype.cpp
+++ b/source/encoder/slicetype.cpp
@@ -1165,6 +1165,12 @@ void Lookahead::destroy()
         delete curFrame;
     }

+    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/20241110/1588520a/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Memory-Leak-Fix-Part1.patch
Type: application/octet-stream
Size: 4622 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20241110/1588520a/attachment.obj>


More information about the x265-devel mailing list