gst-libav: fix context leaks

A AVCodecContext needs cleaning up before being freed.
Go through all of the allocations/setups to ensure none of them
can leak a context or its contents.
This commit is contained in:
Vincent Penquerc'h 2014-01-15 09:02:33 +00:00
parent ead14945aa
commit ca1b5d8576
6 changed files with 15 additions and 3 deletions

View file

@ -150,9 +150,11 @@ gst_ffmpegauddec_finalize (GObject * object)
{ {
GstFFMpegAudDec *ffmpegdec = (GstFFMpegAudDec *) object; GstFFMpegAudDec *ffmpegdec = (GstFFMpegAudDec *) object;
if (ffmpegdec->context != NULL) if (ffmpegdec->context != NULL) {
gst_ffmpeg_avcodec_close (ffmpegdec->context);
av_free (ffmpegdec->context); av_free (ffmpegdec->context);
ffmpegdec->context = NULL; ffmpegdec->context = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object); G_OBJECT_CLASS (parent_class)->finalize (object);
} }
@ -199,6 +201,7 @@ gst_ffmpegauddec_start (GstAudioDecoder * decoder)
oclass = (GstFFMpegAudDecClass *) (G_OBJECT_GET_CLASS (ffmpegdec)); oclass = (GstFFMpegAudDecClass *) (G_OBJECT_GET_CLASS (ffmpegdec));
GST_OBJECT_LOCK (ffmpegdec); GST_OBJECT_LOCK (ffmpegdec);
gst_ffmpeg_avcodec_close (ffmpegdec->context);
if (avcodec_get_context_defaults3 (ffmpegdec->context, oclass->in_plugin) < 0) { if (avcodec_get_context_defaults3 (ffmpegdec->context, oclass->in_plugin) < 0) {
GST_DEBUG_OBJECT (ffmpegdec, "Failed to set context defaults"); GST_DEBUG_OBJECT (ffmpegdec, "Failed to set context defaults");
GST_OBJECT_UNLOCK (ffmpegdec); GST_OBJECT_UNLOCK (ffmpegdec);

View file

@ -191,6 +191,7 @@ gst_ffmpegaudenc_finalize (GObject * object)
GstFFMpegAudEnc *ffmpegaudenc = (GstFFMpegAudEnc *) object; GstFFMpegAudEnc *ffmpegaudenc = (GstFFMpegAudEnc *) object;
/* clean up remaining allocated data */ /* clean up remaining allocated data */
gst_ffmpeg_avcodec_close (ffmpegaudenc->context);
av_free (ffmpegaudenc->context); av_free (ffmpegaudenc->context);
G_OBJECT_CLASS (parent_class)->finalize (object); G_OBJECT_CLASS (parent_class)->finalize (object);
@ -203,6 +204,7 @@ gst_ffmpegaudenc_start (GstAudioEncoder * encoder)
GstFFMpegAudEncClass *oclass = GstFFMpegAudEncClass *oclass =
(GstFFMpegAudEncClass *) G_OBJECT_GET_CLASS (ffmpegaudenc); (GstFFMpegAudEncClass *) G_OBJECT_GET_CLASS (ffmpegaudenc);
gst_ffmpeg_avcodec_close (ffmpegaudenc->context);
if (avcodec_get_context_defaults3 (ffmpegaudenc->context, if (avcodec_get_context_defaults3 (ffmpegaudenc->context,
oclass->in_plugin) < 0) { oclass->in_plugin) < 0) {
GST_DEBUG_OBJECT (ffmpegaudenc, "Failed to set context defaults"); GST_DEBUG_OBJECT (ffmpegaudenc, "Failed to set context defaults");

View file

@ -827,9 +827,11 @@ gst_ffmpeg_cfg_install_property (GstFFMpegVidEncClass * klass, guint base)
} }
} }
if (ctx) if (ctx) {
gst_ffmpeg_avcodec_close (ctx);
av_free (ctx); av_free (ctx);
} }
}
/* returns TRUE if it is a known property for this config system, /* returns TRUE if it is a known property for this config system,
* FALSE otherwise */ * FALSE otherwise */

