<!DOCTYPE html><html><head><title></title><style type="text/css">p.MsoNormal,p.MsoNoSpacing{margin:0}</style></head><body><div>Hard coding a max string size is pretty bad and will fail.<br></div><div><br></div><div>On Sun, 10 Nov 2024, at 06:40, Pavan Tarun Chakka Venkata wrote:<br></div><blockquote type="cite" id="qt" style=""><div dir="ltr"><div class="qt-gmail_default" style="font-family:tahoma, sans-serif;"><div>From e33b7bc78be5d49dd510435981231a63f1c76aec Mon Sep 17 00:00:00 2001<br></div><div>From: Min Chen <<a href="mailto:chenm003@163.com">chenm003@163.com</a>><br></div><div>Date: Sat, 9 Nov 2024 12:58:49 +0530<br></div><div>Subject: [PATCH 2/3] Memory Leak Fix: Part 2<br></div><div><br></div><div>---<br></div><div> source/CMakeLists.txt | 2 +-<br></div><div> source/abrEncApp.cpp | 9 +-<br></div><div> source/common/param.cpp | 140 ++++++++++++++++---------------<br></div><div> source/common/temporalfilter.cpp | 7 ++<br></div><div> source/common/temporalfilter.h | 2 +-<br></div><div> source/common/threadpool.cpp | 4 +-<br></div><div> source/encoder/analysis.cpp | 6 +-<br></div><div> source/encoder/api.cpp | 17 +++-<br></div><div> source/encoder/encoder.cpp | 111 +++++++++++-------------<br></div><div> source/encoder/encoder.h | 1 +<br></div><div> source/encoder/frameencoder.cpp | 12 ++-<br></div><div> source/encoder/framefilter.cpp | 8 +-<br></div><div> source/encoder/ratecontrol.cpp | 4 +-<br></div><div> source/encoder/search.cpp | 4 +-<br></div><div> source/encoder/slicetype.cpp | 16 ++--<br></div><div> source/x265.cpp | 24 ++++--<br></div><div> source/x265.h | 28 ++++---<br></div><div> source/x265cli.cpp | 7 +-<br></div><div> source/x265cli.h | 8 +-<br></div><div> 19 files changed, 210 insertions(+), 200 deletions(-)<br></div><div><br></div><div>diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt<br></div><div>index 310683909..14f6ccc49 100755<br></div><div>--- a/source/CMakeLists.txt<br></div><div>+++ b/source/CMakeLists.txt<br></div><div>@@ -31,7 +31,7 @@ option(NATIVE_BUILD "Target the build CPU" OFF)<br></div><div> option(STATIC_LINK_CRT "Statically link C and C++ runtimes for release builds" OFF)<br></div><div> mark_as_advanced(FPROFILE_USE FPROFILE_GENERATE NATIVE_BUILD)<br></div><div> # X265_BUILD must be incremented each time the public API is changed<br></div><div>-set(X265_BUILD 213)<br></div><div>+set(X265_BUILD 214)<br></div><div> configure_file("${PROJECT_SOURCE_DIR}/<a href="http://x265.def.in">x265.def.in</a>"<br></div><div> "${PROJECT_BINARY_DIR}/x265.def")<br></div><div> configure_file("${PROJECT_SOURCE_DIR}/<a href="http://x265_config.h.in">x265_config.h.in</a>"<br></div><div>diff --git a/source/abrEncApp.cpp b/source/abrEncApp.cpp<br></div><div>index ebdd3b3ba..a56e14cde 100644<br></div><div>--- a/source/abrEncApp.cpp<br></div><div>+++ b/source/abrEncApp.cpp<br></div><div>@@ -282,8 +282,8 @@ namespace X265_NS {<br></div><div> <br></div><div> m_param->analysisLoadReuseLevel = m_cliopt.loadLevel;<br></div><div> m_param->analysisSaveReuseLevel = m_cliopt.saveLevel;<br></div><div>- m_param->analysisSave = m_cliopt.saveLevel ? "save.dat" : NULL;<br></div><div>- m_param->analysisLoad = m_cliopt.loadLevel ? "load.dat" : NULL;<br></div><div>+ strcpy(m_param->analysisSave, m_cliopt.saveLevel ? "save.dat" : "");<br></div><div>+ strcpy(m_param->analysisLoad, m_cliopt.loadLevel ? "load.dat" : "");<br></div><div> m_param->bUseAnalysisFile = 0;<br></div><div> <br></div><div> if (m_cliopt.loadLevel)<br></div><div>@@ -599,7 +599,7 @@ ret:<br></div><div> x265_picture* pic_recon;<br></div><div> x265_picture pic_out[MAX_LAYERS];<br></div><div> <br></div><div>- pic_recon = (m_cliopt.recon[0] || m_param->analysisSave || m_param->analysisLoad || pts_queue || reconPlay || m_param->csvLogLevel) ? pic_out : NULL;<br></div><div>+ pic_recon = (m_cliopt.recon[0] || strlen(m_param->analysisSave) || strlen(m_param->analysisLoad) || pts_queue || reconPlay || m_param->csvLogLevel) ? pic_out : NULL;<br></div><div> uint32_t inFrameCount = 0;<br></div><div> uint32_t outFrameCount = 0;<br></div><div> x265_nal *p_nal;<br></div><div>@@ -895,7 +895,7 @@ ret:<br></div><div> delete reconPlay;<br></div><div> <br></div><div> api->encoder_get_stats(m_encoder, &stats, sizeof(stats));<br></div><div>- if (m_param->csvfn && !b_ctrl_c)<br></div><div>+ if (strlen(m_param->csvfn) && !b_ctrl_c)<br></div><div> #if ENABLE_LIBVMAF<br></div><div> api->vmaf_encoder_log(m_encoder, m_cliopt.argCnt, m_cliopt.argString, m_cliopt.param, vmafdata);<br></div><div> #else<br></div><div>@@ -919,7 +919,6 @@ ret:<br></div><div> if (b_ctrl_c)<br></div><div> general_log(m_param, NULL, X265_LOG_INFO, "aborted at input frame %d, output frame %d in %s\n",<br></div><div> m_cliopt.seek + inFrameCount, stats.encodedPictureCount, profileName);<br></div><div>- if(m_param->numaPools) free((char*)m_param->numaPools);<br></div><div> api->param_free(m_param);<br></div><div> <br></div><div> X265_FREE(errorBuf);<br></div><div>diff --git a/source/common/param.cpp b/source/common/param.cpp<br></div><div>index 1beb3c056..010721315 100755<br></div><div>--- a/source/common/param.cpp<br></div><div>+++ b/source/common/param.cpp<br></div><div>@@ -94,6 +94,7 @@ namespace X265_NS {<br></div><div> x265_param *x265_param_alloc()<br></div><div> {<br></div><div> x265_param* param = (x265_param*)x265_malloc(sizeof(x265_param));<br></div><div>+ memset(param, 0, sizeof(x265_param));<br></div><div> #ifdef SVT_HEVC<br></div><div> param->svtHevcParam = (EB_H265_ENC_CONFIGURATION*)x265_malloc(sizeof(EB_H265_ENC_CONFIGURATION));<br></div><div> #endif<br></div><div>@@ -151,8 +152,8 @@ void x265_param_default(x265_param* param)<br></div><div> <br></div><div> param->logLevel = X265_LOG_INFO;<br></div><div> param->csvLogLevel = 0;<br></div><div>- param->csvfn = NULL;<br></div><div>- param->rc.lambdaFileName = NULL;<br></div><div>+ param->csvfn[0] = 0;<br></div><div>+ param->rc.lambdaFileName[0] = 0;<br></div><div> param->bLogCuStats = 0;<br></div><div> param->decodedPictureHashSEI = 0;<br></div><div> <br></div><div>@@ -279,9 +280,9 @@ void x265_param_default(x265_param* param)<br></div><div> param->analysisReuseMode = 0; /*DEPRECATED*/<br></div><div> param->analysisMultiPassRefine = 0;<br></div><div> param->analysisMultiPassDistortion = 0;<br></div><div>- param->analysisReuseFileName = NULL;<br></div><div>- param->analysisSave = NULL;<br></div><div>- param->analysisLoad = NULL;<br></div><div>+ param->analysisReuseFileName[0] = 0;<br></div><div>+ param->analysisSave[0] = 0;<br></div><div>+ param->analysisLoad[0] = 0;<br></div><div> param->bIntraInBFrames = 1;<br></div><div> param->bLossless = 0;<br></div><div> param->bCULossless = 0;<br></div><div>@@ -317,8 +318,8 @@ void x265_param_default(x265_param* param)<br></div><div> param->rc.bStatRead = 0;<br></div><div> param->rc.bStatWrite = 0;<br></div><div> param->rc.dataShareMode = X265_SHARE_MODE_FILE;<br></div><div>- param->rc.statFileName = NULL;<br></div><div>- param->rc.sharedMemName = NULL;<br></div><div>+ param->rc.statFileName[0] = 0;<br></div><div>+ param->rc.sharedMemName[0] = 0;<br></div><div> param->rc.bEncFocusedFramesOnly = 0;<br></div><div> param->rc.complexityBlur = 20;<br></div><div> param->rc.qblur = 0.5;<br></div><div>@@ -362,7 +363,7 @@ void x265_param_default(x265_param* param)<br></div><div> param->maxLuma = PIXEL_MAX;<br></div><div> param->log2MaxPocLsb = 8;<br></div><div> param->maxSlices = 1;<br></div><div>- param->videoSignalTypePreset = NULL;<br></div><div>+ param->videoSignalTypePreset[0] = 0;<br></div><div> <br></div><div> /*Conformance window*/<br></div><div> param->confWinRightOffset = 0;<br></div><div>@@ -379,7 +380,7 @@ void x265_param_default(x265_param* param)<br></div><div> param->analysisReuseLevel = 0; /*DEPRECATED*/<br></div><div> param->analysisSaveReuseLevel = 0;<br></div><div> param->analysisLoadReuseLevel = 0;<br></div><div>- param->toneMapFile = NULL;<br></div><div>+ param->toneMapFile[0] = 0;<br></div><div> param->bDhdr10opt = 0;<br></div><div> param->dolbyProfile = 0;<br></div><div> param->bCTUInfo = 0;<br></div><div>@@ -396,7 +397,7 @@ void x265_param_default(x265_param* param)<br></div><div> param->bDisableLookahead = 0;<br></div><div> param->bCopyPicToFrame = 1;<br></div><div> param->maxAUSizeFactor = 1;<br></div><div>- param->naluFile = NULL;<br></div><div>+ param->naluFile[0] = 0;<br></div><div> <br></div><div> /* DCT Approximations */<br></div><div> param->bLowPassDct = 0;<br></div><div>@@ -842,7 +843,7 @@ int x265_zone_param_parse(x265_param* p, const char* name, const char* value)<br></div><div> p->rdoqLevel = 0;<br></div><div> }<br></div><div> OPT("b-intra") p->bIntraInBFrames = atobool(value);<br></div><div>- OPT("scaling-list") p->scalingLists = strdup(value);<br></div><div>+ OPT("scaling-list") snprintf(p->scalingLists, X265_MAX_STRING_SIZE, "%s", value);<br></div><div> OPT("crf")<br></div><div> {<br></div><div> p->rc.rfConstant = atof(value);<br></div><div>@@ -1294,13 +1295,13 @@ int x265_param_parse(x265_param* p, const char* name, const char* value)<br></div><div> p->rc.bStatRead = pass & 2;<br></div><div> p->rc.dataShareMode = X265_SHARE_MODE_FILE;<br></div><div> }<br></div><div>- OPT("stats") p->rc.statFileName = strdup(value);<br></div><div>- OPT("scaling-list") p->scalingLists = strdup(value);<br></div><div>- OPT2("pools", "numa-pools") p->numaPools = strdup(value);<br></div><div>- OPT("lambda-file") p->rc.lambdaFileName = strdup(value);<br></div><div>- OPT("analysis-reuse-file") p->analysisReuseFileName = strdup(value);<br></div><div>+ OPT("stats") snprintf(p->rc.statFileName, X265_MAX_STRING_SIZE, "%s", value);<br></div><div>+ OPT("scaling-list") snprintf(p->scalingLists, X265_MAX_STRING_SIZE, "%s", value);<br></div><div>+ OPT2("pools", "numa-pools") snprintf(p->numaPools, X265_MAX_STRING_SIZE, "%s", value);<br></div><div>+ OPT("lambda-file") snprintf(p->rc.lambdaFileName, X265_MAX_STRING_SIZE, "%s", value);<br></div><div>+ OPT("analysis-reuse-file") snprintf(p->analysisReuseFileName, X265_MAX_STRING_SIZE, "%s", value);<br></div><div> OPT("qg-size") p->rc.qgSize = atoi(value);<br></div><div>- OPT("master-display") p->masteringDisplayColorVolume = strdup(value);<br></div><div>+ OPT("master-display") snprintf(p->masteringDisplayColorVolume, X265_MAX_STRING_SIZE, "%s", value);<br></div><div> OPT("max-cll") bError |= sscanf(value, "%hu,%hu", &p->maxCLL, &p->maxFALL) != 2;<br></div><div> OPT("min-luma") p->minLuma = (uint16_t)atoi(value);<br></div><div> OPT("max-luma") p->maxLuma = (uint16_t)atoi(value);<br></div><div>@@ -1312,7 +1313,7 @@ int x265_param_parse(x265_param* p, const char* name, const char* value)<br></div><div> if (bExtraParams)<br></div><div> {<br></div><div> if (0) ;<br></div><div>- OPT("csv") p->csvfn = strdup(value);<br></div><div>+ OPT("csv") snprintf(p->csvfn, X265_MAX_STRING_SIZE, "%s", value);<br></div><div> OPT("csv-log-level") p->csvLogLevel = atoi(value);<br></div><div> OPT("qpmin") p->rc.qpMin = atoi(value);<br></div><div> OPT("analyze-src-pics") p->bSourceReferenceEstimation = atobool(value);<br></div><div>@@ -1357,7 +1358,7 @@ int x265_param_parse(x265_param* p, const char* name, const char* value)<br></div><div> OPT("hdr-opt") p->bHDR10Opt = atobool(value); /*DEPRECATED*/<br></div><div> OPT("hdr10-opt") p->bHDR10Opt = atobool(value);<br></div><div> OPT("limit-sao") p->bLimitSAO = atobool(value);<br></div><div>- OPT("dhdr10-info") p->toneMapFile = strdup(value);<br></div><div>+ OPT("dhdr10-info") snprintf(p->toneMapFile, X265_MAX_STRING_SIZE, "%s", value);<br></div><div> OPT("dhdr10-opt") p->bDhdr10opt = atobool(value);<br></div><div> OPT("idr-recovery-sei") p->bEmitIDRRecoverySEI = atobool(value);<br></div><div> OPT("const-vbv") p->rc.bEnableConstVbv = atobool(value);<br></div><div>@@ -1374,15 +1375,15 @@ int x265_param_parse(x265_param* p, const char* name, const char* value)<br></div><div> OPT("copy-pic") p->bCopyPicToFrame = atobool(value);<br></div><div> OPT("refine-analysis-type")<br></div><div> {<br></div><div>- if (strcmp(strdup(value), "avc") == 0)<br></div><div>+ if (strcmp((value), "avc") == 0)<br></div><div> {<br></div><div> p->bAnalysisType = AVC_INFO;<br></div><div> }<br></div><div>- else if (strcmp(strdup(value), "hevc") == 0)<br></div><div>+ else if (strcmp((value), "hevc") == 0)<br></div><div> {<br></div><div> p->bAnalysisType = HEVC_INFO;<br></div><div> }<br></div><div>- else if (strcmp(strdup(value), "off") == 0)<br></div><div>+ else if (strcmp((value), "off") == 0)<br></div><div> {<br></div><div> p->bAnalysisType = DEFAULT;<br></div><div> }<br></div><div>@@ -1392,8 +1393,8 @@ int x265_param_parse(x265_param* p, const char* name, const char* value)<br></div><div> }<br></div><div> }<br></div><div> OPT("gop-lookahead") p->gopLookahead = atoi(value);<br></div><div>- OPT("analysis-save") p->analysisSave = strdup(value);<br></div><div>- OPT("analysis-load") p->analysisLoad = strdup(value);<br></div><div>+ OPT("analysis-save") snprintf(p->analysisSave, X265_MAX_STRING_SIZE, "%s", value);<br></div><div>+ OPT("analysis-load") snprintf(p->analysisLoad, X265_MAX_STRING_SIZE, "%s", value);<br></div><div> OPT("radl") p->radl = atoi(value);<br></div><div> OPT("max-ausize-factor") p->maxAUSizeFactor = atof(value);<br></div><div> OPT("dynamic-refine") p->bDynamicRefine = atobool(value);<br></div><div>@@ -1402,7 +1403,7 @@ int x265_param_parse(x265_param* p, const char* name, const char* value)<br></div><div> OPT("pic-struct") p->pictureStructure = atoi(value);<br></div><div> OPT("chunk-start") p->chunkStart = atoi(value);<br></div><div> OPT("chunk-end") p->chunkEnd = atoi(value);<br></div><div>- OPT("nalu-file") p->naluFile = strdup(value);<br></div><div>+ OPT("nalu-file") snprintf(p->naluFile, X265_MAX_STRING_SIZE, "%s", value);<br></div><div> OPT("dolby-vision-profile")<br></div><div> {<br></div><div> if (atof(value) < 10)<br></div><div>@@ -1478,7 +1479,7 @@ int x265_param_parse(x265_param* p, const char* name, const char* value)<br></div><div> OPT("vbv-live-multi-pass") p->bliveVBV2pass = atobool(value);<br></div><div> OPT("min-vbv-fullness") p->minVbvFullness = atof(value);<br></div><div> OPT("max-vbv-fullness") p->maxVbvFullness = atof(value);<br></div><div>- OPT("video-signal-type-preset") p->videoSignalTypePreset = strdup(value);<br></div><div>+ OPT("video-signal-type-preset") snprintf(p->videoSignalTypePreset, X265_MAX_STRING_SIZE, "%s", value);<br></div><div> OPT("eob") p->bEnableEndOfBitstream = atobool(value);<br></div><div> OPT("eos") p->bEnableEndOfSequence = atobool(value);<br></div><div> /* Film grain characterstics model filename */<br></div><div>@@ -1866,11 +1867,11 @@ int x265_check_params(x265_param* param)<br></div><div> "Constant QP is incompatible with 2pass");<br></div><div> CHECK(param->rc.bStrictCbr && (param->rc.bitrate <= 0 || param->rc.vbvBufferSize <=0),<br></div><div> "Strict-cbr cannot be applied without specifying target bitrate or vbv bufsize");<br></div><div>- CHECK(param->analysisSave && (param->analysisSaveReuseLevel < 0 || param->analysisSaveReuseLevel > 10),<br></div><div>+ CHECK(strlen(param->analysisSave) && (param->analysisSaveReuseLevel < 0 || param->analysisSaveReuseLevel > 10),<br></div><div> "Invalid analysis save refine level. Value must be between 1 and 10 (inclusive)");<br></div><div>- CHECK(param->analysisLoad && (param->analysisLoadReuseLevel < 0 || param->analysisLoadReuseLevel > 10),<br></div><div>+ CHECK(strlen(param->analysisLoad) && (param->analysisLoadReuseLevel < 0 || param->analysisLoadReuseLevel > 10),<br></div><div> "Invalid analysis load refine level. Value must be between 1 and 10 (inclusive)");<br></div><div>- CHECK(param->analysisLoad && (param->mvRefine < 1 || param->mvRefine > 3),<br></div><div>+ CHECK(strlen(param->analysisLoad) && (param->mvRefine < 1 || param->mvRefine > 3),<br></div><div> "Invalid mv refinement level. Value must be between 1 and 3 (inclusive)");<br></div><div> CHECK(param->scaleFactor > 2, "Invalid scale-factor. Supports factor <= 2");<br></div><div> CHECK(param->rc.qpMax < QP_MIN || param->rc.qpMax > QP_MAX_MAX,<br></div><div>@@ -1948,7 +1949,7 @@ int x265_check_params(x265_param* param)<br></div><div> "SEA motion search does not support resolutions greater than 480p in 32 bit build");<br></div><div> #endif<br></div><div> <br></div><div>- if (param->masteringDisplayColorVolume || param->maxFALL || param->maxCLL)<br></div><div>+ if (strlen(param->masteringDisplayColorVolume) || param->maxFALL || param->maxCLL)<br></div><div> param->bEmitHDR10SEI = 1;<br></div><div> <br></div><div> bool isSingleSEI = (param->bRepeatHeaders<br></div><div>@@ -1958,8 +1959,8 @@ int x265_check_params(x265_param* param)<br></div><div> || param->bEmitIDRRecoverySEI<br></div><div> || !!param->interlaceMode<br></div><div> || param->preferredTransferCharacteristics > 1<br></div><div>- || param->toneMapFile<br></div><div>- || param->naluFile);<br></div><div>+ || strlen(param->toneMapFile)<br></div><div>+ || strlen(param->naluFile));<br></div><div> <br></div><div> if (!isSingleSEI && param->bSingleSeiNal)<br></div><div> {<br></div><div>@@ -1990,7 +1991,7 @@ int x265_check_params(x265_param* param)<br></div><div> CHECK((param->internalCsp != X265_CSP_I420), "Alpha encode supported only with i420a colorspace");<br></div><div> CHECK((param->internalBitDepth > 10), "BitDepthConstraint must be 8 and 10 for Scalable main profile");<br></div><div> CHECK((param->analysisMultiPassDistortion || param->analysisMultiPassRefine), "Alpha encode doesnot support multipass feature");<br></div><div>- CHECK((param->analysisSave || param->analysisLoad), "Alpha encode doesnot support analysis save and load feature");<br></div><div>+ CHECK((strlen(param->analysisSave) || strlen(param->analysisLoad)), "Alpha encode doesnot support analysis save and load feature");<br></div><div> }<br></div><div> #endif<br></div><div> #if ENABLE_MULTIVIEW<br></div><div>@@ -1999,7 +2000,7 @@ int x265_check_params(x265_param* param)<br></div><div> {<br></div><div> CHECK(param->internalBitDepth != 8, "BitDepthConstraint must be 8 for Multiview main profile");<br></div><div> CHECK(param->analysisMultiPassDistortion || param->analysisMultiPassRefine, "Multiview encode doesnot support multipass feature");<br></div><div>- CHECK(param->analysisSave || param->analysisLoad, "Multiview encode doesnot support analysis save and load feature");<br></div><div>+ CHECK(strlen(param->analysisSave) || strlen(param->analysisLoad), "Multiview encode doesnot support analysis save and load feature");<br></div><div> }<br></div><div> #endif<br></div><div> #if ENABLE_SCC_EXT<br></div><div>@@ -2202,11 +2203,11 @@ char *x265_param2string(x265_param* p, int padx, int pady)<br></div><div> {<br></div><div> char *buf, *s;<br></div><div> size_t bufSize = 4000 + p->rc.zoneCount * 64;<br></div><div>- if (p->numaPools)<br></div><div>+ if (strlen(p->numaPools))<br></div><div> bufSize += strlen(p->numaPools);<br></div><div>- if (p->masteringDisplayColorVolume)<br></div><div>+ if (strlen(p->masteringDisplayColorVolume))<br></div><div> bufSize += strlen(p->masteringDisplayColorVolume);<br></div><div>- if (p->videoSignalTypePreset)<br></div><div>+ if (strlen(p->videoSignalTypePreset))<br></div><div> bufSize += strlen(p->videoSignalTypePreset);<br></div><div> <br></div><div> buf = s = X265_MALLOC(char, bufSize);<br></div><div>@@ -2217,7 +2218,7 @@ char *x265_param2string(x265_param* p, int padx, int pady)<br></div><div> <br></div><div> s += snprintf(s, bufSize - (s - buf), "cpuid=%d", p->cpuid);<br></div><div> s += snprintf(s, bufSize - (s - buf), " frame-threads=%d", p->frameNumThreads);<br></div><div>- if (p->numaPools)<br></div><div>+ if (strlen(p->numaPools))<br></div><div> s += snprintf(s, bufSize - (s - buf), " numa-pools=%s", p->numaPools);<br></div><div> BOOL(p->bEnableWavefront, "wpp");<br></div><div> BOOL(p->bDistributeModeAnalysis, "pmode");<br></div><div>@@ -2225,7 +2226,7 @@ char *x265_param2string(x265_param* p, int padx, int pady)<br></div><div> BOOL(p->bEnablePsnr, "psnr");<br></div><div> BOOL(p->bEnableSsim, "ssim");<br></div><div> s += snprintf(s, bufSize - (s - buf), " log-level=%d", p->logLevel);<br></div><div>- if (p->csvfn)<br></div><div>+ if (strlen(p->csvfn))<br></div><div> s += snprintf(s, bufSize - (s - buf), " csv csv-log-level=%d", p->csvLogLevel);<br></div><div> s += snprintf(s, bufSize - (s - buf), " bitdepth=%d", p->internalBitDepth);<br></div><div> s += snprintf(s, bufSize - (s - buf), " input-csp=%d", p->internalCsp);<br></div><div>@@ -2402,7 +2403,7 @@ char *x265_param2string(x265_param* p, int padx, int pady)<br></div><div> s += snprintf(s, bufSize - (s - buf), " left=%d top=%d right=%d bottom=%d",<br></div><div> p->vui.defDispWinLeftOffset, p->vui.defDispWinTopOffset,<br></div><div> p->vui.defDispWinRightOffset, p->vui.defDispWinBottomOffset);<br></div><div>- if (p->masteringDisplayColorVolume)<br></div><div>+ if (strlen(p->masteringDisplayColorVolume))<br></div><div> s += snprintf(s, bufSize - (s - buf), " master-display=%s", p->masteringDisplayColorVolume);<br></div><div> if (p->bEmitCLL)<br></div><div> s += snprintf(s, bufSize - (s - buf), " cll=%hu,%hu", p->maxCLL, p->maxFALL);<br></div><div>@@ -2422,9 +2423,9 @@ char *x265_param2string(x265_param* p, int padx, int pady)<br></div><div> BOOL(p->bHDR10Opt, "hdr10-opt");<br></div><div> BOOL(p->bDhdr10opt, "dhdr10-opt");<br></div><div> BOOL(p->bEmitIDRRecoverySEI, "idr-recovery-sei");<br></div><div>- if (p->analysisSave)<br></div><div>+ if (strlen(p->analysisSave))<br></div><div> s += snprintf(s, bufSize - (s - buf), " analysis-save");<br></div><div>- if (p->analysisLoad)<br></div><div>+ if (strlen(p->analysisLoad))<br></div><div> s += snprintf(s, bufSize - (s - buf), " analysis-load");<br></div><div> s += snprintf(s, bufSize - (s - buf), " analysis-reuse-level=%d", p->analysisReuseLevel);<br></div><div> s += snprintf(s, bufSize - (s - buf), " analysis-save-reuse-level=%d", p->analysisSaveReuseLevel);<br></div><div>@@ -2474,7 +2475,7 @@ char *x265_param2string(x265_param* p, int padx, int pady)<br></div><div> <br></div><div> bool parseLambdaFile(x265_param* param)<br></div><div> {<br></div><div>- if (!param->rc.lambdaFileName)<br></div><div>+ if (!strlen(param->rc.lambdaFileName))<br></div><div> return false;<br></div><div> <br></div><div> FILE *lfn = x265_fopen(param->rc.lambdaFileName, "r");<br></div><div>@@ -2692,8 +2693,8 @@ void x265_copy_params(x265_param* dst, x265_param* src)<br></div><div> dst->mcstfFrameRange = src->mcstfFrameRange;<br></div><div> dst->cpuid = src->cpuid;<br></div><div> dst->frameNumThreads = src->frameNumThreads;<br></div><div>- if (src->numaPools) dst->numaPools = strdup(src->numaPools);<br></div><div>- else dst->numaPools = NULL;<br></div><div>+ if (strlen(src->numaPools)) snprintf(dst->numaPools, X265_MAX_STRING_SIZE, "%s", src->numaPools);<br></div><div>+ else dst->numaPools[0] = 0;<br></div><div> <br></div><div> dst->bEnableWavefront = src->bEnableWavefront;<br></div><div> dst->bDistributeModeAnalysis = src->bDistributeModeAnalysis;<br></div><div>@@ -2703,8 +2704,8 @@ void x265_copy_params(x265_param* dst, x265_param* src)<br></div><div> dst->bEnableSsim = src->bEnableSsim;<br></div><div> dst->logLevel = src->logLevel;<br></div><div> dst->csvLogLevel = src->csvLogLevel;<br></div><div>- if (src->csvfn) dst->csvfn = strdup(src->csvfn);<br></div><div>- else dst->csvfn = NULL;<br></div><div>+ if (strlen(src->csvfn)) snprintf(dst->csvfn, X265_MAX_STRING_SIZE, "%s", src->csvfn);<br></div><div>+ else dst->csvfn[0] = 0;<br></div><div> dst->internalBitDepth = src->internalBitDepth;<br></div><div> dst->sourceBitDepth = src->sourceBitDepth;<br></div><div> dst->internalCsp = src->internalCsp;<br></div><div>@@ -2754,8 +2755,8 @@ void x265_copy_params(x265_param* dst, x265_param* src)<br></div><div> dst->bEnableTransformSkip = src->bEnableTransformSkip;<br></div><div> dst->noiseReductionInter = src->noiseReductionInter;<br></div><div> dst->noiseReductionIntra = src->noiseReductionIntra;<br></div><div>- if (src->scalingLists) dst->scalingLists = strdup(src->scalingLists);<br></div><div>- else dst->scalingLists = NULL;<br></div><div>+ if (strlen(src->scalingLists)) snprintf(dst->scalingLists, X265_MAX_STRING_SIZE, "%s", src->scalingLists);<br></div><div>+ else dst->scalingLists[0] = 0;<br></div><div> dst->bEnableStrongIntraSmoothing = src->bEnableStrongIntraSmoothing;<br></div><div> dst->bEnableConstrainedIntra = src->bEnableConstrainedIntra;<br></div><div> dst->maxNumMergeCand = src->maxNumMergeCand;<br></div><div>@@ -2797,8 +2798,8 @@ void x265_copy_params(x265_param* dst, x265_param* src)<br></div><div> dst->psyRdoq = src->psyRdoq;<br></div><div> dst->bEnableRdRefine = src->bEnableRdRefine;<br></div><div> dst->analysisReuseMode = src->analysisReuseMode;<br></div><div>- if (src->analysisReuseFileName) dst->analysisReuseFileName=strdup(src->analysisReuseFileName);<br></div><div>- else dst->analysisReuseFileName = NULL;<br></div><div>+ if (strlen(src->analysisReuseFileName)) snprintf(dst->analysisReuseFileName, X265_MAX_STRING_SIZE, "%s", src->analysisReuseFileName);<br></div><div>+ else dst->analysisReuseFileName[0] = 0;<br></div><div> dst->bLossless = src->bLossless;<br></div><div> dst->cbQpOffset = src->cbQpOffset;<br></div><div> dst->crQpOffset = src->crQpOffset;<br></div><div>@@ -2827,10 +2828,10 @@ void x265_copy_params(x265_param* dst, x265_param* src)<br></div><div> dst->rc.bStatWrite = src->rc.bStatWrite;<br></div><div> dst->rc.bStatRead = src->rc.bStatRead;<br></div><div> dst->rc.dataShareMode = src->rc.dataShareMode;<br></div><div>- if (src->rc.statFileName) dst->rc.statFileName=strdup(src->rc.statFileName);<br></div><div>- else dst->rc.statFileName = NULL;<br></div><div>- if (src->rc.sharedMemName) dst->rc.sharedMemName = strdup(src->rc.sharedMemName);<br></div><div>- else dst->rc.sharedMemName = NULL;<br></div><div>+ if (strlen(src->rc.statFileName)) snprintf(dst->rc.statFileName, X265_MAX_STRING_SIZE, "%s", src->rc.statFileName);<br></div><div>+ else dst->rc.statFileName[0] = 0;<br></div><div>+ if (strlen(src->rc.sharedMemName)) snprintf(dst->rc.sharedMemName, X265_MAX_STRING_SIZE, "%s", src->rc.sharedMemName);<br></div><div>+ else dst->rc.sharedMemName[0] = 0;<br></div><div> dst->rc.qblur = src->rc.qblur;<br></div><div> dst->rc.complexityBlur = src->rc.complexityBlur;<br></div><div> dst->rc.bEnableSlowFirstPass = src->rc.bEnableSlowFirstPass;<br></div><div>@@ -2864,8 +2865,8 @@ void x265_copy_params(x265_param* dst, x265_param* src)<br></div><div> else<br></div><div> dst->rc.zones = NULL;<br></div><div> <br></div><div>- if (src->rc.lambdaFileName) dst->rc.lambdaFileName = strdup(src->rc.lambdaFileName);<br></div><div>- else dst->rc.lambdaFileName = NULL;<br></div><div>+ if (strlen(src->rc.lambdaFileName)) snprintf(dst->rc.lambdaFileName, X265_MAX_STRING_SIZE, "%s", src->rc.lambdaFileName);<br></div><div>+ else dst->rc.lambdaFileName[0] = 0;<br></div><div> dst->rc.bStrictCbr = src->rc.bStrictCbr;<br></div><div> dst->rc.qgSize = src->rc.qgSize;<br></div><div> dst->rc.bEnableGrain = src->rc.bEnableGrain;<br></div><div>@@ -2896,8 +2897,8 @@ void x265_copy_params(x265_param* dst, x265_param* src)<br></div><div> dst->vui.defDispWinRightOffset = src->vui.defDispWinRightOffset;<br></div><div> dst->vui.defDispWinTopOffset = src->vui.defDispWinTopOffset;<br></div><div> <br></div><div>- if (src->masteringDisplayColorVolume) dst->masteringDisplayColorVolume=strdup( src->masteringDisplayColorVolume);<br></div><div>- else dst->masteringDisplayColorVolume = NULL;<br></div><div>+ if (strlen(src->masteringDisplayColorVolume)) snprintf(dst->masteringDisplayColorVolume, X265_MAX_STRING_SIZE, "%s", src->masteringDisplayColorVolume);<br></div><div>+ else dst->masteringDisplayColorVolume[0] = 0;<br></div><div> dst->maxLuma = src->maxLuma;<br></div><div> dst->minLuma = src->minLuma;<br></div><div> dst->bEmitCLL = src->bEmitCLL;<br></div><div>@@ -2926,8 +2927,8 @@ void x265_copy_params(x265_param* dst, x265_param* src)<br></div><div> dst->analysisSaveReuseLevel = src->analysisSaveReuseLevel;<br></div><div> dst->analysisLoadReuseLevel = src->analysisLoadReuseLevel;<br></div><div> dst->bLimitSAO = src->bLimitSAO;<br></div><div>- if (src->toneMapFile) dst->toneMapFile = strdup(src->toneMapFile);<br></div><div>- else dst->toneMapFile = NULL;<br></div><div>+ if (strlen(src->toneMapFile)) snprintf(dst->toneMapFile, X265_MAX_STRING_SIZE, "%s", src->toneMapFile);<br></div><div>+ else dst->toneMapFile[0] = 0;<br></div><div> dst->bDhdr10opt = src->bDhdr10opt;<br></div><div> dst->bCTUInfo = src->bCTUInfo;<br></div><div> dst->bUseRcStats = src->bUseRcStats;<br></div><div>@@ -2949,10 +2950,10 @@ void x265_copy_params(x265_param* dst, x265_param* src)<br></div><div> dst->vbvEndFrameAdjust = src->vbvEndFrameAdjust;<br></div><div> dst->bAnalysisType = src->bAnalysisType;<br></div><div> dst->bCopyPicToFrame = src->bCopyPicToFrame;<br></div><div>- if (src->analysisSave) dst->analysisSave=strdup(src->analysisSave);<br></div><div>- else dst->analysisSave = NULL;<br></div><div>- if (src->analysisLoad) dst->analysisLoad=strdup(src->analysisLoad);<br></div><div>- else dst->analysisLoad = NULL;<br></div><div>+ if (strlen(src->analysisSave)) snprintf(dst->analysisSave, X265_MAX_STRING_SIZE, "%s", src->analysisSave);<br></div><div>+ else dst->analysisSave[0] = 0;<br></div><div>+ if (strlen(src->analysisLoad)) snprintf(dst->analysisLoad, X265_MAX_STRING_SIZE, "%s", src->analysisLoad);<br></div><div>+ else dst->analysisLoad[0] = 0;<br></div><div> dst->gopLookahead = src->gopLookahead;<br></div><div> dst->radl = src->radl;<br></div><div> dst->selectiveSAO = src->selectiveSAO;<br></div><div>@@ -2962,8 +2963,8 @@ void x265_copy_params(x265_param* dst, x265_param* src)<br></div><div> dst->bSingleSeiNal = src->bSingleSeiNal;<br></div><div> dst->chunkStart = src->chunkStart;<br></div><div> dst->chunkEnd = src->chunkEnd;<br></div><div>- if (src->naluFile) dst->naluFile=strdup(src->naluFile);<br></div><div>- else dst->naluFile = NULL;<br></div><div>+ if (src->naluFile) snprintf(dst->naluFile, X265_MAX_STRING_SIZE, "%s", src->naluFile);<br></div><div>+ else dst->naluFile[0] = 0;<br></div><div> dst->scaleFactor = src->scaleFactor;<br></div><div> dst->ctuDistortionRefine = src->ctuDistortionRefine;<br></div><div> dst->bEnableHRDConcatFlag = src->bEnableHRDConcatFlag;<br></div><div>@@ -3001,8 +3002,8 @@ void x265_copy_params(x265_param* dst, x265_param* src)<br></div><div> dst->bEnableSCC = src->bEnableSCC;<br></div><div> #endif<br></div><div> <br></div><div>- if (src->videoSignalTypePreset) dst->videoSignalTypePreset = strdup(src->videoSignalTypePreset);<br></div><div>- else dst->videoSignalTypePreset = NULL;<br></div><div>+ if (strlen(src->videoSignalTypePreset)) snprintf(dst->videoSignalTypePreset, X265_MAX_STRING_SIZE, "%s", src->videoSignalTypePreset);<br></div><div>+ else dst->videoSignalTypePreset[0] = 0;<br></div><div> #ifdef SVT_HEVC<br></div><div> memcpy(dst->svtHevcParam, src->svtHevcParam, sizeof(EB_H265_ENC_CONFIGURATION));<br></div><div> #endif<br></div><div>@@ -3236,6 +3237,7 @@ int svt_param_parse(x265_param* param, const char* name, const char* value)<br></div><div> svtHevcParam->logicalProcessors = atoi(temp1);<br></div><div> }<br></div><div> }<br></div><div>+ free(pools);<br></div><div> }<br></div><div> OPT("high-tier") svtHevcParam->tier = x265_atobool(value, bError);<br></div><div> OPT("qpmin") svtHevcParam->minQpAllowed = atoi(value);<br></div><div>diff --git a/source/common/temporalfilter.cpp b/source/common/temporalfilter.cpp<br></div><div>index 215feaa0f..75b7f2188 100644<br></div><div>--- a/source/common/temporalfilter.cpp<br></div><div>+++ b/source/common/temporalfilter.cpp<br></div><div>@@ -153,6 +153,13 @@ TemporalFilter::TemporalFilter()<br></div><div> m_motionVectorFactor = 16;<br></div><div> }<br></div><div> <br></div><div>+TemporalFilter::~TemporalFilter()<br></div><div>+{<br></div><div>+ if (m_metld)<br></div><div>+ delete m_metld;<br></div><div>+ predPUYuv.destroy();<br></div><div>+}<br></div><div>+<br></div><div> void TemporalFilter::init(const x265_param* param)<br></div><div> {<br></div><div> m_param = param;<br></div><div>diff --git a/source/common/temporalfilter.h b/source/common/temporalfilter.h<br></div><div>index 723644633..bc7109b40 100644<br></div><div>--- a/source/common/temporalfilter.h<br></div><div>+++ b/source/common/temporalfilter.h<br></div><div>@@ -118,7 +118,7 @@ namespace X265_NS {<br></div><div> {<br></div><div> public:<br></div><div> TemporalFilter();<br></div><div>- ~TemporalFilter() {}<br></div><div>+ ~TemporalFilter();<br></div><div> <br></div><div> void init(const x265_param* param);<br></div><div> <br></div><div>diff --git a/source/common/threadpool.cpp b/source/common/threadpool.cpp<br></div><div>index ab6bd0d43..b3505e5c0 100644<br></div><div>--- a/source/common/threadpool.cpp<br></div><div>+++ b/source/common/threadpool.cpp<br></div><div>@@ -302,7 +302,7 @@ ThreadPool* ThreadPool::allocThreadPools(x265_param* p, int& numPools, bool isTh<br></div><div> * For windows because threads can't be allocated to live across sockets<br></div><div> * changing the default behavior to be per-socket pools -- FIXME */<br></div><div> #if defined(_WIN32_WINNT) && _WIN32_WINNT >= _WIN32_WINNT_WIN7 || HAVE_LIBNUMA<br></div><div>- if (!p->numaPools || (strcmp(p->numaPools, "NULL") == 0 || strcmp(p->numaPools, "*") == 0 || strcmp(p->numaPools, "") == 0))<br></div><div>+ if (!strlen(p->numaPools) || (strcmp(p->numaPools, "NULL") == 0 || strcmp(p->numaPools, "*") == 0 || strcmp(p->numaPools, "") == 0))<br></div><div> {<br></div><div> char poolString[50] = "";<br></div><div> for (int i = 0; i < numNumaNodes; i++)<br></div><div>@@ -317,7 +317,7 @@ ThreadPool* ThreadPool::allocThreadPools(x265_param* p, int& numPools, bool isTh<br></div><div> x265_param_parse(p, "pools", poolString);<br></div><div> }<br></div><div> #endif<br></div><div>- if (p->numaPools && *p->numaPools)<br></div><div>+ if (strlen(p->numaPools))<br></div><div> {<br></div><div> const char *nodeStr = p->numaPools;<br></div><div> for (int i = 0; i < numNumaNodes; i++)<br></div><div>diff --git a/source/encoder/analysis.cpp b/source/encoder/analysis.cpp<br></div><div>index 6c72283f3..da5aeca77 100644<br></div><div>--- a/source/encoder/analysis.cpp<br></div><div>+++ b/source/encoder/analysis.cpp<br></div><div>@@ -203,7 +203,7 @@ Mode& Analysis::compressCTU(CUData& ctu, Frame& frame, const CUGeom& cuGeom, con<br></div><div> }<br></div><div> <br></div><div> int reuseLevel = X265_MAX(m_param->analysisSaveReuseLevel, m_param->analysisLoadReuseLevel);<br></div><div>- if ((m_param->analysisSave || m_param->analysisLoad) && m_slice->m_sliceType != I_SLICE && reuseLevel > 1 && reuseLevel < 10)<br></div><div>+ if ((strlen(m_param->analysisSave) || strlen(m_param->analysisLoad)) && m_slice->m_sliceType != I_SLICE && reuseLevel > 1 && reuseLevel < 10)<br></div><div> {<br></div><div> int numPredDir = m_slice->isInterP() ? 1 : 2;<br></div><div> m_reuseInterDataCTU = m_frame->m_analysisData.interData;<br></div><div>@@ -217,7 +217,7 @@ Mode& Analysis::compressCTU(CUData& ctu, Frame& frame, const CUGeom& cuGeom, con<br></div><div> m_reusePartSize = &m_reuseInterDataCTU->partSize[ctu.m_cuAddr * ctu.m_numPartitions];<br></div><div> m_reuseMergeFlag = &m_reuseInterDataCTU->mergeFlag[ctu.m_cuAddr * ctu.m_numPartitions];<br></div><div> }<br></div><div>- if (m_param->analysisSave && !m_param->analysisLoad)<br></div><div>+ if (strlen(m_param->analysisSave) && !strlen(m_param->analysisLoad))<br></div><div> for (int i = 0; i < X265_MAX_PRED_MODE_PER_CTU * numPredDir; i++)<br></div><div> m_reuseRef[i] = -1;<br></div><div> }<br></div><div>@@ -4130,7 +4130,7 @@ int Analysis::calculateQpforCuSize(const CUData& ctu, const CUGeom& cuGeom, int3<br></div><div> double qp = baseQp >= 0 ? baseQp : curEncData.m_cuStat[ctu.m_cuAddr].baseQp;<br></div><div> bool bCuTreeOffset = IS_REFERENCED(m_frame) && m_param->rc.cuTree && !complexCheck;<br></div><div> <br></div><div>- if ((m_param->analysisMultiPassDistortion && m_param->rc.bStatRead) || (m_param->ctuDistortionRefine && m_param->analysisLoad))<br></div><div>+ if ((m_param->analysisMultiPassDistortion && m_param->rc.bStatRead) || (m_param->ctuDistortionRefine && strlen(m_param->analysisLoad)))<br></div><div> {<br></div><div> x265_analysis_distortion_data* distortionData = m_frame->m_analysisData.distortionData;<br></div><div> if ((distortionData->threshold[ctu.m_cuAddr] < 0.9 || distortionData->threshold[ctu.m_cuAddr] > 1.1)<br></div><div>diff --git a/source/encoder/api.cpp b/source/encoder/api.cpp<br></div><div>index 5d2a951e5..abcb2113c 100644<br></div><div>--- a/source/encoder/api.cpp<br></div><div>+++ b/source/encoder/api.cpp<br></div><div>@@ -204,6 +204,8 @@ x265_encoder *x265_encoder_open(x265_param *p)<br></div><div> }<br></div><div> }<br></div><div> <br></div><div>+ // Need free zone because follow up Memcpy will broken all of pointer<br></div><div>+ x265_zone_free(zoneParam);<br></div><div> memcpy(zoneParam, param, sizeof(x265_param));<br></div><div> for (int i = 0; i < param->rc.zonefileCount; i++)<br></div><div> {<br></div><div>@@ -211,7 +213,7 @@ x265_encoder *x265_encoder_open(x265_param *p)<br></div><div> }<br></div><div> <br></div><div> /* Try to open CSV file handle */<br></div><div>- if (encoder->m_param->csvfn)<br></div><div>+ if (strlen(encoder->m_param->csvfn))<br></div><div> {<br></div><div> encoder->m_param->csvfpt = x265_csvlog_open(encoder->m_param);<br></div><div> if (!encoder->m_param->csvfpt)<br></div><div>@@ -221,6 +223,7 @@ x265_encoder *x265_encoder_open(x265_param *p)<br></div><div> }<br></div><div> }<br></div><div> <br></div><div>+ encoder->m_templateParam = param;<br></div><div> encoder->m_latestParam = latestParam;<br></div><div> encoder->m_zoneParam = zoneParam;<br></div><div> x265_copy_params(latestParam, param);<br></div><div>@@ -309,7 +312,7 @@ int x265_encoder_reconfig(x265_encoder* enc, x265_param* param_in)<br></div><div> return -1;<br></div><div> x265_param save;<br></div><div> Encoder* encoder = static_cast<Encoder*>(enc);<br></div><div>- if (encoder->m_param->csvfn == NULL && param_in->csvfpt != NULL)<br></div><div>+ if (strlen(encoder->m_param->csvfn) && param_in->csvfpt != NULL)<br></div><div> encoder->m_param->csvfpt = param_in->csvfpt;<br></div><div> if (encoder->m_latestParam->forceFlush != param_in->forceFlush)<br></div><div> return encoder->reconfigureParam(encoder->m_latestParam, param_in);<br></div><div>@@ -327,18 +330,20 @@ int x265_encoder_reconfig(x265_encoder* enc, x265_param* param_in)<br></div><div> {<br></div><div> /* reconfigure failed, recover saved param set */<br></div><div> x265_copy_params(encoder->m_latestParam, &save);<br></div><div>+ x265_zone_free(&save);<br></div><div> ret = -1;<br></div><div> }<br></div><div> else<br></div><div> {<br></div><div> encoder->configure(encoder->m_latestParam);<br></div><div>- if (encoder->m_latestParam->scalingLists && encoder->m_latestParam->scalingLists != encoder->m_param->scalingLists)<br></div><div>+ if (strlen(encoder->m_latestParam->scalingLists) && strcmp(encoder->m_latestParam->scalingLists, encoder->m_param->scalingLists))<br></div><div> {<br></div><div> if (encoder->m_param->bRepeatHeaders)<br></div><div> {<br></div><div> if (encoder->m_scalingList.parseScalingList(encoder->m_latestParam->scalingLists))<br></div><div> {<br></div><div> x265_copy_params(encoder->m_latestParam, &save);<br></div><div>+ x265_zone_free(&save);<br></div><div> return -1;<br></div><div> }<br></div><div> encoder->m_scalingList.setupQuantMatrices(encoder->m_param->internalCsp);<br></div><div>@@ -347,6 +352,7 @@ int x265_encoder_reconfig(x265_encoder* enc, x265_param* param_in)<br></div><div> {<br></div><div> x265_log(encoder->m_param, X265_LOG_ERROR, "Repeat headers is turned OFF, cannot reconfigure scalinglists\n");<br></div><div> x265_copy_params(encoder->m_latestParam, &save);<br></div><div>+ x265_zone_free(&save);<br></div><div> return -1;<br></div><div> }<br></div><div> }<br></div><div>@@ -373,6 +379,7 @@ int x265_encoder_reconfig(x265_encoder* enc, x265_param* param_in)<br></div><div> /* Zones support modifying num of Refs. Requires determining level at each zone start*/<br></div><div> if (encoder->m_param->rc.zonefileCount)<br></div><div> determineLevel(*encoder->m_latestParam, encoder->m_vps);<br></div><div>+ x265_zone_free(&save);<br></div><div> return ret;<br></div><div> }<br></div><div> <br></div><div>@@ -1009,7 +1016,7 @@ void x265_picture_init(x265_param *param, x265_picture *pic)<br></div><div> pic->picStruct = 0;<br></div><div> pic->vbvEndFlag = 0;<br></div><div> <br></div><div>- if ((param->analysisSave || param->analysisLoad) || (param->bAnalysisType == AVC_INFO))<br></div><div>+ if ((strlen(param->analysisSave) || strlen(param->analysisLoad)) || (param->bAnalysisType == AVC_INFO))<br></div><div> {<br></div><div> uint32_t widthInCU = (param->sourceWidth + param->maxCUSize - 1) >> param->maxLog2CUSize;<br></div><div> uint32_t heightInCU = (param->sourceHeight + param->maxCUSize - 1) >> param->maxLog2CUSize;<br></div><div>@@ -1041,6 +1048,8 @@ void x265_zone_free(x265_param *param)<br></div><div> {<br></div><div> for (int i = 0; i < param->rc.zonefileCount; i++)<br></div><div> x265_free(param->rc.zones[i].zoneParam);<br></div><div>+ param->rc.zonefileCount = 0;<br></div><div>+ param->rc.zoneCount = 0;<br></div><div> x265_free(param->rc.zones);<br></div><div> }<br></div><div> }<br></div><div>diff --git a/source/encoder/encoder.cpp b/source/encoder/encoder.cpp<br></div><div>index 5f784e72b..d1d12e91c 100644<br></div><div>--- a/source/encoder/encoder.cpp<br></div><div>+++ b/source/encoder/encoder.cpp<br></div><div>@@ -138,6 +138,7 @@ Encoder::Encoder()<br></div><div> m_outputCount = 0;<br></div><div> m_param = NULL;<br></div><div> m_latestParam = NULL;<br></div><div>+ m_templateParam = NULL;<br></div><div> m_threadPool = NULL;<br></div><div> m_analysisFileIn = NULL;<br></div><div> m_analysisFileOut = NULL;<br></div><div>@@ -255,7 +256,7 @@ void Encoder::create()<br></div><div> p->bEnableWavefront = 0;<br></div><div> }<br></div><div> <br></div><div>- bool allowPools = !p->numaPools || strcmp(p->numaPools, "none");<br></div><div>+ bool allowPools = !strlen(p->numaPools) || strcmp(p->numaPools, "none");<br></div><div> <br></div><div> // Trim the thread pool if --wpp, --pme, and --pmode are disabled<br></div><div> if (!p->bEnableWavefront && !p->bDistributeModeAnalysis && !p->bDistributeMotionEstimation && !p->lookaheadSlices)<br></div><div>@@ -336,7 +337,7 @@ void Encoder::create()<br></div><div> m_aborted = true;<br></div><div> return;<br></div><div> }<br></div><div>- else if (!m_param->scalingLists || !strcmp(m_param->scalingLists, "off"))<br></div><div>+ else if (!strlen(m_param->scalingLists) || !strcmp(m_param->scalingLists, "off"))<br></div><div> m_scalingList.m_bEnabled = false;<br></div><div> else if (!strcmp(m_param->scalingLists, "default"))<br></div><div> m_scalingList.setDefaultScalingList();<br></div><div>@@ -478,7 +479,7 @@ void Encoder::create()<br></div><div> m_aborted = true;<br></div><div> <br></div><div> initRefIdx();<br></div><div>- if (m_param->analysisSave && m_param->bUseAnalysisFile)<br></div><div>+ if (strlen(m_param->analysisSave) && m_param->bUseAnalysisFile)<br></div><div> {<br></div><div> char* temp = strcatFilename(m_param->analysisSave, ".temp");<br></div><div> if (!temp)<br></div><div>@@ -498,7 +499,7 @@ void Encoder::create()<br></div><div> if (m_param->analysisMultiPassRefine || m_param->analysisMultiPassDistortion)<br></div><div> {<br></div><div> const char* name = m_param->analysisReuseFileName;<br></div><div>- if (!name)<br></div><div>+ if (!strlen(name))<br></div><div> name = defaultAnalysisFileName;<br></div><div> if (m_param->rc.bStatWrite)<br></div><div> {<br></div><div>@@ -550,7 +551,7 @@ void Encoder::create()<br></div><div> <br></div><div> m_nalList.m_annexB = !!m_param->bAnnexB;<br></div><div> <br></div><div>- if (m_param->naluFile)<br></div><div>+ if (strlen(m_param->naluFile))<br></div><div> {<br></div><div> m_naluFile = x265_fopen(m_param->naluFile, "r");<br></div><div> if (!m_naluFile)<br></div><div>@@ -951,19 +952,16 @@ void Encoder::destroy()<br></div><div> <br></div><div> if (m_latestParam != NULL && m_latestParam != m_param)<br></div><div> {<br></div><div>- if (m_latestParam->scalingLists != m_param->scalingLists)<br></div><div>- free((char*)m_latestParam->scalingLists);<br></div><div>- if (m_latestParam->numaPools != m_param->numaPools)<br></div><div>- free((char*)m_latestParam->numaPools);<br></div><div>-<br></div><div> PARAM_NS::x265_param_free(m_latestParam);<br></div><div> }<br></div><div> if (m_zoneParam != NULL && m_zoneParam != m_param) {<br></div><div>- if (m_zoneParam->numaPools != m_param->numaPools)<br></div><div>- free((char*)m_zoneParam->numaPools);<br></div><div>-<br></div><div> PARAM_NS::x265_param_free(m_zoneParam);<br></div><div> }<br></div><div>+ if (m_templateParam != NULL && m_templateParam != m_param) {<br></div><div>+ // TODO: we don't free zone here because it is overwrite into m_zoneParam in x265_encoder_open<br></div><div>+ m_templateParam->rc.zonefileCount = m_templateParam->rc.zoneCount = 0;<br></div><div>+ PARAM_NS::x265_param_free(m_templateParam);<br></div><div>+ }<br></div><div> if (m_analysisFileIn)<br></div><div> fclose(m_analysisFileIn);<br></div><div> <br></div><div>@@ -971,8 +969,8 @@ void Encoder::destroy()<br></div><div> {<br></div><div> int bError = 1;<br></div><div> fclose(m_analysisFileOut);<br></div><div>- const char* name = m_param->analysisSave ? m_param->analysisSave : m_param->analysisReuseFileName;<br></div><div>- if (!name)<br></div><div>+ const char* name = strlen(m_param->analysisSave) ? m_param->analysisSave : m_param->analysisReuseFileName;<br></div><div>+ if (!strlen(name))<br></div><div> name = defaultAnalysisFileName;<br></div><div> char* temp = strcatFilename(name, ".temp");<br></div><div> if (temp)<br></div><div>@@ -1000,19 +998,6 @@ void Encoder::destroy()<br></div><div> {<br></div><div> if (m_param->csvfpt)<br></div><div> fclose(m_param->csvfpt);<br></div><div>- /* release string arguments that were strdup'd */<br></div><div>- free((char*)m_param->rc.lambdaFileName);<br></div><div>- free((char*)m_param->rc.statFileName);<br></div><div>- free((char*)m_param->rc.sharedMemName);<br></div><div>- free((char*)m_param->analysisReuseFileName);<br></div><div>- free((char*)m_param->scalingLists);<br></div><div>- free((char*)m_param->csvfn);<br></div><div>- free((char*)m_param->numaPools);<br></div><div>- free((char*)m_param->masteringDisplayColorVolume);<br></div><div>- free((char*)m_param->toneMapFile);<br></div><div>- free((char*)m_param->analysisSave);<br></div><div>- free((char*)m_param->analysisLoad);<br></div><div>- free((char*)m_param->videoSignalTypePreset);<br></div><div> PARAM_NS::x265_param_free(m_param);<br></div><div> }<br></div><div> }<br></div><div>@@ -1509,7 +1494,7 @@ int Encoder::encode(const x265_picture* pic_in, x265_picture* pic_out)<br></div><div> <br></div><div> if (*m_exportedPic)<br></div><div> {<br></div><div>- if (!m_param->bUseAnalysisFile && m_param->analysisSave)<br></div><div>+ if (!m_param->bUseAnalysisFile && strlen(m_param->analysisSave))<br></div><div> x265_free_analysis_data(m_param, &m_exportedPic[0]->m_analysisData);<br></div><div> <br></div><div> for (int i = 0; i < m_param->numLayers; i++)<br></div><div>@@ -1801,7 +1786,7 @@ int Encoder::encode(const x265_picture* pic_in, x265_picture* pic_out)<br></div><div> <br></div><div> /* In analysisSave mode, x265_analysis_data is allocated in inputPic and inFrame points to this */<br></div><div> /* Load analysis data before lookahead->addPicture, since sliceType has been decided */<br></div><div>- if (m_param->analysisLoad)<br></div><div>+ if (strlen(m_param->analysisLoad))<br></div><div> {<br></div><div> /* reads analysis data for the frame and allocates memory based on slicetype */<br></div><div> static int paramBytes = CONF_OFFSET_BYTES;<br></div><div>@@ -1992,7 +1977,7 @@ int Encoder::encode(const x265_picture* pic_in, x265_picture* pic_out)<br></div><div> x265_frame_stats* frameData = NULL;<br></div><div> <br></div><div> /* Free up inputPic->analysisData since it has already been used */<br></div><div>- if ((m_param->analysisLoad && !m_param->analysisSave) || ((m_param->bAnalysisType == AVC_INFO) && slice->m_sliceType != I_SLICE))<br></div><div>+ if ((strlen(m_param->analysisLoad) && !strlen(m_param->analysisSave)) || ((m_param->bAnalysisType == AVC_INFO) && slice->m_sliceType != I_SLICE))<br></div><div> x265_free_analysis_data(m_param, &outFrame->m_analysisData);<br></div><div> if (pic_out)<br></div><div> {<br></div><div>@@ -2020,7 +2005,7 @@ int Encoder::encode(const x265_picture* pic_in, x265_picture* pic_out)<br></div><div> }<br></div><div> <br></div><div> /* Dump analysis data from pic_out to file in save mode and free */<br></div><div>- if (m_param->analysisSave)<br></div><div>+ if (strlen(m_param->analysisSave))<br></div><div> {<br></div><div> pic_out[sLayer].analysisData.poc = pic_out[sLayer].poc;<br></div><div> pic_out[sLayer].analysisData.sliceType = pic_out[sLayer].sliceType;<br></div><div>@@ -2140,7 +2125,7 @@ int Encoder::encode(const x265_picture* pic_in, x265_picture* pic_out)<br></div><div> <br></div><div> if ((m_outputCount + 1) >= m_param->chunkStart)<br></div><div> finishFrameStats(outFrame, curEncoder, frameData, m_pocLast, sLayer);<br></div><div>- if (m_param->analysisSave)<br></div><div>+ if (strlen(m_param->analysisSave))<br></div><div> {<br></div><div> pic_out[sLayer].analysisData.frameBits = frameData->bits;<br></div><div> if (!slice->isIntra())<br></div><div>@@ -2334,7 +2319,7 @@ int Encoder::encode(const x265_picture* pic_in, x265_picture* pic_out)<br></div><div> int baseViewType = frameEnc[0]->m_lowres.sliceType;<br></div><div> frameEnc[layer]->m_encData->m_slice->m_origSliceType = IS_X265_TYPE_B(baseViewType) ? B_SLICE : (baseViewType == X265_TYPE_P) ? P_SLICE : I_SLICE;<br></div><div> }<br></div><div>- if (m_param->analysisLoad && m_param->bDisableLookahead)<br></div><div>+ if (strlen(m_param->analysisLoad) && m_param->bDisableLookahead)<br></div><div> {<br></div><div> frameEnc[0]->m_dts = frameEnc[0]->m_analysisData.lookahead.dts;<br></div><div> frameEnc[0]->m_reorderedPts = frameEnc[0]->m_analysisData.lookahead.reorderedPts;<br></div><div>@@ -2409,7 +2394,7 @@ int Encoder::encode(const x265_picture* pic_in, x265_picture* pic_out)<br></div><div> <br></div><div> curEncoder->m_rce.encodeOrder = frameEnc[0]->m_encodeOrder = m_encodedFrameNum++;<br></div><div> <br></div><div>- if (!m_param->analysisLoad || !m_param->bDisableLookahead)<br></div><div>+ if (!strlen(m_param->analysisLoad) || !m_param->bDisableLookahead)<br></div><div> {<br></div><div> if (m_bframeDelay)<br></div><div> {<br></div><div>@@ -2424,7 +2409,7 @@ int Encoder::encode(const x265_picture* pic_in, x265_picture* pic_out)<br></div><div> }<br></div><div> <br></div><div> /* Allocate analysis data before encode in save mode. This is allocated in frameEnc[0] */<br></div><div>- if (m_param->analysisSave && !m_param->analysisLoad)<br></div><div>+ if (strlen(m_param->analysisSave) && !strlen(m_param->analysisLoad))<br></div><div> {<br></div><div> x265_analysis_data* analysis = &frameEnc[0]->m_analysisData;<br></div><div> analysis->poc = frameEnc[0]->m_poc;<br></div><div>@@ -2618,8 +2603,8 @@ int Encoder::reconfigureParam(x265_param* encParam, x265_param* param)<br></div><div> encParam->bEnableRectInter = param->bEnableRectInter;<br></div><div> encParam->maxNumMergeCand = param->maxNumMergeCand;<br></div><div> encParam->bIntraInBFrames = param->bIntraInBFrames;<br></div><div>- if (param->scalingLists && !encParam->scalingLists)<br></div><div>- encParam->scalingLists = strdup(param->scalingLists);<br></div><div>+ if (strlen(param->scalingLists) && !strlen(encParam->scalingLists))<br></div><div>+ snprintf(encParam->scalingLists, X265_MAX_STRING_SIZE, "%s", param->scalingLists);<br></div><div> <br></div><div> encParam->rc.aqMode = param->rc.aqMode;<br></div><div> encParam->rc.aqStrength = param->rc.aqStrength;<br></div><div>@@ -3442,7 +3427,7 @@ void Encoder::getStreamHeaders(NALList& list, Entropy& sbacCoder, Bitstream& bs)<br></div><div> cllsei.writeSEImessages(bs, m_sps, NAL_UNIT_PREFIX_SEI, list, m_param->bSingleSeiNal);<br></div><div> }<br></div><div> <br></div><div>- if (m_param->masteringDisplayColorVolume)<br></div><div>+ if (strlen(m_param->masteringDisplayColorVolume))<br></div><div> {<br></div><div> SEIMasteringDisplayColorVolume mdsei;<br></div><div> if (mdsei.parse(m_param->masteringDisplayColorVolume))<br></div><div>@@ -3785,8 +3770,8 @@ void Encoder::configureZone(x265_param *p, x265_param *zone)<br></div><div> p->bEnableRectInter = zone->bEnableRectInter;<br></div><div> p->maxNumMergeCand = zone->maxNumMergeCand;<br></div><div> p->bIntraInBFrames = zone->bIntraInBFrames;<br></div><div>- if (zone->scalingLists)<br></div><div>- p->scalingLists = strdup(zone->scalingLists);<br></div><div>+ if (strlen(zone->scalingLists))<br></div><div>+ snprintf(p->scalingLists, X265_MAX_STRING_SIZE, "%s", zone->scalingLists);<br></div><div> <br></div><div> p->rc.aqMode = zone->rc.aqMode;<br></div><div> p->rc.aqStrength = zone->rc.aqStrength;<br></div><div>@@ -3883,15 +3868,15 @@ void Encoder::configureVideoSignalTypePreset(x265_param* p)<br></div><div> p->bEmitHDR10SEI = 1;<br></div><div> if (!strcmp(colorVolume, "P3D65x1000n0005"))<br></div><div> {<br></div><div>- p->masteringDisplayColorVolume = strdup("G(13250,34500)B(7500,3000)R(34000,16000)WP(15635,16450)L(10000000,5)");<br></div><div>+ snprintf(p->masteringDisplayColorVolume, X265_MAX_STRING_SIZE, "G(13250,34500)B(7500,3000)R(34000,16000)WP(15635,16450)L(10000000,5)");<br></div><div> }<br></div><div> else if (!strcmp(colorVolume, "P3D65x4000n005"))<br></div><div> {<br></div><div>- p->masteringDisplayColorVolume = strdup("G(13250,34500)B(7500,3000)R(34000,16000)WP(15635,16450)L(40000000,50)");<br></div><div>+ snprintf(p->masteringDisplayColorVolume, X265_MAX_STRING_SIZE, "G(13250,34500)B(7500,3000)R(34000,16000)WP(15635,16450)L(40000000,50)");<br></div><div> }<br></div><div> else if (!strcmp(colorVolume, "BT2100x108n0005"))<br></div><div> {<br></div><div>- p->masteringDisplayColorVolume = strdup("G(8500,39850)B(6550,2300)R(34000,146000)WP(15635,16450)L(10000000,1)");<br></div><div>+ snprintf(p->masteringDisplayColorVolume, X265_MAX_STRING_SIZE, "G(8500,39850)B(6550,2300)R(34000,146000)WP(15635,16450)L(10000000,1)");<br></div><div> }<br></div><div> else<br></div><div> {<br></div><div>@@ -4107,37 +4092,37 @@ void Encoder::configure(x265_param *p)<br></div><div> p->rc.rfConstantMin = 0;<br></div><div> }<br></div><div> <br></div><div>- if (p->analysisSaveReuseLevel && !p->analysisSave)<br></div><div>+ if (p->analysisSaveReuseLevel && !strlen(p->analysisSave))<br></div><div> {<br></div><div> x265_log(p, X265_LOG_WARNING, "analysis-save-reuse-level can be set only when analysis-save is enabled."<br></div><div> " Resetting analysis-save-reuse-level to 0.\n");<br></div><div> p->analysisSaveReuseLevel = 0;<br></div><div> }<br></div><div> <br></div><div>- if (p->analysisLoadReuseLevel && !p->analysisLoad)<br></div><div>+ if (p->analysisLoadReuseLevel && !strlen(p->analysisLoad))<br></div><div> {<br></div><div> x265_log(p, X265_LOG_WARNING, "analysis-load-reuse-level can be set only when analysis-load is enabled."<br></div><div> " Resetting analysis-load-reuse-level to 0.\n");<br></div><div> p->analysisLoadReuseLevel = 0;<br></div><div> }<br></div><div> <br></div><div>- if (p->analysisSave && !p->analysisSaveReuseLevel)<br></div><div>+ if (strlen(p->analysisSave) && !p->analysisSaveReuseLevel)<br></div><div> p->analysisSaveReuseLevel = 5;<br></div><div> <br></div><div>- if (p->analysisLoad && !p->analysisLoadReuseLevel)<br></div><div>+ if (strlen(p->analysisLoad) && !p->analysisLoadReuseLevel)<br></div><div> p->analysisLoadReuseLevel = 5;<br></div><div> <br></div><div>- if ((p->analysisLoad || p->analysisSave) && (p->bDistributeModeAnalysis || p->bDistributeMotionEstimation))<br></div><div>+ if ((strlen(p->analysisLoad) || p->analysisSave) && (p->bDistributeModeAnalysis || p->bDistributeMotionEstimation))<br></div><div> {<br></div><div> x265_log(p, X265_LOG_WARNING, "Analysis load/save options incompatible with pmode/pme, Disabling pmode/pme\n");<br></div><div> p->bDistributeMotionEstimation = p->bDistributeModeAnalysis = 0;<br></div><div> }<br></div><div> <br></div><div>- if ((p->analysisLoad || p->analysisSave) && (p->analysisMultiPassRefine || p->analysisMultiPassDistortion))<br></div><div>+ if ((strlen(p->analysisLoad) || strlen(p->analysisSave)) && (p->analysisMultiPassRefine || p->analysisMultiPassDistortion))<br></div><div> {<br></div><div> x265_log(p, X265_LOG_WARNING, "Cannot use Analysis load/save option and multi-pass-opt-analysis/multi-pass-opt-distortion together,"<br></div><div> "Disabling Analysis load/save and multi-pass-opt-analysis/multi-pass-opt-distortion\n");<br></div><div>- p->analysisSave = p->analysisLoad = NULL;<br></div><div>+ p->analysisSave[0] = p->analysisLoad[0] = 0;<br></div><div> p->analysisMultiPassRefine = p->analysisMultiPassDistortion = 0;<br></div><div> }<br></div><div> if (p->scaleFactor)<br></div><div>@@ -4190,12 +4175,12 @@ void Encoder::configure(x265_param *p)<br></div><div> <br></div><div> if (p->ctuDistortionRefine == CTU_DISTORTION_INTERNAL)<br></div><div> {<br></div><div>- if (!p->analysisLoad && !p->analysisSave)<br></div><div>+ if (!strlen(p->analysisLoad) && !strlen(p->analysisSave))<br></div><div> {<br></div><div> x265_log(p, X265_LOG_WARNING, "refine-ctu-distortion 1 requires analysis save/load. Disabling refine-ctu-distortion\n");<br></div><div> p->ctuDistortionRefine = 0;<br></div><div> }<br></div><div>- if (p->scaleFactor && p->analysisLoad)<br></div><div>+ if (p->scaleFactor && strlen(p->analysisLoad))<br></div><div> {<br></div><div> x265_log(p, X265_LOG_WARNING, "refine-ctu-distortion 1 cannot be enabled along with multi resolution analysis refinement. Disabling refine-ctu-distortion\n");<br></div><div> p->ctuDistortionRefine = 0;<br></div><div>@@ -4317,7 +4302,7 @@ void Encoder::configure(x265_param *p)<br></div><div> p->bEnableTSkipFast &= p->bEnableTransformSkip;<br></div><div> p->bLimitSAO &= p->bEnableSAO;<br></div><div> <br></div><div>- if (m_param->bUseAnalysisFile && m_param->analysisLoad && (p->confWinRightOffset || p->confWinBottomOffset))<br></div><div>+ if (m_param->bUseAnalysisFile && strlen(m_param->analysisLoad) && (p->confWinRightOffset || p->confWinBottomOffset))<br></div><div> x265_log(p, X265_LOG_WARNING, "It is recommended not to set conformance window offset in file based analysis-load."<br></div><div> " Offsets are shared in the analysis file already.\n");<br></div><div> /* initialize the conformance window */<br></div><div>@@ -4328,7 +4313,7 @@ void Encoder::configure(x265_param *p)<br></div><div> m_conformanceWindow.leftOffset = 0;<br></div><div> <br></div><div> uint32_t padsize = 0;<br></div><div>- if (m_param->analysisLoad && m_param->bUseAnalysisFile)<br></div><div>+ if (strlen(m_param->analysisLoad) && m_param->bUseAnalysisFile)<br></div><div> {<br></div><div> m_analysisFileIn = x265_fopen(m_param->analysisLoad, "rb");<br></div><div> if (!m_analysisFileIn)<br></div><div>@@ -4459,19 +4444,19 @@ void Encoder::configure(x265_param *p)<br></div><div> m_param->bEnableFrameDuplication = 0;<br></div><div> }<br></div><div> #ifdef ENABLE_HDR10_PLUS<br></div><div>- if (m_param->bDhdr10opt && m_param->toneMapFile == NULL)<br></div><div>+ if (m_param->bDhdr10opt && strlen(m_param->toneMapFile) == 0)<br></div><div> {<br></div><div> x265_log(p, X265_LOG_WARNING, "Disabling dhdr10-opt. dhdr10-info must be enabled.\n");<br></div><div> m_param->bDhdr10opt = 0;<br></div><div> }<br></div><div> <br></div><div>- if (m_param->toneMapFile)<br></div><div>+ if (strlen(m_param->toneMapFile))<br></div><div> {<br></div><div> if (!x265_fopen(p->toneMapFile, "r"))<br></div><div> {<br></div><div> x265_log(p, X265_LOG_ERROR, "Unable to open tone-map file.\n");<br></div><div> m_bToneMap = 0;<br></div><div>- m_param->toneMapFile = NULL;<br></div><div>+ m_param->toneMapFile[0] = 0;<br></div><div> m_aborted = true;<br></div><div> }<br></div><div> else<br></div><div>@@ -4480,11 +4465,11 @@ void Encoder::configure(x265_param *p)<br></div><div> else<br></div><div> m_bToneMap = 0;<br></div><div> #else<br></div><div>- if (m_param->toneMapFile)<br></div><div>+ if (strlen(m_param->toneMapFile))<br></div><div> {<br></div><div> x265_log(p, X265_LOG_WARNING, "--dhdr10-info disabled. Enable HDR10_PLUS in cmake.\n");<br></div><div> m_bToneMap = 0;<br></div><div>- m_param->toneMapFile = NULL;<br></div><div>+ m_param->toneMapFile[0] = 0;<br></div><div> }<br></div><div> else if (m_param->bDhdr10opt)<br></div><div> {<br></div><div>@@ -4648,10 +4633,10 @@ void Encoder::configure(x265_param *p)<br></div><div> }<br></div><div> }<br></div><div> <br></div><div>- if (p->videoSignalTypePreset) // Default disabled.<br></div><div>+ if (strlen(p->videoSignalTypePreset)) // Default disabled.<br></div><div> configureVideoSignalTypePreset(p);<br></div><div> <br></div><div>- if (m_param->toneMapFile || p->bHDR10Opt || p->bEmitHDR10SEI)<br></div><div>+ if (strlen(m_param->toneMapFile) || p->bHDR10Opt || p->bEmitHDR10SEI)<br></div><div> {<br></div><div> if (!p->bRepeatHeaders)<br></div><div> {<br></div><div>@@ -6281,6 +6266,8 @@ void Encoder::readUserSeiFile(x265_sei_payload& seiMsg, int curPoc)<br></div><div> x265_log(m_param, X265_LOG_WARNING, "SEI message for frame %d is not inserted. Will support only PREFIX SEI messages.\n", poc);<br></div><div> break;<br></div><div> }<br></div><div>+ if (base64Decode)<br></div><div>+ free(base64Decode);<br></div><div> }<br></div><div> }<br></div><div> <br></div><div>diff --git a/source/encoder/encoder.h b/source/encoder/encoder.h<br></div><div>index 6289779e7..95c73de8a 100644<br></div><div>--- a/source/encoder/encoder.h<br></div><div>+++ b/source/encoder/encoder.h<br></div><div>@@ -209,6 +209,7 @@ public:<br></div><div> x265_param* m_param;<br></div><div> x265_param* m_latestParam; // Holds latest param during a reconfigure<br></div><div> x265_param* m_zoneParam;<br></div><div>+ x265_param* m_templateParam;<br></div><div> RateControl* m_rateControl;<br></div><div> Lookahead* m_lookahead;<br></div><div> AdaptiveFrameDuplication* m_dupBuffer[DUP_BUFFER]; // picture buffer of size 2<br></div><div>diff --git a/source/encoder/frameencoder.cpp b/source/encoder/frameencoder.cpp<br></div><div>index b6f2d6ed1..95eef813b 100644<br></div><div>--- a/source/encoder/frameencoder.cpp<br></div><div>+++ b/source/encoder/frameencoder.cpp<br></div><div>@@ -109,8 +109,6 @@ void FrameEncoder::destroy()<br></div><div> <br></div><div> if (m_param->bEnableTemporalFilter)<br></div><div> {<br></div><div>- delete m_frameEncTF->m_metld;<br></div><div>-<br></div><div> for (int i = 0; i < (m_frameEncTF->m_range << 1); i++)<br></div><div> m_frameEncTF->destroyRefPicInfo(&m_mcstfRefList[i]);<br></div><div> <br></div><div>@@ -368,7 +366,7 @@ void FrameEncoder::threadMain()<br></div><div> while (!m_frame[0]->m_ctuInfo)<br></div><div> m_frame[0]->m_copied.wait();<br></div><div> }<br></div><div>- if ((m_param->bAnalysisType == AVC_INFO) && !m_param->analysisSave && !m_param->analysisLoad && !(IS_X265_TYPE_I(m_frame[0]->m_lowres.sliceType)))<br></div><div>+ if ((m_param->bAnalysisType == AVC_INFO) && !strlen(m_param->analysisSave) && !strlen(m_param->analysisLoad) && !(IS_X265_TYPE_I(m_frame[0]->m_lowres.sliceType)))<br></div><div> {<br></div><div> while (((m_frame[0]->m_analysisData.interData == NULL && m_frame[0]->m_analysisData.intraData == NULL) || (uint32_t)m_frame[0]->m_poc != m_frame[0]->m_analysisData.poc))<br></div><div> m_frame[0]->m_copyMVType.wait();<br></div><div>@@ -555,7 +553,7 @@ void FrameEncoder::compressFrame(int layer)<br></div><div> m_cuStats.countWeightAnalyze++;<br></div><div> ScopedElapsedTime time(m_cuStats.weightAnalyzeTime);<br></div><div> #endif<br></div><div>- if (m_param->analysisLoad)<br></div><div>+ if (strlen(m_param->analysisLoad))<br></div><div> {<br></div><div> for (int list = 0; list < slice->isInterB() + 1; list++) <br></div><div> {<br></div><div>@@ -580,7 +578,7 @@ void FrameEncoder::compressFrame(int layer)<br></div><div> else<br></div><div> slice->disableWeights();<br></div><div> <br></div><div>- if (m_param->analysisSave && (bUseWeightP || bUseWeightB))<br></div><div>+ if (strlen(m_param->analysisSave) && (bUseWeightP || bUseWeightB))<br></div><div> reuseWP = (WeightParam*)m_frame[layer]->m_analysisData.wt;<br></div><div> // Generate motion references<br></div><div> int numPredDir = slice->isInterP() ? 1 : slice->isInterB() ? 2 : 0;<br></div><div>@@ -594,7 +592,7 @@ void FrameEncoder::compressFrame(int layer)<br></div><div> slice->m_refReconPicList[l][ref] = slice->m_refFrameList[l][ref]->m_reconPic[0];<br></div><div> m_mref[l][ref].init(slice->m_refReconPicList[l][ref], w, *m_param);<br></div><div> }<br></div><div>- if (m_param->analysisSave && (bUseWeightP || bUseWeightB))<br></div><div>+ if (strlen(m_param->analysisSave) && (bUseWeightP || bUseWeightB))<br></div><div> {<br></div><div> for (int i = 0; i < (m_param->internalCsp != X265_CSP_I400 ? 3 : 1); i++)<br></div><div> *(reuseWP++) = slice->m_weightPredTable[l][0][i];<br></div><div>@@ -1656,7 +1654,7 @@ void FrameEncoder::processRowEncoder(int intRow, ThreadLocalData& tld, int layer<br></div><div> /* TODO: use defines from slicetype.h for lowres block size */<br></div><div> uint32_t block_y = (ctu->m_cuPelY >> m_param->maxLog2CUSize) * noOfBlocks;<br></div><div> uint32_t block_x = (ctu->m_cuPelX >> m_param->maxLog2CUSize) * noOfBlocks;<br></div><div>- if (!m_param->analysisLoad || !m_param->bDisableLookahead)<br></div><div>+ if (!strlen(m_param->analysisLoad) || !m_param->bDisableLookahead)<br></div><div> {<br></div><div> cuStat.vbvCost = 0;<br></div><div> cuStat.intraVbvCost = 0;<br></div><div>diff --git a/source/encoder/framefilter.cpp b/source/encoder/framefilter.cpp<br></div><div>index 71dc42b2c..b58799afd 100644<br></div><div>--- a/source/encoder/framefilter.cpp<br></div><div>+++ b/source/encoder/framefilter.cpp<br></div><div>@@ -162,11 +162,9 @@ void FrameFilter::destroy()<br></div><div> <br></div><div> if (m_parallelFilter)<br></div><div> {<br></div><div>- if (m_useSao)<br></div><div>- {<br></div><div>- for(int row = 0; row < m_numRows; row++)<br></div><div>- m_parallelFilter[row].m_sao.destroy((row == 0 ? 1 : 0));<br></div><div>- }<br></div><div>+ // NOTE: don't check m_useSao because it is dynamic controllable<br></div><div>+ for(int row = 0; row < m_numRows; row++)<br></div><div>+ m_parallelFilter[row].m_sao.destroy((row == 0 ? 1 : 0));<br></div><div> <br></div><div> delete[] m_parallelFilter;<br></div><div> m_parallelFilter = NULL;<br></div><div>diff --git a/source/encoder/ratecontrol.cpp b/source/encoder/ratecontrol.cpp<br></div><div>index e46896987..5908992ce 100644<br></div><div>--- a/source/encoder/ratecontrol.cpp<br></div><div>+++ b/source/encoder/ratecontrol.cpp<br></div><div>@@ -496,7 +496,7 @@ bool RateControl::init(const SPS& sps)<br></div><div> {<br></div><div> /* If the user hasn't defined the stat filename, use the default value */<br></div><div> const char *fileName = m_param->rc.statFileName;<br></div><div>- if (!fileName)<br></div><div>+ if (!strlen(fileName))<br></div><div> fileName = s_defaultStatFileName;<br></div><div> /* Load stat file and init 2pass algo */<br></div><div> if (m_param->rc.bStatRead)<br></div><div>@@ -3329,7 +3329,7 @@ void RateControl::terminate()<br></div><div> void RateControl::destroy()<br></div><div> {<br></div><div> const char *fileName = m_param->rc.statFileName;<br></div><div>- if (!fileName)<br></div><div>+ if (!strlen(fileName))<br></div><div> fileName = s_defaultStatFileName;<br></div><div> <br></div><div> if (m_statFileOut)<br></div><div>diff --git a/source/encoder/search.cpp b/source/encoder/search.cpp<br></div><div>index e398843a8..2a324700d 100644<br></div><div>--- a/source/encoder/search.cpp<br></div><div>+++ b/source/encoder/search.cpp<br></div><div>@@ -2135,7 +2135,7 @@ void Search::singleMotionEstimation(Search& master, Mode& interMode, const Predi<br></div><div> bool bLowresMVP = false;<br></div><div> MV mvmin, mvmax, outmv, mvp = amvp[mvpIdx], mvp_lowres;<br></div><div> <br></div><div>- if (!m_param->analysisSave && !m_param->analysisLoad) /* Prevents load/save outputs from diverging if lowresMV is not available */<br></div><div>+ if (!strlen(m_param->analysisSave) && !strlen(m_param->analysisLoad)) /* Prevents load/save outputs from diverging if lowresMV is not available */<br></div><div> {<br></div><div> MV lmv = getLowresMV(interMode.cu, pu, list, ref);<br></div><div> int layer = m_param->numViews > 1 ? m_frame->m_viewId : (m_param->numScalableLayers > 1) ? m_frame->m_sLayerId : 0;<br></div><div>@@ -2476,7 +2476,7 @@ void Search::predInterSearch(Mode& interMode, const CUGeom& cuGeom, bool bChroma<br></div><div> MV mvmin, mvmax, outmv, mvp = amvp[mvpIdx], mvp_lowres;<br></div><div> bool bLowresMVP = false;<br></div><div> <br></div><div>- if (!m_param->analysisSave && !m_param->analysisLoad) /* Prevents load/save outputs from diverging when lowresMV is not available */<br></div><div>+ if (!strlen(m_param->analysisSave) && !strlen(m_param->analysisLoad)) /* Prevents load/save outputs from diverging when lowresMV is not available */<br></div><div> {<br></div><div> MV lmv = getLowresMV(cu, pu, list, ref);<br></div><div> int layer = m_param->numViews > 1 ? m_frame->m_viewId : (m_param->numScalableLayers > 1) ? m_frame->m_sLayerId : 0;<br></div><div>diff --git a/source/encoder/slicetype.cpp b/source/encoder/slicetype.cpp<br></div><div>index 046cf1596..f44c11ac4 100644<br></div><div>--- a/source/encoder/slicetype.cpp<br></div><div>+++ b/source/encoder/slicetype.cpp<br></div><div>@@ -1194,7 +1194,7 @@ void Lookahead::destroy()<br></div><div> /* Called by API thread */<br></div><div> void Lookahead::addPicture(Frame& curFrame, int sliceType)<br></div><div> {<br></div><div>- if (m_param->analysisLoad && m_param->bDisableLookahead)<br></div><div>+ if (strlen(m_param->analysisLoad) && m_param->bDisableLookahead)<br></div><div> {<br></div><div> if (!m_filled)<br></div><div> m_filled = true;<br></div><div>@@ -1295,7 +1295,7 @@ Frame* Lookahead::getDecidedPicture()<br></div><div> return out;<br></div><div> }<br></div><div> <br></div><div>- if (m_param->analysisLoad && m_param->bDisableLookahead)<br></div><div>+ if (strlen(m_param->analysisLoad) && m_param->bDisableLookahead)<br></div><div> return NULL;<br></div><div> <br></div><div> findJob(-1); /* run slicetypeDecide() if necessary */<br></div><div>@@ -1365,14 +1365,14 @@ void Lookahead::getEstimatedPictureCost(Frame *curFrame)<br></div><div> default:<br></div><div> return;<br></div><div> }<br></div><div>- if (!curFrame->m_param->analysisLoad || !curFrame->m_param->bDisableLookahead)<br></div><div>+ if (!strlen(curFrame->m_param->analysisLoad) || !curFrame->m_param->bDisableLookahead)<br></div><div> {<br></div><div> X265_CHECK(curFrame->m_lowres.costEst[b - p0][p1 - b] > 0, "Slice cost not estimated\n")<br></div><div> <br></div><div> if (curFrame->m_param->rc.cuTree && !curFrame->m_param->rc.bStatRead)<br></div><div> /* update row satds based on cutree offsets */<br></div><div> curFrame->m_lowres.satdCost = frameCostRecalculate(frames, p0, p1, b);<br></div><div>- else if (!curFrame->m_param->analysisLoad || curFrame->m_param->scaleFactor || curFrame->m_param->bAnalysisType == HEVC_INFO)<br></div><div>+ else if (!strlen(curFrame->m_param->analysisLoad) || curFrame->m_param->scaleFactor || curFrame->m_param->bAnalysisType == HEVC_INFO)<br></div><div> {<br></div><div> if (curFrame->m_param->rc.aqMode)<br></div><div> curFrame->m_lowres.satdCost = curFrame->m_lowres.costEstAq[b - p0][p1 - b];<br></div><div>@@ -1909,7 +1909,7 @@ void Lookahead::slicetypeDecide()<br></div><div> if (!m_param->rc.bStatRead)<br></div><div> slicetypeAnalyse(frames, false);<br></div><div> bool bIsVbv = m_param->rc.vbvBufferSize > 0 && m_param->rc.vbvMaxBitrate > 0;<br></div><div>- if ((m_param->analysisLoad && m_param->scaleFactor && bIsVbv) || m_param->bliveVBV2pass)<br></div><div>+ if ((strlen(m_param->analysisLoad) && m_param->scaleFactor && bIsVbv) || m_param->bliveVBV2pass)<br></div><div> {<br></div><div> int numFrames;<br></div><div> for (numFrames = 0; numFrames < maxSearch; numFrames++)<br></div><div>@@ -1923,7 +1923,7 @@ void Lookahead::slicetypeDecide()<br></div><div> }<br></div><div> <br></div><div> int bframes, brefs;<br></div><div>- if (!m_param->analysisLoad || m_param->bAnalysisType == HEVC_INFO)<br></div><div>+ if (!strlen(m_param->analysisLoad) || m_param->bAnalysisType == HEVC_INFO)<br></div><div> {<br></div><div> bool isClosedGopRadl = m_param->radl && (m_param->keyframeMax != m_param->keyframeMin);<br></div><div> for (bframes = 0, brefs = 0;; bframes++)<br></div><div>@@ -2340,7 +2340,7 @@ void Lookahead::slicetypeDecide()<br></div><div> if (!m_param->rc.bStatRead)<br></div><div> slicetypeAnalyse(frames, true);<br></div><div> bool bIsVbv = m_param->rc.vbvBufferSize > 0 && m_param->rc.vbvMaxBitrate > 0;<br></div><div>- if ((m_param->analysisLoad && m_param->scaleFactor && bIsVbv) || m_param->bliveVBV2pass)<br></div><div>+ if ((strlen(m_param->analysisLoad) && m_param->scaleFactor && bIsVbv) || m_param->bliveVBV2pass)<br></div><div> {<br></div><div> int numFrames;<br></div><div> for (numFrames = 0; numFrames < maxSearch; numFrames++)<br></div><div>@@ -2485,7 +2485,7 @@ void Lookahead::slicetypeDecide()<br></div><div> if (!m_param->rc.bStatRead)<br></div><div> slicetypeAnalyse(frames, true);<br></div><div> bool bIsVbv = m_param->rc.vbvBufferSize > 0 && m_param->rc.vbvMaxBitrate > 0;<br></div><div>- if ((m_param->analysisLoad && m_param->scaleFactor && bIsVbv) || m_param->bliveVBV2pass)<br></div><div>+ if ((strlen(m_param->analysisLoad) && m_param->scaleFactor && bIsVbv) || m_param->bliveVBV2pass)<br></div><div> {<br></div><div> int numFrames;<br></div><div> for (numFrames = 0; numFrames < maxSearch; numFrames++)<br></div><div>diff --git a/source/x265.cpp b/source/x265.cpp<br></div><div>index c9d2513e2..f392d27bf 100644<br></div><div>--- a/source/x265.cpp<br></div><div>+++ b/source/x265.cpp<br></div><div>@@ -154,6 +154,9 @@ static bool parseAbrConfig(FILE* abrConfig, CLIOptions cliopt[], uint8_t numEnco<br></div><div> char line[1024];<br></div><div> char* argLine;<br></div><div> <br></div><div>+ char **argv = (char**)alloca(256 * sizeof(char *));<br></div><div>+ char *strPool = (char*)alloca(256 * X265_MAX_STRING_SIZE * sizeof(char));<br></div><div>+ int strPoolSize = 256 * X265_MAX_STRING_SIZE;<br></div><div> for (uint32_t i = 0; i < numEncodes; i++)<br></div><div> {<br></div><div> if (fgets(line, sizeof(line), abrConfig) == NULL) {<br></div><div>@@ -168,7 +171,6 @@ static bool parseAbrConfig(FILE* abrConfig, CLIOptions cliopt[], uint8_t numEnco<br></div><div> char* start = strchr(argLine, ' ');<br></div><div> while (isspace((unsigned char)*start)) start++;<br></div><div> int argc = 0;<br></div><div>- char **argv = (char**)malloc(256 * sizeof(char *));<br></div><div> // Adding a dummy string to avoid file parsing error<br></div><div> argv[argc++] = (char *)"x265";<br></div><div> <br></div><div>@@ -193,15 +195,18 @@ static bool parseAbrConfig(FILE* abrConfig, CLIOptions cliopt[], uint8_t numEnco<br></div><div> }<br></div><div> else<br></div><div> {<br></div><div>- cliopt[i].encName = strdup(head[0]);<br></div><div>+ snprintf(cliopt[i].encName, X265_MAX_STRING_SIZE, "%s", head[0]);<br></div><div> cliopt[i].loadLevel = atoi(head[1]);<br></div><div>- cliopt[i].reuseName = strdup(head[2]);<br></div><div>+ snprintf(cliopt[i].reuseName, X265_MAX_STRING_SIZE, "%s", head[2]);<br></div><div> }<br></div><div> <br></div><div> char* token = strtok(start, " ");<br></div><div> while (token)<br></div><div> {<br></div><div>- argv[argc++] = strdup(token);<br></div><div>+ argv[argc++] = strPool;<br></div><div>+ strPool += strlen(token);<br></div><div>+ strPoolSize -= strlen(token);<br></div><div>+ strcpy(argv[argc++], token);<br></div><div> token = strtok(NULL, " ");<br></div><div> }<br></div><div> argv[argc] = NULL;<br></div><div>@@ -213,6 +218,7 @@ static bool parseAbrConfig(FILE* abrConfig, CLIOptions cliopt[], uint8_t numEnco<br></div><div> exit(1);<br></div><div> }<br></div><div> }<br></div><div>+ X265_CHECK(strPoolSize >= 0, "string pool broken!");<br></div><div> return true;<br></div><div> }<br></div><div> <br></div><div>@@ -319,11 +325,11 @@ int main(int argc, char **argv)<br></div><div> if (abrEnc->m_passEnc[idx]->m_ret)<br></div><div> {<br></div><div> if (isAbrLadder)<br></div><div>- x265_log(NULL, X265_LOG_INFO, "Error generating ABR-ladder \n");<br></div><div>- ret = abrEnc->m_passEnc[idx]->m_ret;<br></div><div>- threadsActive = 0;<br></div><div>- break;<br></div><div>- }<br></div><div>+ x265_log(NULL, X265_LOG_INFO, "Error generating ABR-ladder \n");<br></div><div>+ ret = abrEnc->m_passEnc[idx]->m_ret;<br></div><div>+ threadsActive = 0;<br></div><div>+ break;<br></div><div>+ }<br></div><div> }<br></div><div> }<br></div><div> <br></div><div>diff --git a/source/x265.h b/source/x265.h<br></div><div>index 13c4a47e2..671e196f6 100644<br></div><div>--- a/source/x265.h<br></div><div>+++ b/source/x265.h<br></div><div>@@ -36,6 +36,8 @@ extern "C" {<br></div><div> #pragma warning(disable: 4201) // non-standard extension used (nameless struct/union)<br></div><div> #endif<br></div><div> <br></div><div>+#define X265_MAX_STRING_SIZE (256)<br></div><div>+<br></div><div> /* x265_encoder:<br></div><div> * opaque handler for encoder */<br></div><div> typedef struct x265_encoder x265_encoder;<br></div><div>@@ -1141,7 +1143,7 @@ typedef struct x265_param<br></div><div> *<br></div><div> * Frame encoders are distributed between the available thread pools, and<br></div><div> * the encoder will never generate more thread pools than frameNumThreads */<br></div><div>- const char* numaPools;<br></div><div>+ char numaPools[X265_MAX_STRING_SIZE];<br></div><div> <br></div><div> /* Enable wavefront parallel processing, greatly increases parallelism for<br></div><div> * less than 1% compression efficiency loss. Requires a thread pool, enabled<br></div><div>@@ -1185,7 +1187,7 @@ typedef struct x265_param<br></div><div> * per-slice statistics to this log file in encode order. Otherwise the<br></div><div> * encoder will emit per-stream statistics into the log file when<br></div><div> * x265_encoder_log is called (presumably at the end of the encode) */<br></div><div>- const char* csvfn;<br></div><div>+ char csvfn[X265_MAX_STRING_SIZE];<br></div><div> <br></div><div> /*== Internal Picture Specification ==*/<br></div><div> <br></div><div>@@ -1465,7 +1467,7 @@ typedef struct x265_param<br></div><div> * - all other strings indicate a filename containing custom scaling lists<br></div><div> * in the HM format. The encode will fail if the file is not parsed<br></div><div> * correctly. Custom lists must be signaled in the SPS. */<br></div><div>- const char *scalingLists;<br></div><div>+ char scalingLists[X265_MAX_STRING_SIZE];<br></div><div> <br></div><div> /*== Intra Coding Tools ==*/<br></div><div> <br></div><div>@@ -1650,7 +1652,7 @@ typedef struct x265_param<br></div><div> int analysisReuseMode;<br></div><div> <br></div><div> /* Filename for multi-pass-opt-analysis/distortion. Default name is "x265_analysis.dat" */<br></div><div>- const char* analysisReuseFileName;<br></div><div>+ char analysisReuseFileName[X265_MAX_STRING_SIZE];<br></div><div> <br></div><div> /*== Rate Control ==*/<br></div><div> <br></div><div>@@ -1767,7 +1769,7 @@ typedef struct x265_param<br></div><div> <br></div><div> /* Filename of the 2pass output/input stats file, if unspecified the<br></div><div> * encoder will default to using x265_2pass.log */<br></div><div>- const char* statFileName;<br></div><div>+ char statFileName[X265_MAX_STRING_SIZE];<br></div><div> <br></div><div> /* temporally blur quants */<br></div><div> double qblur;<br></div><div>@@ -1791,7 +1793,7 @@ typedef struct x265_param<br></div><div> * are separated by comma, space or newline. Text after a hash (#) is<br></div><div> * ignored. The lambda tables are process-global, so these new lambda<br></div><div> * values will affect all encoders in the same process */<br></div><div>- const char* lambdaFileName;<br></div><div>+ char lambdaFileName[X265_MAX_STRING_SIZE];<br></div><div> <br></div><div> /* Enable stricter conditions to check bitrate deviations in CBR mode. May compromise<br></div><div> * quality to maintain bitrate adherence */<br></div><div>@@ -1828,7 +1830,7 @@ typedef struct x265_param<br></div><div> int dataShareMode;<br></div><div> <br></div><div> /* Unique shared memory name. Required if the shared memory mode enabled. NULL by default */<br></div><div>- const char* sharedMemName;<br></div><div>+ char sharedMemName[X265_MAX_STRING_SIZE];<br></div><div> <br></div><div> } rc;<br></div><div> <br></div><div>@@ -1933,7 +1935,7 @@ typedef struct x265_param<br></div><div> * are unsigned 16bit integers and %u are unsigned 32bit integers. The SEI<br></div><div> * includes X,Y display primaries for RGB channels, white point X,Y and<br></div><div> * max,min luminance values. */<br></div><div>- const char* masteringDisplayColorVolume;<br></div><div>+ char masteringDisplayColorVolume[X265_MAX_STRING_SIZE];<br></div><div> <br></div><div> /* Maximum Content light level(MaxCLL), specified as integer that indicates the<br></div><div> * maximum pixel intensity level in units of 1 candela per square metre of the<br></div><div>@@ -2022,7 +2024,7 @@ typedef struct x265_param<br></div><div> int bLimitSAO;<br></div><div> <br></div><div> /* File containing the tone mapping information */<br></div><div>- const char* toneMapFile;<br></div><div>+ char toneMapFile[X265_MAX_STRING_SIZE];<br></div><div> <br></div><div> /* Insert tone mapping information only for IDR frames and when the <br></div><div> * tone mapping information changes. */<br></div><div>@@ -2098,11 +2100,11 @@ typedef struct x265_param<br></div><div> int gopLookahead;<br></div><div> <br></div><div> /*Write per-frame analysis information into analysis buffers. Default disabled. */<br></div><div>- const char* analysisSave;<br></div><div>+ char analysisSave[X265_MAX_STRING_SIZE];<br></div><div> <br></div><div> /* Read analysis information into analysis buffer and use this analysis information<br></div><div> * to reduce the amount of work the encoder must perform. Default disabled. */<br></div><div>- const char* analysisLoad;<br></div><div>+ char analysisLoad[X265_MAX_STRING_SIZE];<br></div><div> <br></div><div> /*Number of RADL pictures allowed in front of IDR*/<br></div><div> int radl;<br></div><div>@@ -2134,7 +2136,7 @@ typedef struct x265_param<br></div><div> * Default 0 (disabled). */<br></div><div> int chunkEnd;<br></div><div> /* File containing base64 encoded SEI messages in POC order */<br></div><div>- const char* naluFile;<br></div><div>+ char naluFile[X265_MAX_STRING_SIZE];<br></div><div> <br></div><div> /* Generate bitstreams confirming to the specified dolby vision profile,<br></div><div> * note that 0x7C01 makes RPU appear to be an unspecified NAL type in<br></div><div>@@ -2295,7 +2297,7 @@ typedef struct x265_param<br></div><div> * precedence than individual VUI parameters. If any individual VUI option is specified<br></div><div> * together with this, which changes the values set corresponding to the system-id<br></div><div> * or color-volume, it will be discarded. */<br></div><div>- const char* videoSignalTypePreset;<br></div><div>+ char videoSignalTypePreset[X265_MAX_STRING_SIZE];<br></div><div> <br></div><div> /* Flag indicating whether the encoder should emit an End of Bitstream<br></div><div> * NAL at the end of bitstream. Default false */<br></div><div>diff --git a/source/x265cli.cpp b/source/x265cli.cpp<br></div><div>index 12df761cc..fd82ebd22 100755<br></div><div>--- a/source/x265cli.cpp<br></div><div>+++ b/source/x265cli.cpp<br></div><div>@@ -555,7 +555,6 @@ namespace X265_NS {<br></div><div> showHelp(globalParam);<br></div><div> }<br></div><div> <br></div><div>- globalParam->rc.zones[zonefileCount].zoneParam = api->param_alloc();<br></div><div> if (!globalParam->rc.zones[zonefileCount].zoneParam)<br></div><div> {<br></div><div> x265_log(NULL, X265_LOG_ERROR, "param alloc failed\n");<br></div><div>@@ -1131,6 +1130,7 @@ namespace X265_NS {<br></div><div> }<br></div><div> <br></div><div> rewind(zoneFile);<br></div><div>+ char **args = (char**)alloca(256 * sizeof(char *));<br></div><div> param->rc.zones = X265_MALLOC(x265_zone, param->rc.zonefileCount);<br></div><div> for (int i = 0; i < param->rc.zonefileCount; i++)<br></div><div> {<br></div><div>@@ -1148,7 +1148,6 @@ namespace X265_NS {<br></div><div> start++;<br></div><div> param->rc.zones[i].startFrame = atoi(argLine);<br></div><div> int argCount = 0;<br></div><div>- char **args = (char**)malloc(256 * sizeof(char *));<br></div><div> // Adding a dummy string to avoid file parsing error<br></div><div> args[argCount++] = (char *)"x265";<br></div><div> char* token = strtok(start, " ");<br></div><div>@@ -1354,6 +1353,7 @@ namespace X265_NS {<br></div><div> rewind(multiViewConfig);<br></div><div> int linenum = 0;<br></div><div> int numInput = 0;<br></div><div>+ char** args = (char**)malloc(256 * sizeof(char*));<br></div><div> while (fgets(line, sizeof(line), multiViewConfig))<br></div><div> {<br></div><div> if (*line == '#' || (strcmp(line, "\r\n") == 0))<br></div><div>@@ -1365,7 +1365,6 @@ namespace X265_NS {<br></div><div> char* start = strchr(argLine, '-');<br></div><div> int argCount = 0;<br></div><div> char flag[] = "true";<br></div><div>- char** args = (char**)malloc(256 * sizeof(char*));<br></div><div> //Adding a dummy string to avoid file parsing error<br></div><div> args[argCount++] = (char*)"x265";<br></div><div> char* token = strtok(start, " ");<br></div><div>@@ -1467,10 +1466,12 @@ namespace X265_NS {<br></div><div> {<br></div><div> if (api)<br></div><div> api->param_free(param);<br></div><div>+ free(args);<br></div><div> exit(1);<br></div><div> }<br></div><div> linenum++;<br></div><div> }<br></div><div>+ free(args);<br></div><div> if (numInput != (param->format ? 1 : param->numViews))<br></div><div> {<br></div><div> x265_log(NULL, X265_LOG_WARNING, "Number of Input files does not match with the given format <%d>\n", param->format);<br></div><div>diff --git a/source/x265cli.h b/source/x265cli.h<br></div><div>index 3df0fa7a6..aaa385cb4 100644<br></div><div>--- a/source/x265cli.h<br></div><div>+++ b/source/x265cli.h<br></div><div>@@ -434,8 +434,8 @@ static const struct option long_options[] =<br></div><div> /* ABR ladder settings */<br></div><div> bool isAbrLadderConfig;<br></div><div> bool enableScaler;<br></div><div>- char* encName;<br></div><div>- char* reuseName;<br></div><div>+ char encName[X265_MAX_STRING_SIZE];<br></div><div>+ char reuseName[X265_MAX_STRING_SIZE];<br></div><div> uint32_t encId;<br></div><div> int refId;<br></div><div> uint32_t loadLevel;<br></div><div>@@ -471,8 +471,8 @@ static const struct option long_options[] =<br></div><div> bDither = false;<br></div><div> isAbrLadderConfig = false;<br></div><div> enableScaler = false;<br></div><div>- encName = NULL;<br></div><div>- reuseName = NULL;<br></div><div>+ encName[0] = 0;<br></div><div>+ reuseName[0] = 0;<br></div><div> encId = 0;<br></div><div> refId = -1;<br></div><div> loadLevel = 0;<br></div><div>-- <br></div><div>2.41.0.windows.1<br></div></div></div><div>_______________________________________________<br></div><div>x265-devel mailing list<br></div><div><a href="mailto:x265-devel@videolan.org">x265-devel@videolan.org</a><br></div><div><a href="https://mailman.videolan.org/listinfo/x265-devel">https://mailman.videolan.org/listinfo/x265-devel</a><br></div><div><br></div><div><br></div><div><b>Attachments:</b><br></div><ul><li>0002-Memory-Leak-Fix-Part2.patch<br></li></ul></blockquote><div><br></div><div id="sig60240713"><div class="signature">-- </div><div class="signature">Jean-Baptiste Kempf - President</div><div class="signature">+33 672 704 734</div><div class="signature"><a href="https://jbkempf.com/">https://jbkempf.com/</a></div><div class="signature"><br></div></div><div><br></div></body></html>