[x265] [PATCH] tcommotion: use Checked malloc to allocate memory

gopu at multicorewareinc.com gopu at multicorewareinc.com
Mon Mar 10 12:25:40 CET 2014


# HG changeset patch
# User Gopu Govindaswamy
# Date 1394450728 -19800
#      Mon Mar 10 16:55:28 2014 +0530
# Node ID 7c93b0f2bd16d1b25526f2b59d5e35f9f9ce5399
# Parent  592b9b952a71f11b778fb4f8afadf86ff9c9a05c
tcommotion: use Checked malloc to allocate memory

diff -r 592b9b952a71 -r 7c93b0f2bd16 source/Lib/TLibCommon/TComDataCU.cpp
--- a/source/Lib/TLibCommon/TComDataCU.cpp	Mon Mar 10 14:04:38 2014 +0530
+++ b/source/Lib/TLibCommon/TComDataCU.cpp	Mon Mar 10 16:55:28 2014 +0530
@@ -120,8 +120,9 @@
     tmp = g_convertToBit[tmp] + 2;
     m_unitMask = ~((1 << tmp) - 1);
 
-    m_cuMvField[0].create(numPartition);
-    m_cuMvField[1].create(numPartition);
+    bool ok = true;
+    ok &= m_cuMvField[0].create(numPartition);
+    ok &= m_cuMvField[1].create(numPartition);
 
     CHECKED_MALLOC(m_qp, char,  numPartition);
     CHECKED_MALLOC(m_depth, UChar, numPartition);
@@ -159,10 +160,11 @@
     CHECKED_MALLOC(m_pattern, TComPattern, 1);
 
     memset(m_partSizes, SIZE_NONE, numPartition * sizeof(*m_partSizes));
-    return m_pattern;
+    return ok;
 
 fail:
-    return false;
+    ok = false;
+    return ok;
 }
 
 void TComDataCU::destroy()
diff -r 592b9b952a71 -r 7c93b0f2bd16 source/Lib/TLibCommon/TComMotionInfo.cpp
--- a/source/Lib/TLibCommon/TComMotionInfo.cpp	Mon Mar 10 14:04:38 2014 +0530
+++ b/source/Lib/TLibCommon/TComMotionInfo.cpp	Mon Mar 10 16:55:28 2014 +0530
@@ -51,28 +51,24 @@
 // Create / destroy
 // --------------------------------------------------------------------------------------------------------------------
 
-void TComCUMvField::create(uint32_t numPartition)
+bool TComCUMvField::create(uint32_t numPartition)
 {
-    assert(m_mv     == NULL);
-    assert(m_mvd    == NULL);
-    assert(m_refIdx == NULL);
-
-    m_mv     = new MV[numPartition];
-    m_mvd    = new MV[numPartition];
-    m_refIdx = new char[numPartition];
+    CHECKED_MALLOC(m_mv, MV, numPartition);
+    CHECKED_MALLOC(m_mvd, MV, numPartition);
+    CHECKED_MALLOC(m_refIdx, char, numPartition);
 
     m_numPartitions = numPartition;
+
+    return true;
+fail:
+    return false;
 }
 
 void TComCUMvField::destroy()
 {
-    assert(m_mv     != NULL);
-    assert(m_mvd    != NULL);
-    assert(m_refIdx != NULL);
-
-    delete[] m_mv;
-    delete[] m_mvd;
-    delete[] m_refIdx;
+    X265_FREE(m_mv);
+    X265_FREE(m_mvd);
+    X265_FREE(m_refIdx);
 
     m_mv     = NULL;
     m_mvd    = NULL;
diff -r 592b9b952a71 -r 7c93b0f2bd16 source/Lib/TLibCommon/TComMotionInfo.h
--- a/source/Lib/TLibCommon/TComMotionInfo.h	Mon Mar 10 14:04:38 2014 +0530
+++ b/source/Lib/TLibCommon/TComMotionInfo.h	Mon Mar 10 16:55:28 2014 +0530
@@ -102,7 +102,7 @@
     // create / destroy
     // ------------------------------------------------------------------------------------------------------------------
 
-    void create(uint32_t numPartition);
+    bool create(uint32_t numPartition);
     void destroy();
 
     // ------------------------------------------------------------------------------------------------------------------


More information about the x265-devel mailing list