<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jul 24, 2017 at 11:08 AM,  <span dir="ltr"><<a href="mailto:bhavna@multicorewareinc.com" target="_blank">bhavna@multicorewareinc.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"># HG changeset patch<br>
# User Bhavna Hariharan <<a href="mailto:bhavna@multicorewareinc.com">bhavna@multicorewareinc.com</a>><br>
# Date 1500874610 -19800<br>
#      Mon Jul 24 11:06:50 2017 +0530<br>
# Branch stable<br>
# Node ID c28a95a9ebbf5bf6bb5c9a357fc11e<wbr>3c3bdea35c<br>
# Parent  bce945545c241ce4bb87d56d283ac8<wbr>226d862ed5<br>
Fix memory leak in hdr10plus<br></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
Rename numCimInfo and cim to m_numCimInfo and m_cim respectively.<br>
<br>
Fixes memory leaks cause due to incorrect handling of m_cim and m_userSEI<br>
memory allocation.<br>
<br>
Handle crash when empty json file is parsed.<br></blockquote><div><br></div><div>Pushed on appropriate parent in stable branch and merged with latest stable and default tips.</div><div>  </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
diff -r bce945545c24 -r c28a95a9ebbf source/dynamicHDR10/<wbr>JsonHelper.cpp<br>
--- a/source/dynamicHDR10/<wbr>JsonHelper.cpp        Wed Jun 07 16:29:15 2017 +0530<br>
+++ b/source/dynamicHDR10/<wbr>JsonHelper.cpp        Mon Jul 24 11:06:50 2017 +0530<br>
@@ -188,9 +188,15 @@<br>
<br>
     tfile.close();<br>
<br>
-    size_t beginning = json_str2.find_first_of("[");<br>
-    int fixchar = json_str2[json_str2.size() - 2] == ']' ? 1 : 0;<br>
-    return Json::parse(json_str2.substr(<wbr>beginning,json_str2.size() - fixchar),err).array_items();<br>
+    vector<Json> data;<br>
+    if (json_str2.size() != 0)<br>
+    {<br>
+        size_t beginning = json_str2.find_first_of("[");<br>
+        int fixchar = json_str2[json_str2.size() - 2] == ']' ? 1 : 0;<br>
+        return Json::parse(json_str2.substr(<wbr>beginning, json_str2.size() - fixchar), err).array_items();<br>
+    }<br>
+    else<br>
+        return data;<br>
 }<br>
<br>
 bool JsonHelper::<wbr>validatePathExtension(string &path)<br>
diff -r bce945545c24 -r c28a95a9ebbf source/encoder/encoder.cpp<br>
--- a/source/encoder/encoder.cpp        Wed Jun 07 16:29:15 2017 +0530<br>
+++ b/source/encoder/encoder.cpp        Mon Jul 24 11:06:50 2017 +0530<br>
@@ -88,8 +88,8 @@<br>
<br>
 #if ENABLE_DYNAMIC_HDR10<br>
     m_hdr10plus_api = hdr10plus_api_get();<br>
-    numCimInfo = 0;<br>
-    cim = NULL;<br>
+    m_numCimInfo = 0;<br>
+    m_cim = NULL;<br>
 #endif<br>
<br>
     m_prevTonemapPayload.payload = NULL;<br>
@@ -403,6 +403,11 @@<br>
     m_nalList.m_annexB = !!m_param->bAnnexB;<br>
<br>
     m_emitCLLSEI = p->maxCLL || p->maxFALL;<br>
+<br>
+#if ENABLE_DYNAMIC_HDR10<br>
+    if (m_bToneMap)<br>
+        m_numCimInfo = m_hdr10plus_api->hdr10plus_<wbr>json_to_movie_cim(m_param-><wbr>toneMapFile, m_cim);<br>
+#endif<br>
 }<br>
<br>
 void Encoder::stopJobs()<br>