View file

@ -209,6 +209,7 @@ gst_ffmpegdeinterlace_sink_setcaps (GstPad * pad, GstCaps * caps)
ctx->pix_fmt = PIX_FMT_NB; ctx->pix_fmt = PIX_FMT_NB;
gst_ffmpeg_caps_with_codectype (AVMEDIA_TYPE_VIDEO, caps, ctx); gst_ffmpeg_caps_with_codectype (AVMEDIA_TYPE_VIDEO, caps, ctx);
if (ctx->pix_fmt == PIX_FMT_NB) { if (ctx->pix_fmt == PIX_FMT_NB) {
gst_ffmpeg_avcodec_close (ctx);
av_free (ctx); av_free (ctx);
return FALSE; return FALSE;
} }

View file

@ -268,6 +268,7 @@ gst_ffmpegviddec_finalize (GObject * object)
GstFFMpegVidDec *ffmpegdec = (GstFFMpegVidDec *) object; GstFFMpegVidDec *ffmpegdec = (GstFFMpegVidDec *) object;
if (ffmpegdec->context != NULL) { if (ffmpegdec->context != NULL) {
gst_ffmpeg_avcodec_close (ffmpegdec->context);
av_free (ffmpegdec->context); av_free (ffmpegdec->context);
ffmpegdec->context = NULL; ffmpegdec->context = NULL;
} }
@ -1591,6 +1592,7 @@ gst_ffmpegviddec_start (GstVideoDecoder * decoder)
oclass = (GstFFMpegVidDecClass *) (G_OBJECT_GET_CLASS (ffmpegdec)); oclass = (GstFFMpegVidDecClass *) (G_OBJECT_GET_CLASS (ffmpegdec));
GST_OBJECT_LOCK (ffmpegdec); GST_OBJECT_LOCK (ffmpegdec);
gst_ffmpeg_avcodec_close (ffmpegdec->context);
if (avcodec_get_context_defaults3 (ffmpegdec->context, oclass->in_plugin) < 0) { if (avcodec_get_context_defaults3 (ffmpegdec->context, oclass->in_plugin) < 0) {
GST_DEBUG_OBJECT (ffmpegdec, "Failed to set context defaults"); GST_DEBUG_OBJECT (ffmpegdec, "Failed to set context defaults");
GST_OBJECT_UNLOCK (ffmpegdec); GST_OBJECT_UNLOCK (ffmpegdec);

View file

@ -263,6 +263,7 @@ gst_ffmpegvidenc_finalize (GObject * object)
gst_ffmpeg_cfg_finalize (ffmpegenc); gst_ffmpeg_cfg_finalize (ffmpegenc);
/* clean up remaining allocated data */ /* clean up remaining allocated data */
gst_ffmpeg_avcodec_close (ffmpegenc->context);
av_free (ffmpegenc->context); av_free (ffmpegenc->context);
avcodec_free_frame (&ffmpegenc->picture); avcodec_free_frame (&ffmpegenc->picture);
@ -794,6 +795,7 @@ gst_ffmpegvidenc_start (GstVideoEncoder * encoder)
(GstFFMpegVidEncClass *) G_OBJECT_GET_CLASS (ffmpegenc); (GstFFMpegVidEncClass *) G_OBJECT_GET_CLASS (ffmpegenc);
/* close old session */ /* close old session */
gst_ffmpeg_avcodec_close (ffmpegenc->context);
if (avcodec_get_context_defaults3 (ffmpegenc->context, oclass->in_plugin) < 0) { if (avcodec_get_context_defaults3 (ffmpegenc->context, oclass->in_plugin) < 0) {
GST_DEBUG_OBJECT (ffmpegenc, "Failed to set context defaults"); GST_DEBUG_OBJECT (ffmpegenc, "Failed to set context defaults");
return FALSE; return FALSE;