From 16db86c1be4e4328c09746a4f63ecc438e6c185f Mon Sep 17 00:00:00 2001 From: Edward Hervey Date: Mon, 7 Dec 2015 13:36:29 +0100 Subject: [PATCH] teletextdec: Fix leak and NULL pointer usage Coverity CID #1341744 --- ext/teletextdec/gstteletextdec.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/ext/teletextdec/gstteletextdec.c b/ext/teletextdec/gstteletextdec.c index 5f3bb3aad7..864b33e4c2 100644 --- a/ext/teletextdec/gstteletextdec.c +++ b/ext/teletextdec/gstteletextdec.c @@ -178,6 +178,7 @@ static gboolean gst_teletextdec_extract_data_units (GstTeletextDec * static void gst_teletextdec_zvbi_init (GstTeletextDec * teletext); static void gst_teletextdec_zvbi_clear (GstTeletextDec * teletext); +static void gst_teletextdec_reset_frame (GstTeletextDec * teletext); /* initialize the gstteletext's class */ static void @@ -273,10 +274,7 @@ gst_teletextdec_init (GstTeletextDec * teletext) teletext->queue = NULL; g_mutex_init (&teletext->queue_lock); - teletext->frame = g_new0 (GstTeletextFrame, 1); - teletext->frame->sliced_begin = g_new (vbi_sliced, MAX_SLICES); - teletext->frame->current_slice = teletext->frame->sliced_begin; - teletext->frame->sliced_end = teletext->frame->sliced_begin + MAX_SLICES; + gst_teletextdec_reset_frame (teletext); teletext->last_ts = 0; @@ -326,6 +324,8 @@ gst_teletextdec_zvbi_clear (GstTeletextDec * teletext) teletext->decoder = NULL; } if (teletext->frame != NULL) { + if (teletext->frame->sliced_begin) + g_free (teletext->frame->sliced_begin); g_free (teletext->frame); teletext->frame = NULL; } @@ -500,6 +500,10 @@ gst_teletextdec_change_state (GstElement * element, GstStateChange transition) static void gst_teletextdec_reset_frame (GstTeletextDec * teletext) { + if (teletext->frame == NULL) + teletext->frame = g_new0 (GstTeletextFrame, 1); + if (teletext->frame->sliced_begin == NULL) + teletext->frame->sliced_begin = g_new (vbi_sliced, MAX_SLICES); teletext->frame->current_slice = teletext->frame->sliced_begin; teletext->frame->sliced_end = teletext->frame->sliced_begin + MAX_SLICES; teletext->frame->last_field = 0; @@ -518,9 +522,8 @@ gst_teletextdec_process_telx_buffer (GstTeletextDec * teletext, GstBuffer * buf) teletext->in_timestamp = GST_BUFFER_TIMESTAMP (buf); teletext->in_duration = GST_BUFFER_DURATION (buf); - if (teletext->frame == NULL) { + if (teletext->frame == NULL) gst_teletextdec_reset_frame (teletext); - } while (offset < buf_map.size) { res = @@ -820,13 +823,6 @@ fetch_page_failed: return GST_FLOW_ERROR; } -alloc_failed: - { - GST_ERROR_OBJECT (teletext, "Error allocating output buffer, reason %s", - gst_flow_get_name (ret)); - return ret; - } - push_failed: { GST_ERROR_OBJECT (teletext, "Pushing buffer failed, reason %s", -- 2.34.1