From 0d697e8b58b10d41c20c8fbda87d9ed58291a8fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Tue, 11 Aug 2009 16:23:20 -0400 Subject: rtpdtmfsrc: Cleanup events on finalize Problem found by Laurent Glayal Fixes bug #591440 --- gst/dtmf/gstrtpdtmfsrc.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'gst/dtmf') diff --git a/gst/dtmf/gstrtpdtmfsrc.c b/gst/dtmf/gstrtpdtmfsrc.c index 738be59e..cdaa202a 100644 --- a/gst/dtmf/gstrtpdtmfsrc.c +++ b/gst/dtmf/gstrtpdtmfsrc.c @@ -301,6 +301,16 @@ gst_rtp_dtmf_src_class_init (GstRTPDTMFSrcClass * klass) gstbasesrc_class->negotiate = GST_DEBUG_FUNCPTR (gst_rtp_dtmf_src_negotiate); } +static void +gst_rtp_dtmf_src_event_free (GstRTPDTMFSrcEvent * event) +{ + if (event) { + g_free (event->payload); + event->payload = NULL; + g_free (event); + } +} + static void gst_rtp_dtmf_src_init (GstRTPDTMFSrc * object, GstRTPDTMFSrcClass * g_class) { @@ -315,7 +325,8 @@ gst_rtp_dtmf_src_init (GstRTPDTMFSrc * object, GstRTPDTMFSrcClass * g_class) object->interval = DEFAULT_PACKET_INTERVAL; object->packet_redundancy = DEFAULT_PACKET_REDUNDANCY; - object->event_queue = g_async_queue_new (); + object->event_queue = + g_async_queue_new_full ((GDestroyNotify) gst_rtp_dtmf_src_event_free); object->payload = NULL; GST_DEBUG_OBJECT (object, "init done"); @@ -997,7 +1008,7 @@ gst_rtp_dtmf_src_change_state (GstElement * element, GstStateChange transition) /* Flushing the event queue */ while ((event = g_async_queue_try_pop (dtmfsrc->event_queue)) != NULL) - g_free (event); + gst_rtp_dtmf_src_event_free (event); no_preroll = TRUE; break; @@ -1018,7 +1029,7 @@ gst_rtp_dtmf_src_change_state (GstElement * element, GstStateChange transition) /* Flushing the event queue */ while ((event = g_async_queue_try_pop (dtmfsrc->event_queue)) != NULL) - g_free (event); + gst_rtp_dtmf_src_event_free (event); /* Indicate that we don't do PRE_ROLL */ break; -- cgit v1.2.1 From a2ea288a0259c8c30bf8407b066d8edbdffdb954 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Tue, 11 Aug 2009 16:23:20 -0400 Subject: rtpdtmfsrc: Cleanup events on finalize Problem found by Laurent Glayal Fixes bug #591440 --- gst/dtmf/gstrtpdtmfsrc.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'gst/dtmf') diff --git a/gst/dtmf/gstrtpdtmfsrc.c b/gst/dtmf/gstrtpdtmfsrc.c index cdaa202a..b41c0c45 100644 --- a/gst/dtmf/gstrtpdtmfsrc.c +++ b/gst/dtmf/gstrtpdtmfsrc.c @@ -583,7 +583,7 @@ static void gst_rtp_dtmf_src_add_stop_event (GstRTPDTMFSrc * dtmfsrc) { - GstRTPDTMFSrcEvent *event = g_malloc (sizeof (GstRTPDTMFSrcEvent)); + GstRTPDTMFSrcEvent *event = g_new0 (GstRTPDTMFSrcEvent, 1); event->event_type = RTP_DTMF_EVENT_TYPE_STOP; g_async_queue_push (dtmfsrc->event_queue, event); @@ -701,6 +701,7 @@ gst_rtp_dtmf_src_create (GstBaseSrc * basesrc, guint64 offset, gst_rtp_dtmf_src_set_stream_lock (dtmfsrc, TRUE); dtmfsrc->payload = event->payload; + event->payload = NULL; break; case RTP_DTMF_EVENT_TYPE_PAUSE_TASK: @@ -717,7 +718,7 @@ gst_rtp_dtmf_src_create (GstBaseSrc * basesrc, guint64 offset, break; } - g_free (event); + gst_rtp_dtmf_src_event_free (event); } else if (!dtmfsrc->first_packet && !dtmfsrc->last_packet && (dtmfsrc->timestamp - dtmfsrc->start_timestamp) / GST_MSECOND >= MIN_PULSE_DURATION) { @@ -755,7 +756,7 @@ gst_rtp_dtmf_src_create (GstBaseSrc * basesrc, guint64 offset, GST_OBJECT_UNLOCK (dtmfsrc); break; } - g_free (event); + gst_rtp_dtmf_src_event_free (event); } } } while (dtmfsrc->payload == NULL); @@ -1068,7 +1069,7 @@ gst_rtp_dtmf_src_unlock (GstBaseSrc * src) GST_OBJECT_UNLOCK (dtmfsrc); GST_DEBUG_OBJECT (dtmfsrc, "Pushing the PAUSE_TASK event on unlock request"); - event = g_malloc (sizeof (GstRTPDTMFSrcEvent)); + event = g_new0 (GstRTPDTMFSrcEvent, 1); event->event_type = RTP_DTMF_EVENT_TYPE_PAUSE_TASK; g_async_queue_push (dtmfsrc->event_queue, event); -- cgit v1.2.1 From 329b7b9849daf784afb6e43fdf2e5dd7ea396e7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Cr=C3=AAte?= Date: Tue, 11 Aug 2009 16:39:42 -0400 Subject: dtmf: Use GSlice for internal event structures --- gst/dtmf/gstdtmfsrc.c | 18 +++++++++--------- gst/dtmf/gstrtpdtmfsrc.c | 16 ++++++++-------- 2 files changed, 17 insertions(+), 17 deletions(-) (limited to 'gst/dtmf') diff --git a/gst/dtmf/gstdtmfsrc.c b/gst/dtmf/gstdtmfsrc.c index 8595adf8..4115395d 100644 --- a/gst/dtmf/gstdtmfsrc.c +++ b/gst/dtmf/gstdtmfsrc.c @@ -482,7 +482,7 @@ gst_dtmf_src_add_start_event (GstDTMFSrc * dtmfsrc, gint event_number, gint event_volume) { - GstDTMFSrcEvent *event = g_malloc (sizeof (GstDTMFSrcEvent)); + GstDTMFSrcEvent *event = g_slice_new0 (GstDTMFSrcEvent); event->event_type = DTMF_EVENT_TYPE_START; event->sample = 0; event->event_number = CLAMP (event_number, MIN_EVENT, MAX_EVENT); @@ -495,7 +495,7 @@ static void gst_dtmf_src_add_stop_event (GstDTMFSrc * dtmfsrc) { - GstDTMFSrcEvent *event = g_malloc (sizeof (GstDTMFSrcEvent)); + GstDTMFSrcEvent *event = g_slice_new0 (GstDTMFSrcEvent); event->event_type = DTMF_EVENT_TYPE_STOP; event->sample = 0; event->event_number = 0; @@ -658,7 +658,7 @@ gst_dtmf_src_create (GstBaseSrc * basesrc, guint64 offset, break; } if (event) - g_free (event); + g_slice_free (GstDTMFSrcEvent, event); } else if (dtmfsrc->last_event->packet_count * dtmfsrc->interval >= MIN_DUTY_CYCLE) { event = g_async_queue_try_pop (dtmfsrc->event_queue); @@ -673,7 +673,7 @@ gst_dtmf_src_create (GstBaseSrc * basesrc, guint64 offset, case DTMF_EVENT_TYPE_STOP: gst_dtmf_src_set_stream_lock (dtmfsrc, FALSE); - g_free (dtmfsrc->last_event); + g_slice_free (GstDTMFSrcEvent, dtmfsrc->last_event); dtmfsrc->last_event = NULL; break; case DTMF_EVENT_TYPE_PAUSE_TASK: @@ -692,7 +692,7 @@ gst_dtmf_src_create (GstBaseSrc * basesrc, guint64 offset, break; } - g_free (event); + g_slice_free (GstDTMFSrcEvent, event); } } } while (dtmfsrc->last_event == NULL); @@ -748,7 +748,7 @@ paused: GST_DEBUG_OBJECT (dtmfsrc, "Stopping current event"); /* Don't forget to release the stream lock */ gst_dtmf_src_set_stream_lock (dtmfsrc, FALSE); - g_free (dtmfsrc->last_event); + g_slice_free (GstDTMFSrcEvent, dtmfsrc->last_event); dtmfsrc->last_event = NULL; } @@ -772,7 +772,7 @@ gst_dtmf_src_unlock (GstBaseSrc * src) GST_OBJECT_UNLOCK (dtmfsrc); GST_DEBUG_OBJECT (dtmfsrc, "Pushing the PAUSE_TASK event on unlock request"); - event = g_malloc (sizeof (GstDTMFSrcEvent)); + event = g_slice_new0 (GstDTMFSrcEvent); event->event_type = DTMF_EVENT_TYPE_PAUSE_TASK; g_async_queue_push (dtmfsrc->event_queue, event); @@ -875,7 +875,7 @@ gst_dtmf_src_change_state (GstElement * element, GstStateChange transition) event = g_async_queue_try_pop (dtmfsrc->event_queue); while (event != NULL) { - g_free (event); + g_slice_free (GstDTMFSrcEvent, event); event = g_async_queue_try_pop (dtmfsrc->event_queue); } no_preroll = TRUE; @@ -899,7 +899,7 @@ gst_dtmf_src_change_state (GstElement * element, GstStateChange transition) event = g_async_queue_try_pop (dtmfsrc->event_queue); while (event != NULL) { - g_free (event); + g_slice_free (GstDTMFSrcEvent, event); event = g_async_queue_try_pop (dtmfsrc->event_queue); } diff --git a/gst/dtmf/gstrtpdtmfsrc.c b/gst/dtmf/gstrtpdtmfsrc.c index b41c0c45..65d0ce8c 100644 --- a/gst/dtmf/gstrtpdtmfsrc.c +++ b/gst/dtmf/gstrtpdtmfsrc.c @@ -305,9 +305,9 @@ static void gst_rtp_dtmf_src_event_free (GstRTPDTMFSrcEvent * event) { if (event) { - g_free (event->payload); - event->payload = NULL; - g_free (event); + if (event->payload) + g_slice_free (GstRTPDTMFPayload, event->payload); + g_slice_free (GstRTPDTMFSrcEvent, event); } } @@ -568,10 +568,10 @@ gst_rtp_dtmf_src_add_start_event (GstRTPDTMFSrc * dtmfsrc, gint event_number, gint event_volume) { - GstRTPDTMFSrcEvent *event = g_malloc (sizeof (GstRTPDTMFSrcEvent)); + GstRTPDTMFSrcEvent *event = g_slice_new0 (GstRTPDTMFSrcEvent); event->event_type = RTP_DTMF_EVENT_TYPE_START; - event->payload = g_new0 (GstRTPDTMFPayload, 1); + event->payload = g_slice_new0 (GstRTPDTMFPayload); event->payload->event = CLAMP (event_number, MIN_EVENT, MAX_EVENT); event->payload->volume = CLAMP (event_volume, MIN_VOLUME, MAX_VOLUME); event->payload->duration = dtmfsrc->interval * dtmfsrc->clock_rate / 1000; @@ -583,7 +583,7 @@ static void gst_rtp_dtmf_src_add_stop_event (GstRTPDTMFSrc * dtmfsrc) { - GstRTPDTMFSrcEvent *event = g_new0 (GstRTPDTMFSrcEvent, 1); + GstRTPDTMFSrcEvent *event = g_slice_new0 (GstRTPDTMFSrcEvent); event->event_type = RTP_DTMF_EVENT_TYPE_STOP; g_async_queue_push (dtmfsrc->event_queue, event); @@ -816,7 +816,7 @@ send_last: /* Don't forget to release the stream lock */ gst_rtp_dtmf_src_set_stream_lock (dtmfsrc, FALSE); - g_free (dtmfsrc->payload); + g_slice_free (GstRTPDTMFPayload, dtmfsrc->payload); dtmfsrc->payload = NULL; dtmfsrc->last_packet = FALSE; @@ -1069,7 +1069,7 @@ gst_rtp_dtmf_src_unlock (GstBaseSrc * src) GST_OBJECT_UNLOCK (dtmfsrc); GST_DEBUG_OBJECT (dtmfsrc, "Pushing the PAUSE_TASK event on unlock request"); - event = g_new0 (GstRTPDTMFSrcEvent, 1); + event = g_slice_new0 (GstRTPDTMFSrcEvent); event->event_type = RTP_DTMF_EVENT_TYPE_PAUSE_TASK; g_async_queue_push (dtmfsrc->event_queue, event); -- cgit v1.2.1 From 402aad7e871ab242ef16c8c715c50e5a2c236f9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Cr=C3=AAte?= Date: Tue, 11 Aug 2009 16:42:51 -0400 Subject: dtmfsrc: Empty event queue on finalize --- gst/dtmf/gstdtmfsrc.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'gst/dtmf') diff --git a/gst/dtmf/gstdtmfsrc.c b/gst/dtmf/gstdtmfsrc.c index 4115395d..7a1f14b2 100644 --- a/gst/dtmf/gstdtmfsrc.c +++ b/gst/dtmf/gstdtmfsrc.c @@ -287,6 +287,12 @@ gst_dtmf_src_class_init (GstDTMFSrcClass * klass) gstbasesrc_class->negotiate = GST_DEBUG_FUNCPTR (gst_dtmf_src_negotiate); } +static void +event_free (GstDTMFSrcEvent * event) +{ + if (event) + g_slice_free (GstDTMFSrcEvent, event); +} static void gst_dtmf_src_init (GstDTMFSrc * dtmfsrc, GstDTMFSrcClass * g_class) @@ -297,7 +303,7 @@ gst_dtmf_src_init (GstDTMFSrc * dtmfsrc, GstDTMFSrcClass * g_class) dtmfsrc->interval = DEFAULT_PACKET_INTERVAL; - dtmfsrc->event_queue = g_async_queue_new (); + dtmfsrc->event_queue = g_async_queue_new_full ((GDestroyNotify) event_free); dtmfsrc->last_event = NULL; dtmfsrc->sample_rate = DEFAULT_SAMPLE_RATE; -- cgit v1.2.1