<div dir="ltr"><div class="gmail_default" style="font-family:tahoma,sans-serif">From 02fc0a108791efac9db52e729dde4987c1c7142f Mon Sep 17 00:00:00 2001<br>From: PavanTarun <<a href="mailto:pavan.tarun@multicorewareinc.com">pavan.tarun@multicorewareinc.com</a>><br>Date: Sat, 9 Nov 2024 10:20:21 +0530<br>Subject: [PATCH 1/3] Memory Leak Fix: Part 1<br><br>---<br> source/abrEncApp.cpp         | 2 +-<br> source/encoder/api.cpp       | 1 +<br> source/encoder/dpb.cpp       | 7 +++++--<br> source/encoder/encoder.cpp   | 8 ++++++++<br> source/encoder/encoder.h     | 1 +<br> source/encoder/slicetype.cpp | 6 ++++++<br> source/x265cli.cpp           | 4 ++++<br> 7 files changed, 26 insertions(+), 3 deletions(-)<br><br>diff --git a/source/abrEncApp.cpp b/source/abrEncApp.cpp<br>index b90c0e560..ebdd3b3ba 100644<br>--- a/source/abrEncApp.cpp<br>+++ b/source/abrEncApp.cpp<br>@@ -919,7 +919,7 @@ ret:<br>             if (b_ctrl_c)<br>                 general_log(m_param, NULL, X265_LOG_INFO, "aborted at input frame %d, output frame %d in %s\n",<br>                     m_cliopt.seek + inFrameCount, stats.encodedPictureCount, profileName);<br>-<br>+            if(m_param->numaPools)    free((char*)m_param->numaPools);<br>             api->param_free(m_param);<br> <br>             X265_FREE(errorBuf);<br>diff --git a/source/encoder/api.cpp b/source/encoder/api.cpp<br>index 9d8650008..5d2a951e5 100644<br>--- a/source/encoder/api.cpp<br>+++ b/source/encoder/api.cpp<br>@@ -222,6 +222,7 @@ x265_encoder *x265_encoder_open(x265_param *p)<br>     }<br> <br>     encoder->m_latestParam = latestParam;<br>+    encoder->m_zoneParam = zoneParam;<br>     x265_copy_params(latestParam, param);<br>     if (encoder->m_aborted)<br>         goto fail;<br>diff --git a/source/encoder/dpb.cpp b/source/encoder/dpb.cpp<br>index 69f821aee..c5bb10bf2 100644<br>--- a/source/encoder/dpb.cpp<br>+++ b/source/encoder/dpb.cpp<br>@@ -53,8 +53,11 @@ DPB::~DPB()<br>         FrameData* next = m_frameDataFreeList->m_freeListNext;<br>         m_frameDataFreeList->destroy();<br> <br>-        m_frameDataFreeList->m_reconPic[0]->destroy();<br>-        delete m_frameDataFreeList->m_reconPic[0];<br>+        for (int i = 0; i < !!m_frameDataFreeList->m_param->bEnableSCC + 1; i++)<br>+        {<br>+            m_frameDataFreeList->m_reconPic[i]->destroy();<br>+            delete m_frameDataFreeList->m_reconPic[i];<br>+        }<br> <br>         delete m_frameDataFreeList;<br>         m_frameDataFreeList = next;<br>diff --git a/source/encoder/encoder.cpp b/source/encoder/encoder.cpp<br>index 5e715b713..5f784e72b 100644<br>--- a/source/encoder/encoder.cpp<br>+++ b/source/encoder/encoder.cpp<br>@@ -953,9 +953,17 @@ void Encoder::destroy()<br>     {<br>         if (m_latestParam->scalingLists != m_param->scalingLists)<br>             free((char*)m_latestParam->scalingLists);<br>+        if (m_latestParam->numaPools != m_param->numaPools)<br>+            free((char*)m_latestParam->numaPools);<br> <br>         PARAM_NS::x265_param_free(m_latestParam);<br>     }<br>+    if (m_zoneParam != NULL && m_zoneParam != m_param) {<br>+        if (m_zoneParam->numaPools != m_param->numaPools)<br>+            free((char*)m_zoneParam->numaPools);<br>+<br>+        PARAM_NS::x265_param_free(m_zoneParam);<br>+    }<br>     if (m_analysisFileIn)<br>         fclose(m_analysisFileIn);<br> <br>diff --git a/source/encoder/encoder.h b/source/encoder/encoder.h<br>index f50f783d0..6289779e7 100644<br>--- a/source/encoder/encoder.h<br>+++ b/source/encoder/encoder.h<br>@@ -208,6 +208,7 @@ public:<br>     FILE*              m_naluFile;<br>     x265_param*        m_param;<br>     x265_param*        m_latestParam;     // Holds latest param during a reconfigure<br>+    x265_param*        m_zoneParam;<br>     RateControl*       m_rateControl;<br>     Lookahead*         m_lookahead;<br>     AdaptiveFrameDuplication* m_dupBuffer[DUP_BUFFER];      // picture buffer of size 2<br>diff --git a/source/encoder/slicetype.cpp b/source/encoder/slicetype.cpp<br>index 8bbac8244..046cf1596 100644<br>--- a/source/encoder/slicetype.cpp<br>+++ b/source/encoder/slicetype.cpp<br>@@ -1165,6 +1165,12 @@ void Lookahead::destroy()<br>         delete curFrame;<br>     }<br> <br>+    X265_FREE(m_accHistDiffRunningAvgCb[0]);<br>+    X265_FREE(m_accHistDiffRunningAvgCb);<br>+    X265_FREE(m_accHistDiffRunningAvgCr[0]);<br>+    X265_FREE(m_accHistDiffRunningAvgCr);<br>+    X265_FREE(m_accHistDiffRunningAvg[0]);<br>+    X265_FREE(m_accHistDiffRunningAvg);<br>     X265_FREE(m_scratch);<br>     delete [] m_tld;<br>     if (m_param->lookaheadThreads > 0)<br>diff --git a/source/x265cli.cpp b/source/x265cli.cpp<br>index 53a47e340..12df761cc 100755<br>--- a/source/x265cli.cpp<br>+++ b/source/x265cli.cpp<br>@@ -474,6 +474,10 @@ namespace X265_NS {<br>         if (dolbyVisionRpu)<br>             fclose(dolbyVisionRpu);<br>         dolbyVisionRpu = NULL;<br>+#if ENABLE_MULTIVIEW<br>+        if (multiViewConfig)<br>+            fclose(multiViewConfig);<br>+#endif<br>         if (output)<br>             output->release();<br>         output = NULL;<br>-- <br>2.41.0.windows.1<br><br></div></div>