gst/: clean up used memory in this elements correctly on teardown (closes #137279)

Original commit message from CVS:
reviewed by Benjamin Otte  <otte@gnome.org>
* gst/autoplug/gstspider.c: (gst_spider_dispose):
* gst/elements/gstaggregator.c: (gst_aggregator_finalize),
(gst_aggregator_class_init), (gst_aggregator_init):
* gst/elements/gstfilesrc.c: (gst_filesrc_init),
(gst_filesrc_dispose), (gst_filesrc_set_location):
* gst/elements/gstidentity.c: (gst_identity_finalize),
(gst_identity_class_init), (gst_identity_chain):
* gst/elements/gstmultifilesrc.c: (gst_multifilesrc_open_file):
* gst/elements/gststatistics.c: (gst_statistics_finalize),
(gst_statistics_class_init):
* gst/elements/gsttee.c: (gst_tee_finalize), (gst_tee_class_init),
(gst_tee_get_property):
clean up used memory in this elements correctly on teardown (closes
#137279)
This commit is contained in:
Benjamin Otte 2004-03-21 03:22:55 +00:00
parent 5033bd37b9
commit c903ce8a27
14 changed files with 190 additions and 34 deletions

View file

@ -1,3 +1,22 @@
2004-03-21 Tim-Philipp Müller <t.i.m@zen.co.uk>
reviewed by Benjamin Otte <otte@gnome.org>
* gst/autoplug/gstspider.c: (gst_spider_dispose):
* gst/elements/gstaggregator.c: (gst_aggregator_finalize),
(gst_aggregator_class_init), (gst_aggregator_init):
* gst/elements/gstfilesrc.c: (gst_filesrc_init),
(gst_filesrc_dispose), (gst_filesrc_set_location):
* gst/elements/gstidentity.c: (gst_identity_finalize),
(gst_identity_class_init), (gst_identity_chain):
* gst/elements/gstmultifilesrc.c: (gst_multifilesrc_open_file):
* gst/elements/gststatistics.c: (gst_statistics_finalize),
(gst_statistics_class_init):
* gst/elements/gsttee.c: (gst_tee_finalize), (gst_tee_class_init),
(gst_tee_get_property):
clean up used memory in this elements correctly on teardown (closes
#137279)
2004-03-20 Colin Walters <walters@redhat.com>
* gst/registries/gstxmlregistry.c:

View file

@ -196,6 +196,7 @@ gst_spider_dispose (GObject * object)
spider = GST_SPIDER (object);
g_list_free (spider->factories);
spider->factories = NULL;
((GObjectClass *) parent_class)->dispose (object);
}

View file

@ -83,6 +83,7 @@ static GstPad *gst_aggregator_request_new_pad (GstElement * element,
GstPadTemplate * temp, const gchar * unused);
static void gst_aggregator_update_functions (GstAggregator * aggregator);
static void gst_aggregator_finalize (GObject * object);
static void gst_aggregator_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
static void gst_aggregator_get_property (GObject * object, guint prop_id,
@ -106,6 +107,20 @@ gst_aggregator_base_init (gpointer g_class)
gst_static_pad_template_get (&aggregator_src_template));
gst_element_class_set_details (gstelement_class, &gst_aggregator_details);
}
static void
gst_aggregator_finalize (GObject * object)
{
GstAggregator *aggregator;
aggregator = GST_AGGREGATOR (object);
g_list_free (aggregator->sinkpads);
g_free (aggregator->last_message);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gst_aggregator_class_init (GstAggregatorClass * klass)
{
@ -115,7 +130,6 @@ gst_aggregator_class_init (GstAggregatorClass * klass)
gobject_class = (GObjectClass *) klass;
gstelement_class = (GstElementClass *) klass;
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_NUM_PADS,
g_param_spec_int ("num_pads", "Num pads", "The number of source pads",
0, G_MAXINT, 0, G_PARAM_READABLE));
@ -130,6 +144,7 @@ gst_aggregator_class_init (GstAggregatorClass * klass)
g_param_spec_string ("last_message", "Last message",
"The current state of the element", NULL, G_PARAM_READABLE));
gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_aggregator_finalize);
gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_aggregator_set_property);
gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_aggregator_get_property);
@ -148,6 +163,7 @@ gst_aggregator_init (GstAggregator * aggregator)
aggregator->sinkpads = NULL;
aggregator->silent = FALSE;
aggregator->sched = AGGREGATOR_LOOP;
aggregator->last_message = NULL;
gst_aggregator_update_functions (aggregator);
}

