closedcaption: fix leak in line21 decoder
authorTim-Philipp Müller <tim@centricular.com>
Wed, 6 Mar 2019 18:32:38 +0000 (18:32 +0000)
committerTim-Philipp Müller <tim@centricular.com>
Fri, 8 Mar 2019 01:18:39 +0000 (01:18 +0000)
Destroy old decoder instance when shutting down the
element, and also in case the input format changes.

Fix harness/pipeline leak in unit test.

ext/closedcaption/gstline21dec.c
tests/check/elements/line21.c

index b3c93cb..a7f91d8 100644 (file)
@@ -53,6 +53,7 @@ G_DEFINE_TYPE (GstLine21Decoder, gst_line_21_decoder, GST_TYPE_VIDEO_FILTER);
 #define parent_class gst_line_21_decoder_parent_class
 
 static void gst_line_21_decoder_finalize (GObject * self);
+static gboolean gst_line_21_decoder_stop (GstBaseTransform * btrans);
 static gboolean gst_line_21_decoder_set_info (GstVideoFilter * filter,
     GstCaps * incaps, GstVideoInfo * in_info,
     GstCaps * outcaps, GstVideoInfo * out_info);
@@ -85,6 +86,7 @@ gst_line_21_decoder_class_init (GstLine21DecoderClass * klass)
   gst_element_class_add_static_pad_template (gstelement_class, &sinktemplate);
   gst_element_class_add_static_pad_template (gstelement_class, &srctemplate);
 
+  transform_class->stop = gst_line_21_decoder_stop;
   transform_class->prepare_output_buffer =
       gst_line_21_decoder_prepare_output_buffer;
 
@@ -202,7 +204,10 @@ gst_line_21_decoder_set_info (GstVideoFilter * filter,
       self->info = gst_video_info_copy (in_info);
 
     /* initialize the decoder */
-    vbi_raw_decoder_init (&self->zvbi_decoder);
+    if (self->zvbi_decoder.pattern != NULL)
+      vbi_raw_decoder_reset (&self->zvbi_decoder);
+    else
+      vbi_raw_decoder_init (&self->zvbi_decoder);
     /*
      * Set up blank / black / white levels fit for NTSC, no actual relation
      * with the height of the video
@@ -415,6 +420,16 @@ gst_line_21_decoder_transform_ip (GstVideoFilter * filter,
   return GST_FLOW_OK;
 }
 
+static gboolean
+gst_line_21_decoder_stop (GstBaseTransform * btrans)
+{
+  GstLine21Decoder *self = (GstLine21Decoder *) btrans;
+
+  vbi_raw_decoder_destroy (&self->zvbi_decoder);
+
+  return TRUE;
+}
+
 static void
 gst_line_21_decoder_finalize (GObject * object)
 {
index 029ff23..02547ec 100644 (file)
@@ -83,6 +83,7 @@ GST_START_TEST (basic)
     fail_unless (out_cc_meta->data[i] == full_data[i]);
 
   gst_buffer_unref (outbuf);
+  gst_harness_teardown (h);
 }
 
 GST_END_TEST;