@@ -434,7 +439,8 @@<br>
 void Encoder::destroy()<br>
 {<br>
 #if ENABLE_DYNAMIC_HDR10<br>
-    m_hdr10plus_api->hdr10plus_<wbr>clear_movie(cim, numCimInfo);<br>
+    if (m_bToneMap)<br>
+        m_hdr10plus_api->hdr10plus_<wbr>clear_movie(m_cim, m_numCimInfo);<br>
 #endif<br>
<br>
     if (m_exportedPic)<br>
@@ -610,19 +616,18 @@<br>
 #if ENABLE_DYNAMIC_HDR10<br>
         if (m_bToneMap)<br>
         {<br>
-            if (pic_in->poc == 0)<br>
-                numCimInfo = m_hdr10plus_api->hdr10plus_<wbr>json_to_movie_cim(m_param-><wbr>toneMapFile, cim);<br>
-            if (pic_in->poc < numCimInfo)<br>
+            int currentPOC = m_pocLast + 1;<br>
+            if (currentPOC < m_numCimInfo)<br>
             {<br>
                 int32_t i = 0;<br>
                 toneMap.payloadSize = 0;<br>
-                while (cim[pic_in->poc][i] == 0xFF)<br>
-                    toneMap.payloadSize += cim[pic_in->poc][i++] + 1;<br>
-                toneMap.payloadSize += cim[pic_in->poc][i] + 1;<br>
+                while (m_cim[currentPOC][i] == 0xFF)<br>
+                    toneMap.payloadSize += m_cim[currentPOC][i++] + 1;<br>
+                toneMap.payloadSize += m_cim[currentPOC][i] + 1;<br>
<br>
                 toneMap.payload = (uint8_t*)x265_malloc(sizeof(<wbr>uint8_t) * toneMap.payloadSize);<br>
                 toneMap.payloadType = USER_DATA_REGISTERED_ITU_T_<wbr>T35;<br>
-                memcpy(toneMap.payload, cim[pic_in->poc], toneMap.payloadSize);<br>
+                memcpy(toneMap.payload, m_cim[currentPOC], toneMap.payloadSize);<br>
             }<br>
         }<br>
 #endif<br>
@@ -716,7 +721,12 @@<br>
<br>
         if (inFrame->m_userSEI.<wbr>numPayloads)<br>
         {<br>
-            inFrame->m_userSEI.payloads = new x265_sei_payload[numPayloads];<br>
+            if (!inFrame->m_userSEI.payloads)<br>
+            {<br>
+                inFrame->m_userSEI.payloads = new x265_sei_payload[numPayloads];<br>
+                for (int i = 0; i < numPayloads; i++)<br>
+                    inFrame->m_userSEI.payloads[i]<wbr>.payload = NULL;<br>
+            }<br>
             for (int i = 0; i < numPayloads; i++)<br>
             {<br>
                 x265_sei_payload input;<br>
@@ -726,7 +736,8 @@<br>
                     input = pic_in->userSEI.payloads[i];<br>
                 int size = inFrame->m_userSEI.payloads[i]<wbr>.payloadSize = input.payloadSize;<br>
                 inFrame->m_userSEI.payloads[i]<wbr>.payloadType = input.payloadType;<br>
-                inFrame->m_userSEI.payloads[i]<wbr>.payload = new uint8_t[size];<br>
+                if (!inFrame->m_userSEI.payloads[<wbr>i].payload)<br>
+                    inFrame->m_userSEI.payloads[i]<wbr>.payload = new uint8_t[size];<br>
                 memcpy(inFrame->m_userSEI.<wbr>payloads[i].payload, input.payload, size);<br>
             }<br>
             if (toneMap.payload)<br>
diff -r bce945545c24 -r c28a95a9ebbf source/encoder/encoder.h<br>
--- a/source/encoder/encoder.h  Wed Jun 07 16:29:15 2017 +0530<br>
+++ b/source/encoder/encoder.h  Mon Jul 24 11:06:50 2017 +0530<br>
@@ -178,8 +178,8 @@<br>
<br>
 #ifdef ENABLE_DYNAMIC_HDR10<br>
     const hdr10plus_api     *m_hdr10plus_api;<br>
-    uint8_t                 **cim;<br>
-    int                     numCimInfo;<br>
+    uint8_t                 **m_cim;<br>
+    int                     m_numCimInfo;<br>
 #endif<br>
<br>
     x265_sei_payload        m_prevTonemapPayload;<br>
<br>______________________________<wbr>_________________<br>
x265-devel mailing list<br>
<a href="mailto:x265-devel@videolan.org">x265-devel@videolan.org</a><br>
<a href="https://mailman.videolan.org/listinfo/x265-devel" rel="noreferrer" target="_blank">https://mailman.videolan.org/<wbr>listinfo/x265-devel</a><br>
<br></blockquote></div><br></div></div>