[x265] [PATCH] Fix abr-ladder seg fault

Pavan Tarun Chakka Venkata pavan.tarun at multicorewareinc.com
Thu Nov 21 10:16:08 UTC 2024


>From e617839b27edb8ba29844dd572f9e440136955c1 Mon Sep 17 00:00:00 2001
From: Min Chen <chenm003 at 163.com>
Date: Tue, 19 Nov 2024 08:02:34 -0800
Subject: [PATCH] Fix abr-ladder seg fault

---
 source/abrEncApp.cpp | 5 ++++-
 source/abrEncApp.h   | 2 ++
 source/x265.cpp      | 5 +++--
 3 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/source/abrEncApp.cpp b/source/abrEncApp.cpp
index 66787ff11..93d660152 100644
--- a/source/abrEncApp.cpp
+++ b/source/abrEncApp.cpp
@@ -51,6 +51,7 @@ namespace X265_NS {
         m_numActiveEncodes.set(numEncodes);
         m_queueSize = (numEncodes > 1) ? X265_INPUT_QUEUE_SIZE : 1;
         m_passEnc = X265_MALLOC(PassEncoder*, m_numEncodes);
+        m_param = X265_MALLOC(x265_param, m_numEncodes);

         for (uint8_t i = 0; i < m_numEncodes; i++)
         {
@@ -178,7 +179,7 @@ namespace X265_NS {
                 {
                     X265_FREE(m_inputPicBuffer[pass][index]->planes[0]);
                     x265_picture_free(m_inputPicBuffer[pass][index]);
-                    X265_FREE(m_analysisBuffer[pass][index].wt);
+                    x265_free_analysis_data(&m_param[pass],
&m_analysisBuffer[pass][index]);
                 }
                 X265_FREE(m_inputPicBuffer[pass]);

@@ -207,6 +208,7 @@ namespace X265_NS {
         X265_FREE(m_analysisRead);

         X265_FREE(m_passEnc);
+        X265_FREE_ZERO(m_param);
     }

     PassEncoder::PassEncoder(uint32_t id, CLIOptions cliopt, AbrEncoder
*parent)
@@ -588,6 +590,7 @@ ret:
 #if ENABLE_LIBVMAF
             x265_vmaf_data* vmafdata = m_cliopt.vmafData;
 #endif
+            memcpy(&m_parent->m_param[m_id], m_param, sizeof(x265_param));
             /* This allows muxers to modify bitstream format */
             m_cliopt.output->setParam(m_param);
             const x265_api* api = m_cliopt.api;
diff --git a/source/abrEncApp.h b/source/abrEncApp.h
index 7c1142baf..7f66c49aa 100644
--- a/source/abrEncApp.h
+++ b/source/abrEncApp.h
@@ -46,6 +46,8 @@ namespace X265_NS {
         PassEncoder        **m_passEnc;
         uint32_t           m_queueSize;
         ThreadSafeInteger  m_numActiveEncodes;
+        // Temporary duplicated param for free the analysis info,
unnecessary free here
+        x265_param         *m_param;    //[numEncodes]

         x265_picture       ***m_inputPicBuffer; //[numEncodes][queueSize]
         x265_analysis_data **m_analysisBuffer; //[numEncodes][queueSize]
diff --git a/source/x265.cpp b/source/x265.cpp
index 357f5d6ea..bd1afb3f4 100644
--- a/source/x265.cpp
+++ b/source/x265.cpp
@@ -154,13 +154,14 @@ static bool parseAbrConfig(FILE* abrConfig,
CLIOptions cliopt[], uint8_t numEnco
     char line[1024];
     char* argLine;

-    char **argv = (char**)malloc(256 * sizeof(char *));
     char *strPool = (char*)malloc(256 * X265_MAX_STRING_SIZE *
sizeof(char));
     int strPoolSize = 256 * X265_MAX_STRING_SIZE;
     for (uint32_t i = 0; i < numEncodes; i++)
     {
+        char **argv = (char**)malloc(256 * sizeof(char *));
         cliopt[i].stringPool = (i == 0 ? strPool : NULL);
-        cliopt[i].argString = (i == 0 ? argv : NULL);
+        cliopt[i].argString = argv;
+        cliopt[i].orgArgv = NULL;
         if (fgets(line, sizeof(line), abrConfig) == NULL) {
             fprintf(stderr, "Error reading line from configuration
file.\n");
             return false;
-- 
2.35.1.windows.2
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20241121/7f916961/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0010-Fix_abr_ladder_seg_fault.patch
Type: application/octet-stream
Size: 3388 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20241121/7f916961/attachment.obj>


More information about the x265-devel mailing list