From 92e5c5a85ae39d23704afa52ab8795f2dc125a7b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim-Philipp=20M=C3=BCller?= Date: Wed, 6 Mar 2019 23:45:27 +0000 Subject: [PATCH] closedcaption: cea708decoder: fix some memory leaks --- ext/closedcaption/gstcea708decoder.c | 22 ++++++++++++++++++++++ ext/closedcaption/gstcea708decoder.h | 3 +++ ext/closedcaption/gstceaccoverlay.c | 3 +++ 3 files changed, 28 insertions(+) diff --git a/ext/closedcaption/gstcea708decoder.c b/ext/closedcaption/gstcea708decoder.c index fac1546..774a48f 100644 --- a/ext/closedcaption/gstcea708decoder.c +++ b/ext/closedcaption/gstcea708decoder.c @@ -123,6 +123,7 @@ gst_cea708dec_clear_window_text (Cea708Dec * decoder, guint window_id); static void gst_cea708dec_scroll_window_up (Cea708Dec * decoder, guint window_id); static void gst_cea708dec_init_window (Cea708Dec * decoder, guint window_id); +static void gst_cea708dec_clear_window (Cea708Dec * decoder, cea708Window * w); static void gst_cea708dec_set_pen_attributes (Cea708Dec * decoder, guint8 * dtvcc_buffer, int index); @@ -175,6 +176,20 @@ gst_cea708dec_create (PangoContext * pango_context) } void +gst_cea708dec_free (Cea708Dec * dec) +{ + int i; + + for (i = 0; i < MAX_708_WINDOWS; i++) { + cea708Window *window = dec->cc_windows[i]; + gst_cea708dec_clear_window (dec, window); + g_free (window); + } + memset (dec, 0, sizeof (Cea708Dec)); + g_free (dec); +} + +void gst_cea708dec_set_service_number (Cea708Dec * decoder, gint8 desired_service) { int i = 0; @@ -1299,6 +1314,13 @@ gst_cea708dec_scroll_window_up (Cea708Dec * decoder, guint window_id) } static void +gst_cea708dec_clear_window (Cea708Dec * decoder, cea708Window * window) +{ + g_free (window->text_image); + memset (window, 0, sizeof (cea708Window)); +} + +static void gst_cea708dec_init_window (Cea708Dec * decoder, guint window_id) { cea708Window *window = decoder->cc_windows[window_id]; diff --git a/ext/closedcaption/gstcea708decoder.h b/ext/closedcaption/gstcea708decoder.h index 2d0609c..0a29b25 100644 --- a/ext/closedcaption/gstcea708decoder.h +++ b/ext/closedcaption/gstcea708decoder.h @@ -473,6 +473,9 @@ struct _Cea708Dec }; Cea708Dec *gst_cea708dec_create (PangoContext * pango_context); + +void gst_cea708dec_free (Cea708Dec *dec); + void gst_cea708dec_set_service_number (Cea708Dec * decoder, gint8 desired_service); gboolean diff --git a/ext/closedcaption/gstceaccoverlay.c b/ext/closedcaption/gstceaccoverlay.c index 1fd38d9..0b02d41 100644 --- a/ext/closedcaption/gstceaccoverlay.c +++ b/ext/closedcaption/gstceaccoverlay.c @@ -301,6 +301,9 @@ gst_cea_cc_overlay_finalize (GObject * object) overlay->next_composition = NULL; } + gst_cea708dec_free (overlay->decoder); + overlay->decoder = NULL; + g_mutex_clear (&overlay->lock); g_cond_clear (&overlay->cond); -- 2.7.4