]> git.sesse.net Git - ffmpeg/commitdiff
libavfilter/dnn_backend_native: check mem allocation
authorChris Miceli <chris@miceli.net.au>
Wed, 14 Oct 2020 00:19:50 +0000 (11:19 +1100)
committerGuo, Yejun <yejun.guo@intel.com>
Wed, 14 Oct 2020 02:19:05 +0000 (10:19 +0800)
check that frame allocations return non-null.

libavfilter/dnn/dnn_backend_native.c

index d45e211f0c8ac984aa42b14c80f59ae4f48079ba..4fc3ba2044b5fdc02ed5e44dc52bfa0b6b4b2a00 100644 (file)
@@ -79,8 +79,23 @@ static DNNReturnType get_output_native(void *model, const char *input_name, int
 {
     DNNReturnType ret;
     NativeModel *native_model = (NativeModel *)model;
+    NativeContext *ctx = &native_model->ctx;
     AVFrame *in_frame = av_frame_alloc();
-    AVFrame *out_frame = av_frame_alloc();
+    AVFrame *out_frame = NULL;
+
+    if (!in_frame) {
+        av_log(ctx, AV_LOG_ERROR, "Could not allocate memory for input frame\n");
+        return DNN_ERROR;
+    }
+
+    out_frame = av_frame_alloc();
+
+    if (!out_frame) {
+        av_log(ctx, AV_LOG_ERROR, "Could not allocate memory for output frame\n");
+        av_frame_free(&in_frame);
+        return DNN_ERROR;
+    }
+
     in_frame->width = input_width;
     in_frame->height = input_height;