From b6723ecd3cea0f6e819e8671582b3638698a3f16 Mon Sep 17 00:00:00 2001 From: Juan Pablo Ugarte Date: Fri, 10 Feb 2017 10:32:57 -0300 Subject: [PATCH] v4l2object: mark singleton caps as "may be leaked" objects. Set MAY_BE_LEAKED flag on static pads returned by gst_v4l2_object_get_*_caps() functions. Made functions thread safe by using g_once_init[enter|leave] funtions. https://bugzilla.gnome.org/show_bug.cgi?id=778453 --- sys/v4l2/gstv4l2object.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/sys/v4l2/gstv4l2object.c b/sys/v4l2/gstv4l2object.c index 47a8dd7..dc7585c 100644 --- a/sys/v4l2/gstv4l2object.c +++ b/sys/v4l2/gstv4l2object.c @@ -1577,10 +1577,13 @@ gst_v4l2_object_get_all_caps (void) { static GstCaps *caps = NULL; - if (caps == NULL) - caps = gst_v4l2_object_get_caps_helper (GST_V4L2_ALL); + if (g_once_init_enter (&caps)) { + GstCaps *all_caps = gst_v4l2_object_get_caps_helper (GST_V4L2_ALL); + GST_MINI_OBJECT_FLAG_SET (all_caps, GST_MINI_OBJECT_FLAG_MAY_BE_LEAKED); + g_once_init_leave (&caps, all_caps); + } - return gst_caps_ref (caps); + return caps; } GstCaps * @@ -1588,10 +1591,13 @@ gst_v4l2_object_get_raw_caps (void) { static GstCaps *caps = NULL; - if (caps == NULL) - caps = gst_v4l2_object_get_caps_helper (GST_V4L2_RAW); + if (g_once_init_enter (&caps)) { + GstCaps *raw_caps = gst_v4l2_object_get_caps_helper (GST_V4L2_RAW); + GST_MINI_OBJECT_FLAG_SET (raw_caps, GST_MINI_OBJECT_FLAG_MAY_BE_LEAKED); + g_once_init_leave (&caps, raw_caps); + } - return gst_caps_ref (caps); + return caps; } GstCaps * @@ -1599,10 +1605,13 @@ gst_v4l2_object_get_codec_caps (void) { static GstCaps *caps = NULL; - if (caps == NULL) - caps = gst_v4l2_object_get_caps_helper (GST_V4L2_CODEC); + if (g_once_init_enter (&caps)) { + GstCaps *codec_caps = gst_v4l2_object_get_caps_helper (GST_V4L2_CODEC); + GST_MINI_OBJECT_FLAG_SET (codec_caps, GST_MINI_OBJECT_FLAG_MAY_BE_LEAKED); + g_once_init_leave (&caps, codec_caps); + } - return gst_caps_ref (caps); + return caps; } /* collect data for the given caps -- 2.7.4