cuda: Add/fix various annotations
authorSebastian Dröge <sebastian@centricular.com>
Mon, 17 Oct 2022 07:51:42 +0000 (10:51 +0300)
committerSebastian Dröge <sebastian@centricular.com>
Tue, 18 Oct 2022 10:51:17 +0000 (13:51 +0300)
And fix a memory leak when creating a CUDA context fails.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3194>

subprojects/gst-plugins-bad/gst-libs/gst/cuda/gstcudacontext.c
subprojects/gst-plugins-bad/gst-libs/gst/cuda/gstcudautils.c

index aed158a..9b72173 100644 (file)
@@ -374,7 +374,8 @@ gst_cuda_context_finalize (GObject * object)
  *
  * Create #GstCudaContext with given device_id
  *
- * Returns: a new #GstCudaContext or %NULL on failure
+ * Returns: (transfer full) (nullable): a new #GstCudaContext or %NULL on
+ * failure
  *
  * Since: 1.22
  */
@@ -390,13 +391,16 @@ gst_cuda_context_new (guint device_id)
   }
 
   self = gst_cuda_context_new_wrapped (ctx, device_id);
-  if (!self)
+  if (!self) {
+    CuCtxDestroy (ctx);
     return NULL;
+  }
 
   self->priv->owns_context = TRUE;
 
   if (!gst_cuda_result (CuCtxPopCurrent (&old_ctx))) {
     GST_ERROR ("Could not pop current context");
+    g_object_unref (self);
 
     return NULL;
   }
@@ -522,7 +526,7 @@ gst_cuda_context_can_access_peer (GstCudaContext * ctx, GstCudaContext * peer)
  * represented by @handle and @device stay alive while the returned
  * #GstCudaContext is active.
  *
- * Returns: (transfer full): A newly created #GstCudaContext
+ * Returns: (transfer full) (nullable): A newly created #GstCudaContext
  *
  * Since: 1.22
  */
@@ -538,7 +542,7 @@ gst_cuda_context_new_wrapped (CUcontext handler, CUdevice device)
   g_return_val_if_fail (device >= 0, NULL);
 
   if (!init_cuda_ctx ())
-    return FALSE;
+    return NULL;
 
   if (!gst_cuda_result (CuDeviceGetAttribute (&tex_align,
               CU_DEVICE_ATTRIBUTE_TEXTURE_ALIGNMENT, device))) {
index 9dfb0f7..f4d5f5d 100644 (file)
@@ -367,8 +367,7 @@ gst_cuda_handle_context_query (GstElement * element,
  * gst_context_new_cuda_context:
  * @cuda_ctx: (transfer none): a #GstCudaContext
  *
- * Returns: (transfer full) (nullable): a new #GstContext embedding the @cuda_ctx
- * or %NULL
+ * Returns: (transfer full): a new #GstContext embedding the @cuda_ctx
  *
  * Since: 1.22
  */
@@ -571,7 +570,7 @@ gst_cuda_graphics_resource_unregister (GstCudaGraphicsResource * resource)
  *
  * Map previously registered resource with map flags
  *
- * Returns: the `CUgraphicsResource` if successful or %NULL when failed
+ * Returns: (nullable): the `CUgraphicsResource` if successful or %NULL when failed
  *
  * Since: 1.22
  */