From 5109622dd0c4d61553c15d1eebbbaa954cf10b81 Mon Sep 17 00:00:00 2001 From: Jan Schmidt Date: Sun, 5 Feb 2006 23:31:05 +0000 Subject: [PATCH] Add a finalize method to ensure we clean up state even if someone omitted the state change back to NULL. Original commit message from CVS: (theora_enc_finalize), (theora_enc_sink_setcaps): Add a finalize method to ensure we clean up state even if someone omitted the state change back to NULL. * ext/vorbis/vorbisenc.c: (gst_vorbisenc_metadata_set1), (gst_vorbisenc_chain): Free some more leaked bits. * tests/check/pipelines/theoraenc.c: (start_pipeline), (stop_pipeline): Wait for state changes to happen if they're ASYNC. This ought to teach those fancy pants buildbots a lesson. --- ChangeLog | 17 +++++++++++++++++ ext/theora/theoraenc.c | 14 ++++++++++++++ ext/vorbis/vorbisenc.c | 2 ++ tests/check/pipelines/theoraenc.c | 19 ++++++++++++++++--- 4 files changed, 49 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2c788ba..58feb0c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2006-02-06 Jan Schmidt + + * ext/theora/theoraenc.c: (gst_theora_enc_class_init), + (theora_enc_finalize), (theora_enc_sink_setcaps): + Add a finalize method to ensure we clean up state even if + someone omitted the state change back to NULL. + + * ext/vorbis/vorbisenc.c: (gst_vorbisenc_metadata_set1), + (gst_vorbisenc_chain): + Free some more leaked bits. + + * tests/check/pipelines/theoraenc.c: (start_pipeline), + (stop_pipeline): + Wait for state changes to happen if they're ASYNC. + + This ought to teach those fancy pants buildbots a lesson. + 2006-02-05 Jan Schmidt * gst-libs/gst/tag/gstid3tag.c: diff --git a/ext/theora/theoraenc.c b/ext/theora/theoraenc.c index b236628..ee79e1c 100644 --- a/ext/theora/theoraenc.c +++ b/ext/theora/theoraenc.c @@ -148,6 +148,7 @@ static void theora_enc_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec); static void theora_enc_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec); +static void theora_enc_finalize (GObject * object); static void gst_theora_enc_base_init (gpointer g_class) @@ -169,6 +170,7 @@ gst_theora_enc_class_init (GstTheoraEncClass * klass) gobject_class->set_property = theora_enc_set_property; gobject_class->get_property = theora_enc_get_property; + gobject_class->finalize = theora_enc_finalize; g_object_class_install_property (gobject_class, ARG_CENTER, g_param_spec_boolean ("center", "Center", @@ -256,6 +258,16 @@ gst_theora_enc_init (GstTheoraEnc * enc, GstTheoraEncClass * g_class) enc->info.keyframe_frequency_force, enc->granule_shift); } +static void +theora_enc_finalize (GObject * object) +{ + GstTheoraEnc *enc = GST_THEORA_ENC (object); + + theora_clear (&enc->state); + theora_comment_clear (&enc->comment); + theora_info_clear (&enc->info); +} + static gboolean theora_enc_sink_setcaps (GstPad * pad, GstCaps * caps) { @@ -324,6 +336,8 @@ theora_enc_sink_setcaps (GstPad * pad, GstCaps * caps) theora_encode_init (&enc->state, &enc->info); + gst_object_unref (enc); + return TRUE; } diff --git a/ext/vorbis/vorbisenc.c b/ext/vorbis/vorbisenc.c index 8d4a13c..1e17568 100644 --- a/ext/vorbis/vorbisenc.c +++ b/ext/vorbis/vorbisenc.c @@ -613,6 +613,7 @@ gst_vorbisenc_metadata_set1 (const GstTagList * list, const gchar * tag, vorbis_comment_add_tag (&enc->vc, tmptag, vorbisvalue); g_free (tmptag); + g_free (vorbisvalue); } } } @@ -968,6 +969,7 @@ gst_vorbisenc_chain (GstPad * pad, GstBuffer * buffer) gst_vorbisenc_set_metadata (vorbisenc); vorbis_analysis_headerout (&vorbisenc->vd, &vorbisenc->vc, &header, &header_comm, &header_code); + vorbis_comment_clear (&vorbisenc->vc); /* create header buffers */ buf1 = gst_vorbisenc_buffer_from_header_packet (vorbisenc, &header); diff --git a/tests/check/pipelines/theoraenc.c b/tests/check/pipelines/theoraenc.c index 27ebc33..27e3bd6 100644 --- a/tests/check/pipelines/theoraenc.c +++ b/tests/check/pipelines/theoraenc.c @@ -56,13 +56,19 @@ buffer_probe (GstPad * pad, GstBuffer * buffer, gpointer unused) static void start_pipeline (GstElement * bin, GstPad * pad) { + GstStateChangeReturn ret; + id = gst_pad_add_buffer_probe (pad, G_CALLBACK (buffer_probe), NULL); cond = g_cond_new (); lock = g_mutex_new (); - gst_element_set_state (bin, GST_STATE_PLAYING); - + ret = gst_element_set_state (bin, GST_STATE_PLAYING); + fail_if (ret == GST_STATE_CHANGE_FAILURE, "Could not start test pipeline"); + if (ret == GST_STATE_CHANGE_ASYNC) { + ret = gst_element_get_state (bin, NULL, NULL, GST_CLOCK_TIME_NONE); + fail_if (ret != GST_STATE_CHANGE_SUCCESS, "Could not start test pipeline"); + } } /* waits until the probe receives a buffer. will catch every buffer */ @@ -89,6 +95,8 @@ get_buffer (GstElement * bin, GstPad * pad) static void stop_pipeline (GstElement * bin, GstPad * pad) { + GstStateChangeReturn ret; + g_mutex_lock (lock); if (buf) gst_buffer_unref (buf); @@ -98,7 +106,12 @@ stop_pipeline (GstElement * bin, GstPad * pad) g_cond_signal (cond); g_mutex_unlock (lock); - gst_element_set_state (bin, GST_STATE_NULL); + ret = gst_element_set_state (bin, GST_STATE_NULL); + fail_if (ret == GST_STATE_CHANGE_FAILURE, "Could not stop test pipeline"); + if (ret == GST_STATE_CHANGE_ASYNC) { + ret = gst_element_get_state (bin, NULL, NULL, GST_CLOCK_TIME_NONE); + fail_if (ret != GST_STATE_CHANGE_SUCCESS, "Could not stop test pipeline"); + } g_mutex_lock (lock); if (buf) -- 2.7.4