[FFmpeg-devel] [PATCH v2 08/10] vtenc: better allocation failure checking.

kernrj at gmail.com kernrj at gmail.com
Wed Nov 18 19:49:56 CET 2015


From: Rick Kern <kernrj at gmail.com>

Some memory allocations were unchecked.

Signed-off-by: Rick Kern <kernrj at gmail.com>
---
 libavcodec/vtenc.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/libavcodec/vtenc.c b/libavcodec/vtenc.c
index f0d8289..583244c 100644
--- a/libavcodec/vtenc.c
+++ b/libavcodec/vtenc.c
@@ -118,17 +118,20 @@ static int vtenc_q_pop(VTEncContext* vtctx, bool wait, CMSampleBufferRef* buf){
 
     pthread_mutex_unlock(&vtctx->lock);
 
-    CMSampleBufferRef buffer = info->cm_buffer;
+    *buf = info->cm_buffer;
     free(info);
 
     vtctx->frame_ct_out++;
-    *buf = buffer;
 
     return 0;
 }
 
 static void vtenc_q_push(VTEncContext* vtctx, CMSampleBufferRef buffer){
     BufNode* info = (BufNode*)malloc(sizeof(BufNode));
+    if(!info){
+        set_async_error(vtctx, AVERROR(ENOMEM));
+        return;
+    }
 
     CFRetain(buffer);
     info->cm_buffer = buffer;
@@ -499,6 +502,8 @@ static av_cold int vtenc_init(AVCodecContext* avctx){
         &kCFTypeDictionaryValueCallBacks
     );
 
+    if(!enc_info) return AVERROR(ENOMEM);
+
 #if !TARGET_OS_IPHONE
     CFDictionarySetValue(enc_info, kVTVideoEncoderSpecification_RequireHardwareAcceleratedVideoEncoder, kCFBooleanTrue);
     CFDictionarySetValue(enc_info, kVTVideoEncoderSpecification_EnableHardwareAcceleratedVideoEncoder, kCFBooleanTrue);
@@ -543,6 +548,8 @@ static av_cold int vtenc_init(AVCodecContext* avctx){
 
     SInt32 bit_rate = avctx->bit_rate;
     CFNumberRef bit_rate_num = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &bit_rate);
+    if(!bit_rate_num) return AVERROR(ENOMEM);
+
     status = VTSessionSetProperty(vtctx->session, kVTCompressionPropertyKey_AverageBitRate, bit_rate_num);
     CFRelease(bit_rate_num);
 
-- 
2.4.9 (Apple Git-60)



More information about the ffmpeg-devel mailing list