cuda: Add/fix various annotations

And fix a memory leak when creating a CUDA context fails.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3194>
This commit is contained in:
Sebastian Dröge 2022-10-17 10:51:42 +03:00
parent f821ddc108
commit 73557fe093
2 changed files with 10 additions and 7 deletions

View file

@ -374,7 +374,8 @@ gst_cuda_context_finalize (GObject * object)
* *
* Create #GstCudaContext with given device_id * 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 * Since: 1.22
*/ */
@ -390,13 +391,16 @@ gst_cuda_context_new (guint device_id)
} }
self = gst_cuda_context_new_wrapped (ctx, device_id); self = gst_cuda_context_new_wrapped (ctx, device_id);
if (!self) if (!self) {
CuCtxDestroy (ctx);
return NULL; return NULL;
}
self->priv->owns_context = TRUE; self->priv->owns_context = TRUE;
if (!gst_cuda_result (CuCtxPopCurrent (&old_ctx))) { if (!gst_cuda_result (CuCtxPopCurrent (&old_ctx))) {
GST_ERROR ("Could not pop current context"); GST_ERROR ("Could not pop current context");
g_object_unref (self);
return NULL; 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 * represented by @handle and @device stay alive while the returned
* #GstCudaContext is active. * #GstCudaContext is active.
* *
* Returns: (transfer full): A newly created #GstCudaContext * Returns: (transfer full) (nullable): A newly created #GstCudaContext
* *
* Since: 1.22 * Since: 1.22
*/ */
@ -538,7 +542,7 @@ gst_cuda_context_new_wrapped (CUcontext handler, CUdevice device)
g_return_val_if_fail (device >= 0, NULL); g_return_val_if_fail (device >= 0, NULL);
if (!init_cuda_ctx ()) if (!init_cuda_ctx ())
return FALSE; return NULL;
if (!gst_cuda_result (CuDeviceGetAttribute (&tex_align, if (!gst_cuda_result (CuDeviceGetAttribute (&tex_align,
CU_DEVICE_ATTRIBUTE_TEXTURE_ALIGNMENT, device))) { CU_DEVICE_ATTRIBUTE_TEXTURE_ALIGNMENT, device))) {

View file

@ -367,8 +367,7 @@ gst_cuda_handle_context_query (GstElement * element,
* gst_context_new_cuda_context: * gst_context_new_cuda_context:
* @cuda_ctx: (transfer none): a #GstCudaContext * @cuda_ctx: (transfer none): a #GstCudaContext
* *
* Returns: (transfer full) (nullable): a new #GstContext embedding the @cuda_ctx * Returns: (transfer full): a new #GstContext embedding the @cuda_ctx
* or %NULL
* *
* Since: 1.22 * Since: 1.22
*/ */
@ -571,7 +570,7 @@ gst_cuda_graphics_resource_unregister (GstCudaGraphicsResource * resource)
* *
* Map previously registered resource with map flags * 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 * Since: 1.22
*/ */