[x265] [PATCH] common: add CHECKED_MALLOC macro that logs malloc failures and jumps to fail label

Gopu Govindaswamy gopu at multicorewareinc.com
Fri Sep 20 08:46:04 CEST 2013


# HG changeset patch
# User Gopu Govindaswamy <gopu at multicorewareinc.com>
# Date 1379659509 -19800
# Node ID 03195b8c3267dee542fe12886617902b7333a202
# Parent  20d8fa0541d8cf77d52106c08022ae97f3ff5de8
common: add CHECKED_MALLOC macro that logs malloc failures and jumps to fail label

diff -r 20d8fa0541d8 -r 03195b8c3267 source/common/common.cpp
--- a/source/common/common.cpp	Thu Sep 19 22:26:46 2013 -0500
+++ b/source/common/common.cpp	Fri Sep 20 12:15:09 2013 +0530
@@ -86,7 +86,7 @@
 
 void x265_log(x265_param_t *param, int level, const char *fmt, ...)
 {
-    if (level > param->logLevel)
+    if (param && level > param->logLevel)
         return;
     const char *log_level;
     switch (level)
diff -r 20d8fa0541d8 -r 03195b8c3267 source/common/common.h
--- a/source/common/common.h	Thu Sep 19 22:26:46 2013 -0500
+++ b/source/common/common.h	Fri Sep 20 12:15:09 2013 +0530
@@ -96,6 +96,16 @@
 #define X265_MAX4(a, b, c, d) X265_MAX((a), X265_MAX3((b), (c), (d)))
 #define QP_BD_OFFSET (6*(X265_DEPTH-8))
 
+#define CHECKED_MALLOC(var, type, count )\
+{\
+    var = (type *)X265_MALLOC(type, sizeof(type) * (count));\
+    if (!var)\
+    {\
+        x265_log(NULL, X265_LOG_ERROR, "malloc of size %d failed\n", sizeof(type) * (count));\
+        goto fail;\
+    }\
+}
+
 #define ENABLE_CYCLE_COUNTERS 0
 #if ENABLE_CYCLE_COUNTERS
 #include <intrin.h>


More information about the x265-devel mailing list