Fix memory leak (wrong usage gst_caps_from_string)
authorGilbok Lee <gilbok.lee@samsung.com>
Tue, 27 Jun 2017 05:50:03 +0000 (14:50 +0900)
committerGilbok Lee <gilbok.lee@samsung.com>
Tue, 27 Jun 2017 08:30:43 +0000 (17:30 +0900)
Change-Id: I8575e7aba0ea2e2ed9706e0a0e9a8ff16ab2ab45
Signed-off-by: Gilbok Lee <gilbok.lee@samsung.com>
20 files changed:
ext/bz2/gstbz2enc.c
ext/kate/gstkatedec.c
ext/musepack/gstmusepackdec.c
gst/autoconvert/gstautoconvert.c
gst/bayer/gstbayer2rgb.c
gst/cdxaparse/gstvcdparse.c
gst/mxf/mxfalaw.c
gst/mxf/mxfdv-dif.c
gst/mxf/mxfjpeg2000.c
gst/mxf/mxfup.c
gst/mxf/mxfvc3.c
gst/videofilters/gstscenechange.c
gst/videofilters/gstvideodiff.c
gst/videosignal/gstsimplevideomark.c
gst/videosignal/gstvideoanalyse.c
sys/bluez/gsta2dpsink.c
tests/examples/camerabin2/gst-camerabin2-test.c
tests/icles/dccp/call/DCCPClient.c
tests/icles/dccp/call/DCCPServer.c
tests/icles/dccp/mic/DCCPClientPlayMic.c

index c1c1ee1..89cdecb 100644 (file)
@@ -239,16 +239,18 @@ compress_error:
 static void
 gst_bz2enc_init (GstBz2enc * b)
 {
+  GstCaps *tmp = NULL;
   b->sink = gst_pad_new_from_static_template (&sink_template, "sink");
   gst_pad_set_chain_function (b->sink, GST_DEBUG_FUNCPTR (gst_bz2enc_chain));
   gst_pad_set_event_function (b->sink, GST_DEBUG_FUNCPTR (gst_bz2enc_event));
   gst_element_add_pad (GST_ELEMENT (b), b->sink);
 
   b->src = gst_pad_new_from_static_template (&src_template, "src");
-  gst_pad_set_caps (b->src, gst_static_pad_template_get_caps (&src_template));
+  gst_pad_set_caps (b->src, tmp = gst_static_pad_template_get_caps (&src_template));
   gst_pad_use_fixed_caps (b->src);
   gst_element_add_pad (GST_ELEMENT (b), b->src);
 
+  gst_caps_unref(tmp);
   b->block_size = DEFAULT_BLOCK_SIZE;
   b->buffer_size = DEFAULT_BUFFER_SIZE;
   gst_bz2enc_compress_init (b);
index 8748498..43aebf8 100644 (file)
@@ -181,6 +181,7 @@ gst_kate_dec_class_init (GstKateDecClass * klass)
 static void
 gst_kate_dec_init (GstKateDec * dec)
 {
+  GstCaps *tmp = NULL;
   GST_DEBUG_OBJECT (dec, "gst_kate_dec_init");
 
   dec->sinkpad = gst_pad_new_from_static_template (&sink_factory, "sink");
@@ -192,7 +193,7 @@ gst_kate_dec_init (GstKateDec * dec)
       GST_DEBUG_FUNCPTR (gst_kate_dec_sink_event));
   gst_pad_use_fixed_caps (dec->sinkpad);
   gst_pad_set_caps (dec->sinkpad,
-      gst_static_pad_template_get_caps (&sink_factory));
+      tmp = gst_static_pad_template_get_caps (&sink_factory));
   gst_element_add_pad (GST_ELEMENT (dec), dec->sinkpad);
 
   dec->srcpad = gst_pad_new_from_static_template (&src_factory, "src");
@@ -202,6 +203,7 @@ gst_kate_dec_init (GstKateDec * dec)
 
   gst_kate_util_decode_base_init (&dec->decoder, TRUE);
 
+  gst_caps_unref(tmp);
   dec->src_caps = NULL;
   dec->output_format = GST_KATE_FORMAT_UNDEFINED;
   dec->remove_markup = FALSE;
