xvimagesink: Don't leak XvShmImage
authorJan Schmidt <jan@centricular.com>
Fri, 30 Sep 2022 18:51:21 +0000 (04:51 +1000)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Mon, 3 Oct 2022 17:30:51 +0000 (17:30 +0000)
If allocating an XvShmImage generates an X error, but
still returns some allocated memory, make sure to free it
so it doesn't leak.

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

subprojects/gst-plugins-base/sys/xvimage/xvimageallocator.c

index bf1f2bd..a6d8432 100644 (file)
@@ -383,6 +383,13 @@ gst_xvimage_allocator_alloc (GstXvImageAllocator * allocator, gint im_format,
         context->xv_port_id, im_format, NULL, padded_width, padded_height,
         &mem->SHMInfo);
     if (!mem->xvimage || error_caught) {
+
+      /* If the memory was allocated, drop it */
+      if (mem->xvimage) {
+        XFree (mem->xvimage);
+        mem->xvimage = NULL;
+      }
+
       g_mutex_unlock (&context->lock);
 
       /* Reset error flag */