View file

@ -233,6 +233,7 @@ gst_filesrc_init (GstFileSrc * src)
src->filename = NULL;
src->fd = 0;
src->filelen = 0;
src->uri = NULL;
src->curoffset = 0;
src->block_size = DEFAULT_BLOCKSIZE;
@ -251,12 +252,14 @@ gst_filesrc_dispose (GObject * object)
src = GST_FILESRC (object);
G_OBJECT_CLASS (parent_class)->dispose (object);
g_free (src->filename);
g_free (src->uri);
if (src->filename)
g_free (src->filename);
if (src->uri)
g_free (src->uri);
/* dispose may be called multiple times */
src->filename = NULL;
src->uri = NULL;
G_OBJECT_CLASS (parent_class)->dispose (object);
}
static gboolean
@ -266,10 +269,9 @@ gst_filesrc_set_location (GstFileSrc * src, const gchar * location)
if (GST_STATE (src) != GST_STATE_READY && GST_STATE (src) != GST_STATE_NULL)
return FALSE;
if (src->filename)
g_free (src->filename);
if (src->uri)
g_free (src->uri);
g_free (src->filename);
g_free (src->uri);
/* clear the filename if we get a NULL (is that possible?) */
if (location == NULL) {
src->filename = NULL;

View file

@ -68,6 +68,7 @@ enum
GST_BOILERPLATE_FULL (GstIdentity, gst_identity, GstElement, GST_TYPE_ELEMENT,
_do_init);
static void gst_identity_finalize (GObject * object);
static void gst_identity_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
static void gst_identity_get_property (GObject * object, guint prop_id,
@ -84,6 +85,19 @@ gst_identity_base_init (gpointer g_class)
gst_element_class_set_details (gstelement_class, &gst_identity_details);
}
static void
gst_identity_finalize (GObject * object)
{
GstIdentity *identity;
identity = GST_IDENTITY (object);
g_free (identity->last_message);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gst_identity_class_init (GstIdentityClass * klass)
{
@ -125,6 +139,7 @@ gst_identity_class_init (GstIdentityClass * klass)
G_STRUCT_OFFSET (GstIdentityClass, handoff), NULL, NULL,
gst_marshal_VOID__POINTER, G_TYPE_NONE, 1, GST_TYPE_BUFFER);
gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_identity_finalize);
gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_identity_set_property);
gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_identity_get_property);
}
@ -180,9 +195,7 @@ gst_identity_chain (GstPad * pad, GstData * _data)
if (identity->drop_probability > 0.0) {
if ((gfloat) (1.0 * rand () / (RAND_MAX)) < identity->drop_probability) {
if (identity->last_message != NULL) {
g_free (identity->last_message);
}
g_free (identity->last_message);
identity->last_message =
g_strdup_printf ("dropping ******* (%s:%s)i (%d bytes, %"
G_GINT64_FORMAT ")", GST_DEBUG_PAD_NAME (identity->sinkpad),

View file

@ -248,7 +248,7 @@ gst_multifilesrc_open_file (GstMultiFileSrc * src, GstPad * srcpad)
return FALSE;
}
/* open the file */
/* open the file. FIXME: do we need to use O_LARGEFILE here? */
src->fd = open ((const char *) src->currentfilename, O_RDONLY);
if (src->fd < 0) {
GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ,
@ -260,9 +260,12 @@ gst_multifilesrc_open_file (GstMultiFileSrc * src, GstPad * srcpad)
/* find the file length */
src->size = lseek (src->fd, 0, SEEK_END);
lseek (src->fd, 0, SEEK_SET);
/* map the file into memory */
/* map the file into memory.
* FIXME: don't map the whole file at once, there might
* be restrictions set. Get max size via getrlimit
* or re-try with smaller size if mmap fails with ENOMEM? */
src->map = mmap (NULL, src->size, PROT_READ, MAP_SHARED, src->fd, 0);
madvise (src->map, src->size, 2);
madvise (src->map, src->size, MADV_SEQUENTIAL);
/* collapse state if that failed */
if (src->map == NULL) {
close (src->fd);

View file

@ -64,6 +64,7 @@ enum
GST_BOILERPLATE_FULL (GstStatistics, gst_statistics, GstElement,
GST_TYPE_ELEMENT, _do_init);
static void gst_statistics_finalize (GObject * object);
static void gst_statistics_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
static void gst_statistics_get_property (GObject * object, guint prop_id,
@ -85,6 +86,23 @@ gst_statistics_base_init (gpointer g_class)
gst_element_class_set_details (gstelement_class, &gst_statistics_details);
}
static void
gst_statistics_finalize (GObject * object)
{
GstStatistics *statistics;
statistics = GST_STATISTICS (object);
if (statistics->timer)
g_timer_destroy (statistics->timer);
if (statistics->last_timer)
g_timer_destroy (statistics->last_timer);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gst_statistics_class_init (GstStatisticsClass * klass)
{
@ -129,6 +147,7 @@ gst_statistics_class_init (GstStatisticsClass * klass)
G_STRUCT_OFFSET (GstStatisticsClass, update), NULL, NULL,
g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_statistics_finalize);
gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_statistics_set_property);
gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_statistics_get_property);
}

View file

@ -66,6 +66,7 @@ GST_BOILERPLATE_FULL (GstTee, gst_tee, GstElement, GST_TYPE_ELEMENT, _do_init);
static GstPad *gst_tee_request_new_pad (GstElement * element,
GstPadTemplate * temp, const gchar * unused);
static void gst_tee_finalize (GObject * object);
static void gst_tee_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
static void gst_tee_get_property (GObject * object, guint prop_id,
@ -83,6 +84,19 @@ gst_tee_base_init (gpointer g_class)
gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get (&tee_src_template));
}
static void
gst_tee_finalize (GObject * object)
{
GstTee *tee;
tee = GST_TEE (object);
g_free (tee->last_message);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gst_tee_class_init (GstTeeClass * klass)
{
@ -104,6 +118,7 @@ gst_tee_class_init (GstTeeClass * klass)
NULL, G_PARAM_READABLE));
gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_tee_finalize);
gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_tee_set_property);
gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_tee_get_property);
@ -233,7 +248,7 @@ gst_tee_get_property (GObject * object, guint prop_id, GValue * value,
g_value_set_boolean (value, tee->silent);
break;
case ARG_LAST_MESSAGE:
g_value_set_string ((GValue *) value, tee->last_message);
g_value_set_string (value, tee->last_message);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);