index bf08b1d..4e513d9 100644 (file)
@@ -429,8 +429,10 @@ gst_musepack_stream_init (GstMusepackDec * musepackdec)
   gst_pad_use_fixed_caps (musepackdec->srcpad);
   if (!gst_pad_set_caps (musepackdec->srcpad, caps)) {
     GST_ELEMENT_ERROR (musepackdec, CORE, NEGOTIATION, (NULL), (NULL));
+    gst_caps_unref (caps);
     return FALSE;
   }
+  gst_caps_unref (caps);
 
   g_atomic_int_set (&musepackdec->bps, 4 * i.channels);
   g_atomic_int_set (&musepackdec->rate, i.sample_freq);
index 230a15c..9600607 100644 (file)
@@ -845,8 +845,11 @@ gst_auto_convert_default_filter_func (GstPluginFeature * feature,
 
     caps = gst_static_pad_template_get_caps (template);
 
-    if (gst_caps_is_any (caps) || gst_caps_is_empty (caps))
+    if (gst_caps_is_any (caps) || gst_caps_is_empty (caps)) {
+      gst_caps_unref(caps);
       return FALSE;
+    }
+    gst_caps_unref(caps);
   }
 
   if (!src || !sink)
index e159ca2..391d720 100644 (file)
@@ -1,4 +1,4 @@
-/* 
+/*
  * GStreamer
  * Copyright (C) 2007 David Schleef <ds@schleef.org>
  *
@@ -162,7 +162,7 @@ gst_bayer2rgb_class_init (GstBayer2RGBClass * klass)
 {
   GObjectClass *gobject_class;
   GstElementClass *gstelement_class;
-
+  GstCaps *tmp = NULL;
   gobject_class = (GObjectClass *) klass;
   gstelement_class = (GstElementClass *) klass;
 
@@ -176,10 +176,12 @@ gst_bayer2rgb_class_init (GstBayer2RGBClass * klass)
 
   gst_element_class_add_pad_template (gstelement_class,
       gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
-          gst_caps_from_string (SRC_CAPS)));
+          tmp = gst_caps_from_string (SRC_CAPS)));
+  gst_caps_unref (tmp);
   gst_element_class_add_pad_template (gstelement_class,
       gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
-          gst_caps_from_string (SINK_CAPS)));
+          tmp = gst_caps_from_string (SINK_CAPS)));
+  gst_caps_unref (tmp);
 
   GST_BASE_TRANSFORM_CLASS (klass)->transform_caps =
       GST_DEBUG_FUNCPTR (gst_bayer2rgb_transform_caps);
index 4a3a7e7..54f3450 100644 (file)
@@ -77,6 +77,7 @@ gst_vcd_parse_class_init (GstVcdParseClass * klass)
 static void
 gst_vcd_parse_init (GstVcdParse * vcd, GstVcdParseClass * klass)
 {
+  GstCaps *tmp = NULL;
   vcd->sinkpad = gst_pad_new_from_static_template (&sink_factory, "sink");
   gst_pad_set_chain_function (vcd->sinkpad,
       GST_DEBUG_FUNCPTR (gst_vcd_parse_chain));
@@ -91,8 +92,9 @@ gst_vcd_parse_init (GstVcdParse * vcd, GstVcdParseClass * klass)
       GST_DEBUG_FUNCPTR (gst_vcd_parse_src_query));
   gst_pad_use_fixed_caps (vcd->srcpad);
   gst_pad_set_caps (vcd->srcpad,
-      gst_static_pad_template_get_caps (&src_factory));
+      tmp = gst_static_pad_template_get_caps (&src_factory));
   gst_element_add_pad (GST_ELEMENT (vcd), vcd->srcpad);
+  gst_caps_unref(tmp);
 }
 
 /* These conversion functions assume there's no junk between sectors */
@@ -346,9 +348,9 @@ gst_vcd_parse_chain (GstPad * pad, GstBuffer * buf)
      * !  sync    !  header ! subheader ! data ...   ! edc     !
      * ! 12 bytes ! 4 bytes ! 8 bytes   ! 2324 bytes ! 4 bytes !
      * +-------------------------------------------------------+
