msdk: Fix possible memory leaks
authorMengkejiergeli Ba <mengkejiergeli.ba@intel.com>
Mon, 19 Feb 2024 04:50:53 +0000 (12:50 +0800)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Thu, 22 Feb 2024 11:53:06 +0000 (11:53 +0000)
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6161>

subprojects/gst-plugins-bad/sys/msdk/gstmsdkallocator_libva.c
subprojects/gst-plugins-bad/sys/msdk/gstmsdkvpp.c

index 395097147ca1a94943175cc223f3d95cb3ea189b..eab8001602df0ea70174165ee51d1a314a464c06 100644 (file)
@@ -118,13 +118,16 @@ gst_msdk_frame_alloc (mfxHDL pthis, mfxFrameAllocRequest * req,
 
     pool = gst_msdk_context_get_alloc_pool (context);
     if (!pool) {
+      status = MFX_ERR_MEMORY_ALLOC;
       goto error_alloc;
     }
 
     config = gst_buffer_pool_get_config (GST_BUFFER_POOL_CAST (pool));
     if (!gst_buffer_pool_config_get_params (config, &caps, NULL, &min_buffers,
-            &max_buffers))
+            &max_buffers)) {
+      status = MFX_ERR_MEMORY_ALLOC;
       goto error_alloc;
+    }
 
     max_buffers = MAX (max_buffers, surfaces_num);
     gst_buffer_pool_config_set_params (config, caps,
@@ -138,12 +141,14 @@ gst_msdk_frame_alloc (mfxHDL pthis, mfxFrameAllocRequest * req,
     if (!gst_buffer_pool_set_config (pool, config)) {
       GST_ERROR ("Failed to set pool config");
       gst_object_unref (pool);
+      status = MFX_ERR_MEMORY_ALLOC;
       goto error_alloc;
     }
 
     if (!gst_buffer_pool_set_active (pool, TRUE)) {
       GST_ERROR ("Failed to activate pool");
       gst_object_unref (pool);
+      status = MFX_ERR_MEMORY_ALLOC;
       goto error_alloc;
     }
 
@@ -154,6 +159,7 @@ gst_msdk_frame_alloc (mfxHDL pthis, mfxFrameAllocRequest * req,
         GST_ERROR ("Failed to allocate buffer");
         gst_buffer_pool_set_active (pool, FALSE);
         gst_object_unref (pool);
+        status = MFX_ERR_MEMORY_ALLOC;
         goto error_alloc;
       }
 
@@ -163,6 +169,7 @@ gst_msdk_frame_alloc (mfxHDL pthis, mfxFrameAllocRequest * req,
         GST_ERROR ("Failed to get GstMsdkSurface");
         gst_buffer_pool_set_active (pool, FALSE);
         gst_object_unref (pool);
+        status = MFX_ERR_MEMORY_ALLOC;
         goto error_alloc;
       }
 
@@ -192,7 +199,7 @@ gst_msdk_frame_alloc (mfxHDL pthis, mfxFrameAllocRequest * req,
       status = gst_msdk_get_mfx_status_from_va_status (va_status);
       if (status < MFX_ERR_NONE) {
         GST_ERROR ("failed to create buffer");
-        return status;
+        goto error_alloc;
       }
 
       msdk_mid.surface = coded_buf;
@@ -224,7 +231,7 @@ error_alloc:
   g_slice_free (GstMsdkAllocResponse, msdk_resp);
   if (tmp_list)
     g_list_free_full (tmp_list, (GDestroyNotify) gst_msdk_surface_list_free);
-  return MFX_ERR_MEMORY_ALLOC;
+  return status;
 }
 
 mfxStatus
index edb3173b2300b87514b15d5316a1251fbf2d600d..be97f07ced2ce38c9d493cc4c16b26eb0caa63d4 100644 (file)
@@ -865,12 +865,13 @@ gst_msdkvpp_transform (GstBaseTransform * trans, GstBuffer * inbuf,
     in_surface->surface->Data.TimeStamp =
         gst_util_uint64_scale_round (inbuf->pts, 90000, GST_SECOND);
 
-  out_surface = gst_msdk_import_to_msdk_surface (outbuf, thiz->context,
-      &thiz->srcpad_info, GST_MAP_WRITE);
-
-  if (!thiz->use_video_memory)
+  if (thiz->use_video_memory) {
+    out_surface = gst_msdk_import_to_msdk_surface (outbuf, thiz->context,
+        &thiz->srcpad_info, GST_MAP_WRITE);
+  } else {
     out_surface =
         gst_msdk_import_sys_mem_to_msdk_surface (outbuf, &thiz->srcpad_info);
+  }
 
   if (out_surface) {
     out_surface->buf = gst_buffer_ref (outbuf);
@@ -951,14 +952,15 @@ gst_msdkvpp_transform (GstBaseTransform * trans, GstBuffer * inbuf,
       GST_BUFFER_DURATION (outbuf_new) = thiz->buffer_duration;
 
       release_out_surface (thiz, out_surface);
-      out_surface =
-          gst_msdk_import_to_msdk_surface (outbuf_new, thiz->context,
-          &thiz->srcpad_buffer_pool_info, GST_MAP_WRITE);
-
-      if (!thiz->use_video_memory)
+      if (thiz->use_video_memory) {
+        out_surface =
+            gst_msdk_import_to_msdk_surface (outbuf_new, thiz->context,
+            &thiz->srcpad_buffer_pool_info, GST_MAP_WRITE);
+      } else {
         out_surface =
             gst_msdk_import_sys_mem_to_msdk_surface (outbuf_new,
             &thiz->srcpad_buffer_pool_info);
+      }
 
       if (out_surface) {
         out_surface->buf = gst_buffer_ref (outbuf_new);