View file

@ -83,6 +83,7 @@ static GstPad *gst_aggregator_request_new_pad (GstElement * element,
GstPadTemplate * temp, const gchar * unused);
static void gst_aggregator_update_functions (GstAggregator * aggregator);
static void gst_aggregator_finalize (GObject * object);
static void gst_aggregator_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
static void gst_aggregator_get_property (GObject * object, guint prop_id,
@ -106,6 +107,20 @@ gst_aggregator_base_init (gpointer g_class)
gst_static_pad_template_get (&aggregator_src_template));
gst_element_class_set_details (gstelement_class, &gst_aggregator_details);
}
static void
gst_aggregator_finalize (GObject * object)
{
GstAggregator *aggregator;
aggregator = GST_AGGREGATOR (object);
g_list_free (aggregator->sinkpads);
g_free (aggregator->last_message);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gst_aggregator_class_init (GstAggregatorClass * klass)
{
@ -115,7 +130,6 @@ gst_aggregator_class_init (GstAggregatorClass * klass)
gobject_class = (GObjectClass *) klass;
gstelement_class = (GstElementClass *) klass;
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_NUM_PADS,
g_param_spec_int ("num_pads", "Num pads", "The number of source pads",
0, G_MAXINT, 0, G_PARAM_READABLE));
@ -130,6 +144,7 @@ gst_aggregator_class_init (GstAggregatorClass * klass)
g_param_spec_string ("last_message", "Last message",
"The current state of the element", NULL, G_PARAM_READABLE));
gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_aggregator_finalize);
gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_aggregator_set_property);
gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_aggregator_get_property);
@ -148,6 +163,7 @@ gst_aggregator_init (GstAggregator * aggregator)
aggregator->sinkpads = NULL;
aggregator->silent = FALSE;
aggregator->sched = AGGREGATOR_LOOP;
aggregator->last_message = NULL;
gst_aggregator_update_functions (aggregator);
}