-     * 
+     *
      * We strip the data out of it and send it to the srcpad.
-     * 
+     *
      * sync       : 00 FF FF FF FF FF FF FF FF FF FF 00
      * header     : hour minute second mode
      * sub-header : track channel sub_mode coding repeat (4 bytes)
index 3ffce3a..df592c3 100644 (file)
@@ -331,11 +331,13 @@ static MXFEssenceElementWriter mxf_alaw_essence_element_writer = {
 void
 mxf_alaw_init (void)
 {
+  GstCaps *tmp = NULL;
   mxf_essence_element_handler_register (&mxf_alaw_essence_element_handler);
 
   mxf_alaw_essence_element_writer.pad_template =
       gst_pad_template_new ("alaw_audio_sink_%u", GST_PAD_SINK, GST_PAD_REQUEST,
-      gst_caps_from_string (ALAW_CAPS));
+      tmp = gst_caps_from_string (ALAW_CAPS));
+  gst_caps_unref (tmp);
   memcpy (&mxf_alaw_essence_element_writer.data_definition,
       mxf_metadata_track_identifier_get (MXF_METADATA_TRACK_SOUND_ESSENCE), 16);
   mxf_essence_element_writer_register (&mxf_alaw_essence_element_writer);
index 6f72c90..b8c9754 100644 (file)
@@ -261,14 +261,16 @@ static MXFEssenceElementWriter mxf_dv_dif_essence_element_writer = {
 void
 mxf_dv_dif_init (void)
 {
+  GstCaps *tmp = NULL;
   mxf_essence_element_handler_register (&mxf_dv_dif_essence_element_handler);
 
   mxf_dv_dif_essence_element_writer.pad_template =
       gst_pad_template_new ("dv_dif_video_sink_%u", GST_PAD_SINK,
       GST_PAD_REQUEST,
-      gst_caps_from_string ("video/x-dv, width = "
+      tmp = gst_caps_from_string ("video/x-dv, width = "
           GST_VIDEO_SIZE_RANGE ", height = " GST_VIDEO_SIZE_RANGE
           ", framerate = " GST_VIDEO_FPS_RANGE ", systemstream = true"));
+  gst_caps_unref (tmp);
   memcpy (&mxf_dv_dif_essence_element_writer.data_definition,
       mxf_metadata_track_identifier_get (MXF_METADATA_TRACK_PICTURE_ESSENCE),
       16);
index 1679279..a3497eb 100644 (file)
@@ -355,15 +355,17 @@ static MXFEssenceElementWriter mxf_jpeg2000_essence_element_writer = {
 void
 mxf_jpeg2000_init (void)
 {
+  GstCaps *tmp = NULL;
   mxf_essence_element_handler_register (&mxf_jpeg2000_essence_element_handler);
 
   mxf_jpeg2000_essence_element_writer.pad_template =
       gst_pad_template_new ("jpeg2000_video_sink_%u", GST_PAD_SINK,
       GST_PAD_REQUEST,
-      gst_caps_from_string ("image/x-jpc, fields = 1, width = "
+      tmp = gst_caps_from_string ("image/x-jpc, fields = 1, width = "
           GST_VIDEO_SIZE_RANGE ", height = " GST_VIDEO_SIZE_RANGE
           ", framerate = " GST_VIDEO_FPS_RANGE
           ", colorspace = (string) { \"sRGB\", \"sYUV\" }"));
+  gst_caps_unref (tmp);
   memcpy (&mxf_jpeg2000_essence_element_writer.data_definition,
       mxf_metadata_track_identifier_get (MXF_METADATA_TRACK_PICTURE_ESSENCE),
       16);
index afb6d95..251448b 100644 (file)
@@ -21,7 +21,7 @@
  * Generic Container
  */
 
-/* TODO: 
+/* TODO:
  *   - Handle CDCI essence
  *   - Handle more formats with RGBA descriptor (4:4:4 / 4:4:4:4 YUV, RGB656, ...)
  *   - Handle all the dimensions and other properties in the picture
@@ -613,10 +613,11 @@ static MXFEssenceElementWriter mxf_up_essence_element_writer = {
 void
 mxf_up_init (void)
 {
+  GstCaps *tmp = NULL;
   mxf_essence_element_handler_register (&mxf_up_essence_element_handler);
   mxf_up_essence_element_writer.pad_template =
       gst_pad_template_new ("up_video_sink_%u", GST_PAD_SINK, GST_PAD_REQUEST,
-      gst_caps_from_string (GST_VIDEO_CAPS_MAKE ("RGB") "; "
+      tmp = gst_caps_from_string (GST_VIDEO_CAPS_MAKE ("RGB") "; "
           GST_VIDEO_CAPS_MAKE ("BGR") "; "
           GST_VIDEO_CAPS_MAKE ("RGBx") "; "
           GST_VIDEO_CAPS_MAKE ("xRGB") "; "
@@ -629,6 +630,7 @@ mxf_up_init (void)
           GST_VIDEO_CAPS_MAKE ("AYUV") "; "
           GST_VIDEO_CAPS_MAKE ("v308") "; "
           GST_VIDEO_CAPS_MAKE ("UYVY") "; " GST_VIDEO_CAPS_MAKE ("YUY2")));
+  gst_caps_unref (tmp);
 
   memcpy (&mxf_up_essence_element_writer.data_definition,
       mxf_metadata_track_identifier_get (MXF_METADATA_TRACK_PICTURE_ESSENCE),
index bd2ca29..eb75595 100644 (file)
@@ -274,13 +274,15 @@ static MXFEssenceElementWriter mxf_vc3_essence_element_writer = {
 void
 mxf_vc3_init (void)
 {
+  GstCaps *tmp = NULL;
   mxf_essence_element_handler_register (&mxf_vc3_essence_element_handler);
 
   mxf_vc3_essence_element_writer.pad_template =
       gst_pad_template_new ("vc3_video_sink_%u", GST_PAD_SINK, GST_PAD_REQUEST,
-      gst_caps_from_string ("video/x-dnxhd, width = " GST_VIDEO_SIZE_RANGE
+      tmp = gst_caps_from_string ("video/x-dnxhd, width = " GST_VIDEO_SIZE_RANGE
           ", height = " GST_VIDEO_SIZE_RANGE ", framerate = "
           GST_VIDEO_FPS_RANGE));
+  gst_caps_unref (tmp);
   memcpy (&mxf_vc3_essence_element_writer.data_definition,
       mxf_metadata_track_identifier_get (MXF_METADATA_TRACK_PICTURE_ESSENCE),
       16);
index 7abfc8b..8c67614 100644 (file)
@@ -35,7 +35,7 @@
  * <refsect2>
  * <title>Example launch line</title>
  * |[
- * gst-launch -v filesrc location=some_file.ogv ! decodebin ! 
+ * gst-launch -v filesrc location=some_file.ogv ! decodebin !
  *   scenechange ! theoraenc ! fakesink
  * ]|
  * </refsect2>
@@ -60,7 +60,7 @@
  * terms of accuracy, schro's implementation has about 2-3 false positives
  * or false negatives per 100 scene changes.  This implementation has
  * about 5 per 100.  The threshold is tuned for minimum total false
- * positives or negatives, on the assumption that the badness of a 
+ * positives or negatives, on the assumption that the badness of a
  * false negative is the same as a false positive.
  *
  * This algorithm is pretty much at its limit for error rate.  I
@@ -116,13 +116,16 @@ static void
 gst_scene_change_class_init (GstSceneChangeClass * klass)
 {
   GstVideoFilterClass *video_filter_class = GST_VIDEO_FILTER_CLASS (klass);
+  GstCaps *tmp = NULL;
 
   gst_element_class_add_pad_template (GST_ELEMENT_CLASS (klass),
       gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
-          gst_caps_from_string (VIDEO_CAPS)));
+          tmp = gst_caps_from_string (VIDEO_CAPS)));
+  gst_caps_unref (tmp);
   gst_element_class_add_pad_template (GST_ELEMENT_CLASS (klass),
       gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
-          gst_caps_from_string (VIDEO_CAPS)));
+          tmp = gst_caps_from_string (VIDEO_CAPS)));
+  gst_caps_unref (tmp);
 
   gst_element_class_set_static_metadata (GST_ELEMENT_CLASS (klass),
       "Scene change detector",
index c6cdc86..2a5c77e 100644 (file)
@@ -73,15 +73,18 @@ static void
 gst_video_diff_class_init (GstVideoDiffClass * klass)
 {
   GstVideoFilterClass *video_filter_class = GST_VIDEO_FILTER_CLASS (klass);
+  GstCaps *tmp = NULL;
 
   /* Setting up pads and setting metadata should be moved to
      base_class_init if you intend to subclass this class. */
   gst_element_class_add_pad_template (GST_ELEMENT_CLASS (klass),
       gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
-          gst_caps_from_string (VIDEO_SRC_CAPS)));
+          tmp = gst_caps_from_string (VIDEO_SRC_CAPS)));
+  gst_caps_unref (tmp);
   gst_element_class_add_pad_template (GST_ELEMENT_CLASS (klass),
       gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
-          gst_caps_from_string (VIDEO_SINK_CAPS)));
+          tmp = gst_caps_from_string (VIDEO_SINK_CAPS)));
+  gst_caps_unref (tmp);
 
   gst_element_class_set_static_metadata (GST_ELEMENT_CLASS (klass),
       "FIXME Long name", "Generic", "FIXME Description",
index 9d57b52..0ec475a 100644 (file)
  * @see_also: #GstVideoDetect
  *
  * This plugin produces #GstSimpleVideoMark::pattern-count squares in the bottom left
- * corner of the video frames. The squares have a width and height of 
+ * corner of the video frames. The squares have a width and height of
  * respectively #GstSimpleVideoMark:pattern-width and #GstSimpleVideoMark:pattern-height.
  * Even squares will be black and odd squares will be white.
- * 
+ *
  * After writing the pattern, #GstSimpleVideoMark:pattern-data-count squares after the
  * pattern squares are produced as the bitarray given in
  * #GstSimpleVideoMark:pattern-data. 1 bits will produce white squares and 0 bits will
  * produce black squares.
- * 
+ *
  * The element can be enabled with the #GstSimpleVideoMark:enabled property. It is
  * mostly used together with the #GstVideoDetect plugin.
- * 
+ *
  * <refsect2>
  * <title>Example launch line</title>
  * |[
@@ -114,13 +114,16 @@ gst_video_mark_class_init (GstSimpleVideoMarkClass * klass)
   GstBaseTransformClass *base_transform_class =
       GST_BASE_TRANSFORM_CLASS (klass);
   GstVideoFilterClass *video_filter_class = GST_VIDEO_FILTER_CLASS (klass);
+  GstCaps *tmp = NULL;
 
   gst_element_class_add_pad_template (GST_ELEMENT_CLASS (klass),
       gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
-          gst_caps_from_string (VIDEO_CAPS)));
+          tmp = gst_caps_from_string (VIDEO_CAPS)));
+  gst_caps_unref (tmp);
   gst_element_class_add_pad_template (GST_ELEMENT_CLASS (klass),
       gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
-          gst_caps_from_string (VIDEO_CAPS)));
+          tmp = gst_caps_from_string (VIDEO_CAPS)));
+  gst_caps_unref (tmp);
 
   gst_element_class_set_static_metadata (GST_ELEMENT_CLASS (klass),
       "Video marker", "Filter/Effect/Video",
index 3ca4d03..0014e36 100644 (file)
  *   </para>
  * </listitem>
  * </itemizedlist>
- * 
+ *
  * <refsect2>
  * <title>Example launch line</title>
  * |[
  * gst-launch -m videotestsrc ! videoanalyse ! videoconvert ! ximagesink
- * ]| This pipeline emits messages to the console for each frame that has been analysed. 
+ * ]| This pipeline emits messages to the console for each frame that has been analysed.
  * </refsect2>
  */
 
