From 90d92814d47be8a0d5e1fdf12948ceec2086d338 Mon Sep 17 00:00:00 2001 From: Roland Kay Date: Thu, 14 Dec 2006 10:15:24 +0000 Subject: [PATCH] ext/lame/gstlame.*: Fix leak (by calling lame_init_params() before lame_close()); handle Original commit message from CVS: Based on patch by: Roland Kay * ext/lame/gstlame.c: (gst_lame_init), (gst_lame_chain), (gst_lame_setup): * ext/lame/gstlame.h: Fix leak (by calling lame_init_params() before lame_close()); handle NULL return from lame_init() more gracefully. Fixes #385311. --- ext/lame/gstlame.c | 30 ++++++++++++++++++++++++++++++ ext/lame/gstlame.h | 2 ++ 2 files changed, 32 insertions(+) diff --git a/ext/lame/gstlame.c b/ext/lame/gstlame.c index dfbebabee5..7e7d27fa9b 100644 --- a/ext/lame/gstlame.c +++ b/ext/lame/gstlame.c @@ -572,6 +572,11 @@ gst_lame_init (GstLame * lame) /* create an encoder state so we can ask about defaults */ lame->lgf = lame_init (); + if (lame->lgf == NULL) + goto init_error; + + if (lame_init_params (lame->lgf) < 0) + goto init_error; lame->samplerate = 44100; lame->num_channels = 2; @@ -623,6 +628,19 @@ gst_lame_init (GstLame * lame) lame->lgf = NULL; GST_DEBUG_OBJECT (lame, "done initializing"); + lame->init_error = FALSE; + return; + +/* ERRORS */ +init_error: + { + GST_ERROR_OBJECT (lame, "error initializing"); + lame->init_error = TRUE; + if (lame->lgf) { + lame_close (lame->lgf); + lame->lgf = NULL; + } + } } #define CHECK_AND_FIXUP_BITRATE(obj,pspec,rate) \ @@ -974,6 +992,9 @@ gst_lame_chain (GstPad * pad, GstBuffer * buf) GST_LOG_OBJECT (lame, "entered chain"); + if (lame->init_error) + goto init_error; + if (!lame->setup) goto not_setup; @@ -1062,6 +1083,12 @@ not_setup: ("encoder not initialized (input is not audio?)")); return GST_FLOW_ERROR; } +init_error: + { + gst_buffer_unref (buf); + GST_ELEMENT_ERROR (lame, LIBRARY, INIT, (NULL), (NULL)); + return GST_FLOW_ERROR; + } } /* set up the encoder state */ @@ -1088,6 +1115,9 @@ gst_lame_setup (GstLame * lame) lame->lgf = lame_init (); + if (lame->lgf == NULL) + return FALSE; + /* let lame choose a default samplerate */ lame_set_out_samplerate (lame->lgf, 0); diff --git a/ext/lame/gstlame.h b/ext/lame/gstlame.h index ebbc7e4d1e..71bfacc810 100644 --- a/ext/lame/gstlame.h +++ b/ext/lame/gstlame.h @@ -53,6 +53,8 @@ struct _GstLame { /*< private >*/ GstPad *srcpad, *sinkpad; + gboolean init_error; /* an error occured in the instance init function */ + gint samplerate; gint num_channels; gboolean setup;