View file

@ -233,6 +233,7 @@ gst_filesrc_init (GstFileSrc * src)
src->filename = NULL;
src->fd = 0;
src->filelen = 0;
src->uri = NULL;
src->curoffset = 0;
src->block_size = DEFAULT_BLOCKSIZE;
@ -251,12 +252,14 @@ gst_filesrc_dispose (GObject * object)
src = GST_FILESRC (object);
G_OBJECT_CLASS (parent_class)->dispose (object);
g_free (src->filename);
g_free (src->uri);
if (src->filename)
g_free (src->filename);
if (src->uri)
g_free (src->uri);
/* dispose may be called multiple times */
src->filename = NULL;
src->uri = NULL;
G_OBJECT_CLASS (parent_class)->dispose (object);
}
static gboolean
@ -266,10 +269,9 @@ gst_filesrc_set_location (GstFileSrc * src, const gchar * location)
if (GST_STATE (src) != GST_STATE_READY && GST_STATE (src) != GST_STATE_NULL)
return FALSE;
if (src->filename)
g_free (src->filename);
if (src->uri)
g_free (src->uri);
g_free (src->filename);
g_free (src->uri);
/* clear the filename if we get a NULL (is that possible?) */
if (location == NULL) {
src->filename = NULL;

View file

@ -68,6 +68,7 @@ enum
GST_BOILERPLATE_FULL (GstIdentity, gst_identity, GstElement, GST_TYPE_ELEMENT,
_do_init);
static void gst_identity_finalize (GObject * object);
static void gst_identity_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
static void gst_identity_get_property (GObject * object, guint prop_id,
@ -84,6 +85,19 @@ gst_identity_base_init (gpointer g_class)
gst_element_class_set_details (gstelement_class, &gst_identity_details);
}
static void
gst_identity_finalize (GObject * object)
{
GstIdentity *identity;
identity = GST_IDENTITY (object);
g_free (identity->last_message);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gst_identity_class_init (GstIdentityClass * klass)
{
@ -125,6 +139,7 @@ gst_identity_class_init (GstIdentityClass * klass)
G_STRUCT_OFFSET (GstIdentityClass, handoff), NULL, NULL,
gst_marshal_VOID__POINTER, G_TYPE_NONE, 1, GST_TYPE_BUFFER);
gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_identity_finalize);
gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_identity_set_property);
gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_identity_get_property);
}
@ -180,9 +195,7 @@ gst_identity_chain (GstPad * pad, GstData * _data)
if (identity->drop_probability > 0.0) {
if ((gfloat) (1.0 * rand () / (RAND_MAX)) < identity->drop_probability) {
if (identity->last_message != NULL) {
g_free (identity->last_message);
}
g_free (identity->last_message);
identity->last_message =
g_strdup_printf ("dropping ******* (%s:%s)i (%d bytes, %"
G_GINT64_FORMAT ")", GST_DEBUG_PAD_NAME (identity->sinkpad),

View file

@ -248,7 +248,7 @@ gst_multifilesrc_open_file (GstMultiFileSrc * src, GstPad * srcpad)
return FALSE;
}
/* open the file */
/* open the file. FIXME: do we need to use O_LARGEFILE here? */
src->fd = open ((const char *) src->currentfilename, O_RDONLY);
if (src->fd < 0) {
GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ,
@ -260,9 +260,12 @@ gst_multifilesrc_open_file (GstMultiFileSrc * src, GstPad * srcpad)
/* find the file length */
src->size = lseek (src->fd, 0, SEEK_END);
lseek (src->fd, 0, SEEK_SET);
/* map the file into memory */
/* map the file into memory.
* FIXME: don't map the whole file at once, there might
* be restrictions set. Get max size via getrlimit
* or re-try with smaller size if mmap fails with ENOMEM? */
src->map = mmap (NULL, src->size, PROT_READ, MAP_SHARED, src->fd, 0);
madvise (src->map, src->size, 2);
madvise (src->map, src->size, MADV_SEQUENTIAL);
/* collapse state if that failed */
if (src->map == NULL) {
close (src->fd);

View file

@ -64,6 +64,7 @@ enum
GST_BOILERPLATE_FULL (GstStatistics, gst_statistics, GstElement,
GST_TYPE_ELEMENT, _do_init);
static void gst_statistics_finalize (GObject * object);
static void gst_statistics_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
static void gst_statistics_get_property (GObject * object, guint prop_id,
@ -85,6 +86,23 @@ gst_statistics_base_init (gpointer g_class)
gst_element_class_set_details (gstelement_class, &gst_statistics_details);
}
static void
gst_statistics_finalize (GObject * object)
{
GstStatistics *statistics;
statistics = GST_STATISTICS (object);
if (statistics->timer)
g_timer_destroy (statistics->timer);
if (statistics->last_timer)
g_timer_destroy (statistics->last_timer);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gst_statistics_class_init (GstStatisticsClass * klass)
{
@ -129,6 +147,7 @@ gst_statistics_class_init (GstStatisticsClass * klass)
G_STRUCT_OFFSET (GstStatisticsClass, update), NULL, NULL,
g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_statistics_finalize);
gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_statistics_set_property);
gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_statistics_get_property);
}

View file

@ -66,6 +66,7 @@ GST_BOILERPLATE_FULL (GstTee, gst_tee, GstElement, GST_TYPE_ELEMENT, _do_init);
static GstPad *gst_tee_request_new_pad (GstElement * element,
GstPadTemplate * temp, const gchar * unused);
static void gst_tee_finalize (GObject * object);
static void gst_tee_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
static void gst_tee_get_property (GObject * object, guint prop_id,
@ -83,6 +84,19 @@ gst_tee_base_init (gpointer g_class)
gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get (&tee_src_template));
}
static void
gst_tee_finalize (GObject * object)
{
GstTee *tee;
tee = GST_TEE (object);
g_free (tee->last_message);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gst_tee_class_init (GstTeeClass * klass)
{
@ -104,6 +118,7 @@ gst_tee_class_init (GstTeeClass * klass)
NULL, G_PARAM_READABLE));
gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_tee_finalize);
gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_tee_set_property);
gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_tee_get_property);
@ -233,7 +248,7 @@ gst_tee_get_property (GObject * object, guint prop_id, GValue * value,
g_value_set_boolean (value, tee->silent);
break;
case ARG_LAST_MESSAGE:
g_value_set_string ((GValue *) value, tee->last_message);
g_value_set_string (value, tee->last_message);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);