@@ -124,14 +124,17 @@ static void
 gst_video_analyse_class_init (GstVideoAnalyseClass * klass)
 {
   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+  GstCaps *tmp = NULL;
   GstVideoFilterClass *video_filter_class = GST_VIDEO_FILTER_CLASS (klass);
 
   gst_element_class_add_pad_template (GST_ELEMENT_CLASS (klass),
       gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
-          gst_caps_from_string (VIDEO_CAPS)));
+          tmp = gst_caps_from_string (VIDEO_CAPS)));
+  gst_caps_unref (tmp);
   gst_element_class_add_pad_template (GST_ELEMENT_CLASS (klass),
       gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
-          gst_caps_from_string (VIDEO_CAPS)));
+          tmp = gst_caps_from_string (VIDEO_CAPS)));
+  gst_caps_unref (tmp);
 
   gst_element_class_set_static_metadata (GST_ELEMENT_CLASS (klass),
       "Video analyser", "Filter/Analyzer/Video",
index c6da0f9..73b6644 100644 (file)
@@ -705,13 +705,15 @@ gst_a2dp_sink_init (GstA2dpSink * self)
   self->taglist = NULL;
   self->ghostpad = NULL;
   self->sink_is_in_bin = FALSE;
+  GstCaps *tmp = NULL;
 
   g_mutex_init (&self->cb_mutex);
 
   /* we initialize our capsfilter */
   gst_a2dp_sink_init_caps_filter (self);
   g_object_set (self->capsfilter, "caps",
-      gst_static_pad_template_get_caps (&gst_a2dp_sink_factory), NULL);
+      tmp = gst_static_pad_template_get_caps (&gst_a2dp_sink_factory), NULL);
+  gst_caps_unref(tmp);
 
   gst_a2dp_sink_init_fakesink (self);
 
