From b5d9bc355bb68cd789679f1f6c0c27286b4fa6e5 Mon Sep 17 00:00:00 2001
From: AnusuyaKumarasamy <anusuya.kumarasamy@multicorewareinc.com>
Date: Tue, 10 Sep 2024 16:37:51 +0530
Subject: [PATCH]  Fix issue in default code flow & memory leak

---
 source/encoder/dpb.cpp |  7 ++++++-
 source/x265cli.cpp     | 11 ++++++++++-
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/source/encoder/dpb.cpp b/source/encoder/dpb.cpp
index 19480d7ca..caf73ad6d 100644
--- a/source/encoder/dpb.cpp
+++ b/source/encoder/dpb.cpp
@@ -289,7 +289,12 @@ void DPB::prepareEncode(Frame *newFrame)
         slice->m_numRefIdx[0] = x265_clip3(1, newFrame->m_param->maxNumReferences, numRef + newFrame->refPicSetInterLayer0.size() + newFrame->refPicSetInterLayer1.size());
     else
         slice->m_numRefIdx[0] = X265_MIN(newFrame->m_param->maxNumReferences, numRef); // Ensuring L0 contains just the -ve POC
-    slice->m_numRefIdx[1] = X265_MIN(newFrame->m_param->bBPyramid ? 3 : 2, slice->m_rps.numberOfPositivePictures + newFrame->refPicSetInterLayer0.size() + newFrame->refPicSetInterLayer1.size());
+#if ENABLE_MULTIVIEW || ENABLE_SCC_EXT
+    if(slice->m_param->numViews > 1 || !!slice->m_param->bEnableSCC)
+        slice->m_numRefIdx[1] = X265_MIN(newFrame->m_param->bBPyramid ? 3 : 2, slice->m_rps.numberOfPositivePictures + newFrame->refPicSetInterLayer0.size() + newFrame->refPicSetInterLayer1.size());
+    else
+#endif
+        slice->m_numRefIdx[1] = X265_MIN(newFrame->m_param->bBPyramid ? 2 : 1, slice->m_rps.numberOfPositivePictures);
     slice->setRefPicList(m_picList, newFrame->refPicSetInterLayer0, newFrame->refPicSetInterLayer1, layer);
 
     X265_CHECK(slice->m_sliceType != B_SLICE || slice->m_numRefIdx[1], "B slice without L1 references (non-fatal)\n");
diff --git a/source/x265cli.cpp b/source/x265cli.cpp
index 89852c701..ca7d9c973 100755
--- a/source/x265cli.cpp
+++ b/source/x265cli.cpp
@@ -738,7 +738,7 @@ namespace X265_NS {
                 OPT("frames") this->framesToBeEncoded = (uint32_t)x265_atoi(optarg, bError);
                 OPT("no-progress") this->bProgress = false;
                 OPT("output") outputfn = optarg;
-                OPT("input") inputfn[0] = optarg;
+                OPT("input") strcpy(inputfn[0] , optarg);
                 OPT("recon") reconfn[0] = optarg;
                 OPT("input-depth") inputBitDepth = (uint32_t)x265_atoi(optarg, bError);
                 OPT("dither") this->bDither = true;
@@ -1034,6 +1034,15 @@ namespace X265_NS {
             return true;
         }
         general_log_file(param, this->output->getName(), X265_LOG_INFO, "output file: %s\n", outputfn);
+
+        for (int view = 0; view < MAX_VIEWS; view++)
+        {
+            if (inputfn[view] != NULL)
+            {
+                X265_FREE(inputfn[view]);
+                inputfn[view] = NULL;
+            }
+        }
         return false;
     }
 
-- 
2.36.0.windows.1

