<div dir="ltr"><div class="gmail_default" style="font-family:tahoma,sans-serif">From e617839b27edb8ba29844dd572f9e440136955c1 Mon Sep 17 00:00:00 2001<br>From: Min Chen <<a href="mailto:chenm003@163.com">chenm003@163.com</a>><br>Date: Tue, 19 Nov 2024 08:02:34 -0800<br>Subject: [PATCH] Fix abr-ladder seg fault<br><br>---<br> source/abrEncApp.cpp | 5 ++++-<br> source/abrEncApp.h   | 2 ++<br> source/x265.cpp      | 5 +++--<br> 3 files changed, 9 insertions(+), 3 deletions(-)<br><br>diff --git a/source/abrEncApp.cpp b/source/abrEncApp.cpp<br>index 66787ff11..93d660152 100644<br>--- a/source/abrEncApp.cpp<br>+++ b/source/abrEncApp.cpp<br>@@ -51,6 +51,7 @@ namespace X265_NS {<br>         m_numActiveEncodes.set(numEncodes);<br>         m_queueSize = (numEncodes > 1) ? X265_INPUT_QUEUE_SIZE : 1;<br>         m_passEnc = X265_MALLOC(PassEncoder*, m_numEncodes);<br>+        m_param = X265_MALLOC(x265_param, m_numEncodes);<br> <br>         for (uint8_t i = 0; i < m_numEncodes; i++)<br>         {<br>@@ -178,7 +179,7 @@ namespace X265_NS {<br>                 {<br>                     X265_FREE(m_inputPicBuffer[pass][index]->planes[0]);<br>                     x265_picture_free(m_inputPicBuffer[pass][index]);<br>-                    X265_FREE(m_analysisBuffer[pass][index].wt);<br>+                    x265_free_analysis_data(&m_param[pass], &m_analysisBuffer[pass][index]);<br>                 }<br>                 X265_FREE(m_inputPicBuffer[pass]);<br> <br>@@ -207,6 +208,7 @@ namespace X265_NS {<br>         X265_FREE(m_analysisRead);<br> <br>         X265_FREE(m_passEnc);<br>+        X265_FREE_ZERO(m_param);<br>     }<br> <br>     PassEncoder::PassEncoder(uint32_t id, CLIOptions cliopt, AbrEncoder *parent)<br>@@ -588,6 +590,7 @@ ret:<br> #if ENABLE_LIBVMAF<br>             x265_vmaf_data* vmafdata = m_cliopt.vmafData;<br> #endif<br>+            memcpy(&m_parent->m_param[m_id], m_param, sizeof(x265_param));<br>             /* This allows muxers to modify bitstream format */<br>             m_cliopt.output->setParam(m_param);<br>             const x265_api* api = m_cliopt.api;<br>diff --git a/source/abrEncApp.h b/source/abrEncApp.h<br>index 7c1142baf..7f66c49aa 100644<br>--- a/source/abrEncApp.h<br>+++ b/source/abrEncApp.h<br>@@ -46,6 +46,8 @@ namespace X265_NS {<br>         PassEncoder        **m_passEnc;<br>         uint32_t           m_queueSize;<br>         ThreadSafeInteger  m_numActiveEncodes;<br>+        // Temporary duplicated param for free the analysis info, unnecessary free here<br>+        x265_param         *m_param;    //[numEncodes]<br> <br>         x265_picture       ***m_inputPicBuffer; //[numEncodes][queueSize]<br>         x265_analysis_data **m_analysisBuffer; //[numEncodes][queueSize]<br>diff --git a/source/x265.cpp b/source/x265.cpp<br>index 357f5d6ea..bd1afb3f4 100644<br>--- a/source/x265.cpp<br>+++ b/source/x265.cpp<br>@@ -154,13 +154,14 @@ static bool parseAbrConfig(FILE* abrConfig, CLIOptions cliopt[], uint8_t numEnco<br>     char line[1024];<br>     char* argLine;<br> <br>-    char **argv = (char**)malloc(256 * sizeof(char *));<br>     char *strPool = (char*)malloc(256 * X265_MAX_STRING_SIZE * sizeof(char));<br>     int strPoolSize = 256 * X265_MAX_STRING_SIZE;<br>     for (uint32_t i = 0; i < numEncodes; i++)<br>     {<br>+        char **argv = (char**)malloc(256 * sizeof(char *));<br>         cliopt[i].stringPool = (i == 0 ? strPool : NULL);<br>-        cliopt[i].argString = (i == 0 ? argv : NULL);<br>+        cliopt[i].argString = argv;<br>+        cliopt[i].orgArgv = NULL;<br>         if (fgets(line, sizeof(line), abrConfig) == NULL) {<br>             fprintf(stderr, "Error reading line from configuration file.\n");<br>             return false;<br>-- <br>2.35.1.windows.2<br><br></div></div>