index 90e010a..8ab0d44 100644 (file)
@@ -883,6 +883,7 @@ run_pipeline (gpointer user_data)
     preview_caps = gst_caps_from_string (preview_caps_name);
     if (preview_caps) {
       g_object_set (camerabin, "preview-caps", preview_caps, NULL);
+      gst_caps_unref (preview_caps);
       GST_DEBUG ("Preview caps set");
     } else
       GST_DEBUG ("Preview caps set but could not create caps from string");
index 5f7eb01..c0b7cc1 100644 (file)
@@ -106,6 +106,7 @@ main (int argc, char *argv[])
       gst_caps_from_string
       ("audio/x-raw-int, endianness=(int)1234, signed=(boolean)true, width=(int)32, depth=(int)32, rate=(int)44100, channels=(int)2");
   g_object_set (G_OBJECT (dccpclientsrc), "caps", caps, NULL);
+  gst_object_unref (caps);
 
   g_object_set (G_OBJECT (dccpclientsrc), "host", argv[1], NULL);
   /*g_object_set (G_OBJECT (dccpclientsrc), "ccid", 3, NULL);
index fe0e34f..c999d62 100644 (file)
@@ -100,6 +100,7 @@ main (int argc, char *argv[])
       gst_caps_from_string
       ("audio/x-raw-int, endianness=(int)1234, signed=(boolean)true, width=(int)32, depth=(int)32, rate=(int)44100, channels=(int)2");
   g_object_set (G_OBJECT (dccpclientsrc), "caps", caps, NULL);
+  gst_object_unref (caps);
 
   /*g_object_set (G_OBJECT (dccpclientsrc), "ccid", 3, NULL);
      g_object_set (G_OBJECT (dccpserversink), "ccid", 3, NULL); */
index 4cd0c3b..13a6ec7 100644 (file)
@@ -87,6 +87,7 @@ main (int argc, char *argv[])
       ("audio/x-raw-int, endianness=(int)1234, signed=(boolean)true, width=(int)32, depth=(int)32, rate=(int)44100, channels=(int)2");
 
   g_object_set (G_OBJECT (dccpclientsrc), "caps", caps, NULL);
+  gst_object_unref (caps);
   g_object_set (G_OBJECT (dccpclientsrc), "host", argv[1], NULL);
   g_object_set (G_OBJECT (dccpclientsrc), "port", atoi (argv[2]), NULL);
   /*g_object_set (G_OBJECT (dccpclientsrc), "ccid", 3, NULL); */