libs: use array_unref() rather than array_free()
authorVíctor Manuel Jáquez Leal <vjaquez@igalia.com>
Sat, 16 May 2020 18:49:31 +0000 (20:49 +0200)
committerVíctor Manuel Jáquez Leal <vjaquez@igalia.com>
Sat, 16 May 2020 20:29:34 +0000 (20:29 +0000)
It is more convinience and thread-safe.

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

gst-libs/gst/vaapi/gstvaapicontext.c
gst-libs/gst/vaapi/gstvaapidisplay.c
gst-libs/gst/vaapi/gstvaapidisplay_x11.c
gst-libs/gst/vaapi/gstvaapiparser_frame.c
gst-libs/gst/vaapi/gstvaapisurface.c

index e4839d3..5d5deb6 100644 (file)
@@ -255,7 +255,7 @@ context_create (GstVaapiContext * context)
 
 cleanup:
   if (surfaces)
-    g_array_free (surfaces, TRUE);
+    g_array_unref (surfaces);
   return success;
 }
 
index 092885a..5b74d82 100644 (file)
@@ -898,35 +898,12 @@ gst_vaapi_display_destroy (GstVaapiDisplay * display)
 {
   GstVaapiDisplayPrivate *const priv = GST_VAAPI_DISPLAY_GET_PRIVATE (display);
 
-  if (priv->decoders) {
-    g_ptr_array_free (priv->decoders, TRUE);
-    priv->decoders = NULL;
-  }
-
-  if (priv->encoders) {
-    g_ptr_array_free (priv->encoders, TRUE);
-    priv->encoders = NULL;
-  }
-
-  if (priv->codecs) {
-    g_array_free (priv->codecs, TRUE);
-    priv->codecs = NULL;
-  }
-
-  if (priv->image_formats) {
-    g_array_free (priv->image_formats, TRUE);
-    priv->image_formats = NULL;
-  }
-
-  if (priv->subpicture_formats) {
-    g_array_free (priv->subpicture_formats, TRUE);
-    priv->subpicture_formats = NULL;
-  }
-
-  if (priv->properties) {
-    g_array_free (priv->properties, TRUE);
-    priv->properties = NULL;
-  }
+  g_clear_pointer (&priv->decoders, g_ptr_array_unref);
+  g_clear_pointer (&priv->encoders, g_ptr_array_unref);
+  g_clear_pointer (&priv->codecs, g_array_unref);
+  g_clear_pointer (&priv->image_formats, g_array_unref);
+  g_clear_pointer (&priv->subpicture_formats, g_array_unref);
+  g_clear_pointer (&priv->properties, g_array_unref);
 
   if (priv->display) {
     if (!priv->parent)
index 50300b8..1f2e1cc 100644 (file)
@@ -156,10 +156,7 @@ gst_vaapi_display_x11_close_display (GstVaapiDisplay * display)
   GstVaapiDisplayX11Private *const priv =
       GST_VAAPI_DISPLAY_X11_PRIVATE (display);
 
-  if (priv->pixmap_formats) {
-    g_array_free (priv->pixmap_formats, TRUE);
-    priv->pixmap_formats = NULL;
-  }
+  g_clear_pointer (&priv->pixmap_formats, g_array_unref);
 
   if (priv->x11_display) {
     if (!priv->use_foreign_display)
index 4eda63f..66da510 100644 (file)
@@ -60,7 +60,7 @@ free_units (GArray ** units_ptr)
           &g_array_index (units, GstVaapiDecoderUnit, i);
       gst_vaapi_decoder_unit_clear (unit);
     }
-    g_array_free (units, TRUE);
+    g_array_unref (units);
     *units_ptr = NULL;
   }
 }
index 5c821f6..64ab118 100644 (file)
@@ -61,8 +61,7 @@ gst_vaapi_surface_destroy_subpictures (GstVaapiSurface * surface)
 {
   if (surface->subpictures) {
     g_ptr_array_foreach (surface->subpictures, destroy_subpicture_cb, surface);
-    g_ptr_array_free (surface->subpictures, TRUE);
-    surface->subpictures = NULL;
+    g_clear_pointer (&surface->subpictures, g_ptr_array_unref);
   }
 }