gst/tcp/gstmultifdsink.c: clean up the bufqueue when shutting down

Original commit message from CVS:

* gst/tcp/gstmultifdsink.c: (gst_multi_fd_sink_stop):
clean up the bufqueue when shutting down
* tests/check/Makefile.am:
* tests/check/elements/multifdsink.c: (setup_multifdsink),
(cleanup_multifdsink), (GST_START_TEST), (multifdsink_suite),
(main):
add a test for the leak that was just fixed
This commit is contained in:
Thomas Vander Stichele 2006-05-10 16:34:06 +00:00
parent 634dc7bc5b
commit c6b71079c1
4 changed files with 131 additions and 0 deletions

View file

@ -1,3 +1,13 @@
2006-05-10 Thomas Vander Stichele <thomas at apestaart dot org>
* gst/tcp/gstmultifdsink.c: (gst_multi_fd_sink_stop):
clean up the bufqueue when shutting down
* tests/check/Makefile.am:
* tests/check/elements/multifdsink.c: (setup_multifdsink),
(cleanup_multifdsink), (GST_START_TEST), (multifdsink_suite),
(main):
add a test for the leak that was just fixed
2006-05-10 Wim Taymans <wim@fluendo.com>
* gst/adder/gstadder.c: (gst_adder_setcaps),

View file

@ -655,6 +655,8 @@ gst_multi_fd_sink_remove (GstMultiFdSink * sink, int fd)
CLIENTS_UNLOCK (sink);
}
/* can be called both through the signal (ie from any thread) or when stopping,
* after the writing thread has shut down */
void
gst_multi_fd_sink_clear (GstMultiFdSink * sink)
{
@ -1859,6 +1861,8 @@ gst_multi_fd_sink_stop (GstBaseSink * bsink)
{
GstMultiFdSinkClass *fclass;
GstMultiFdSink *this;
GstBuffer *buf;
int i;
this = GST_MULTI_FD_SINK (bsink);
fclass = GST_MULTI_FD_SINK_GET_CLASS (this);
@ -1870,7 +1874,9 @@ gst_multi_fd_sink_stop (GstBaseSink * bsink)
SEND_COMMAND (this, CONTROL_STOP);
if (this->thread) {
GST_DEBUG_OBJECT (this, "joining thread");
g_thread_join (this->thread);
GST_DEBUG_OBJECT (this, "joined thread");
this->thread = NULL;
}
@ -1895,6 +1901,20 @@ gst_multi_fd_sink_stop (GstBaseSink * bsink)
this->fdset = NULL;
}
g_hash_table_foreach_remove (this->fd_hash, multifdsink_hash_remove, this);
/* remove all queued buffers */
if (this->bufqueue) {
GST_DEBUG_OBJECT (this, "Emptying bufqueue with %d buffers",
this->bufqueue->len);
for (i = this->bufqueue->len - 1; i >= 0; --i) {
buf = g_array_index (this->bufqueue, GstBuffer *, i);
GST_LOG_OBJECT (this, "Removing buffer %p (%d) with refcount %d", buf, i,
GST_MINI_OBJECT_REFCOUNT (buf));
gst_buffer_unref (buf);
this->bufqueue = g_array_remove_index (this->bufqueue, i);
}
/* freeing the array is done in _finalize */
}
GST_OBJECT_FLAG_UNSET (this, GST_MULTI_FD_SINK_OPEN);
return TRUE;

View file

@ -38,6 +38,7 @@ check_PROGRAMS = $(check_vorbis) \
elements/audioconvert \
elements/audioresample \
elements/audiotestsrc \
elements/multifdsink \
elements/videorate \
elements/videotestsrc \
elements/volume \

View file

@ -0,0 +1,100 @@
/* GStreamer
*
* Copyright (C) 2006 Thomas Vander Stichele <thomas at apestaart dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include <unistd.h>
#include <gst/check/gstcheck.h>
GstPad *mysrcpad;
static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("application/x-gdp")
);
GstElement *
setup_multifdsink ()
{
GstElement *multifdsink;
GST_DEBUG ("setup_multifdsink");
multifdsink = gst_check_setup_element ("multifdsink");
mysrcpad = gst_check_setup_src_pad (multifdsink, &srctemplate, NULL);
return multifdsink;
}
void
cleanup_multifdsink (GstElement * multifdsink)
{
GST_DEBUG ("cleanup_multifdsink");
gst_check_teardown_src_pad (multifdsink);
gst_check_teardown_element (multifdsink);
}
GST_START_TEST (test_no_clients)
{
GstElement *sink;
GstBuffer *buffer;
sink = setup_multifdsink ();
ASSERT_SET_STATE (sink, GST_STATE_PLAYING, GST_STATE_CHANGE_ASYNC);
buffer = gst_buffer_new_and_alloc (4);
fail_unless (gst_pad_push (mysrcpad, buffer) == GST_FLOW_OK);
GST_DEBUG ("cleaning up multifdsink");
ASSERT_SET_STATE (sink, GST_STATE_NULL, GST_STATE_CHANGE_SUCCESS);
cleanup_multifdsink (sink);
}
GST_END_TEST;
Suite *
multifdsink_suite (void)
{
Suite *s = suite_create ("multifdsink");
TCase *tc_chain = tcase_create ("general");
suite_add_tcase (s, tc_chain);
tcase_add_test (tc_chain, test_no_clients);
return s;
}
int
main (int argc, char **argv)
{
int nf;
Suite *s = multifdsink_suite ();
SRunner *sr = srunner_create (s);
gst_check_init (&argc, &argv);
srunner_run_all (sr, CK_NORMAL);
nf = srunner_ntests_failed (sr);
srunner_free (sr);
return nf;
}