[x265] [PATCH] encoder: Do not use X265_MALLOC use CHECKED_MALLOC

Gopu Govindaswamy gopu at multicorewareinc.com
Fri Sep 20 09:14:15 CEST 2013


# HG changeset patch
# User Gopu Govindaswamy <gopu at multicorewareinc.com>
# Date 1379661247 -19800
# Node ID 3692f665008c8ce96a97872b92bb83aa34ef1049
# Parent  03195b8c3267dee542fe12886617902b7333a202
encoder: Do not use X265_MALLOC use CHECKED_MALLOC

Currently X265_MALLOC did't validate the returned pointer, CHECKED_MALLOC Always
validate the returned pointer and print the Log message and jumps to fail lable
if returned pointer is not valid,

diff -r 03195b8c3267 -r 3692f665008c source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp	Fri Sep 20 12:15:09 2013 +0530
+++ b/source/encoder/encoder.cpp	Fri Sep 20 12:44:07 2013 +0530
@@ -47,7 +47,7 @@
 
     void configure(x265_param_t *param);
     void determineLevelAndProfile(x265_param_t *param);
-    void extract_naldata(AccessUnit &au, size_t &nalcount);
+    int extract_naldata(AccessUnit &au, size_t &nalcount);
 };
 
 x265_t::x265_t()
@@ -364,11 +364,13 @@
     if (encoder->getStreamHeaders(au) == 0)
     {
         size_t nalcount;
-        encoder->extract_naldata( au, nalcount);
-
-        *pp_nal = &encoder->m_nals[0];
-        if (pi_nal) *pi_nal = (int)nalcount;
-        return 0;
+        if (encoder->extract_naldata( au, nalcount) == 0)
+        {
+            *pp_nal = &encoder->m_nals[0];
+            if (pi_nal) *pi_nal = (int)nalcount;
+            return 0;
+        }
+        return -1;
     }
     else
         return -1;
@@ -417,7 +419,7 @@
     BitCost::destroy();
 }
 
-void x265_t::extract_naldata( AccessUnit &au, size_t &nalcount)
+int x265_t::extract_naldata( AccessUnit &au, size_t &nalcount)
 {
         UInt memsize = 0;
         nalcount = 0;
@@ -434,8 +436,8 @@
         if (m_nals)
             X265_FREE(m_nals);
 
-        m_packetData = (char*)X265_MALLOC(char, memsize);
-        m_nals = (x265_nal_t*)X265_MALLOC(x265_nal_t, nalcount);
+        CHECKED_MALLOC(m_packetData, char, memsize);
+        CHECKED_MALLOC(m_nals, x265_nal_t, nalcount);
         nalcount = 0;
         memsize = 0;
 
@@ -483,4 +485,8 @@
             m_nals[i].p_payload = (uint8_t*)m_packetData + offset;
             offset += m_nals[i].i_payload;
         }
+
+        return 0;
+fail:
+        return -1;
 }


More information about the x265-devel mailing list