mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-23 10:11:08 +00:00
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:
parent
ead14945aa
commit
ca1b5d8576
6 changed files with 15 additions and 3 deletions
|
@ -150,9 +150,11 @@ gst_ffmpegauddec_finalize (GObject * object)
|
|||
{
|
||||
GstFFMpegAudDec *ffmpegdec = (GstFFMpegAudDec *) object;
|
||||
|
||||
if (ffmpegdec->context != NULL)
|
||||
if (ffmpegdec->context != NULL) {
|
||||
gst_ffmpeg_avcodec_close (ffmpegdec->context);
|
||||
av_free (ffmpegdec->context);
|
||||
ffmpegdec->context = NULL;
|
||||
ffmpegdec->context = NULL;
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
||||
}
|
||||
|
@ -199,6 +201,7 @@ gst_ffmpegauddec_start (GstAudioDecoder * decoder)
|
|||
oclass = (GstFFMpegAudDecClass *) (G_OBJECT_GET_CLASS (ffmpegdec));
|
||||
|
||||
GST_OBJECT_LOCK (ffmpegdec);
|
||||
gst_ffmpeg_avcodec_close (ffmpegdec->context);
|
||||
if (avcodec_get_context_defaults3 (ffmpegdec->context, oclass->in_plugin) < 0) {
|
||||
GST_DEBUG_OBJECT (ffmpegdec, "Failed to set context defaults");
|
||||
GST_OBJECT_UNLOCK (ffmpegdec);
|
||||
|
|
|
@ -191,6 +191,7 @@ gst_ffmpegaudenc_finalize (GObject * object)
|
|||
GstFFMpegAudEnc *ffmpegaudenc = (GstFFMpegAudEnc *) object;
|
||||
|
||||
/* clean up remaining allocated data */
|
||||
gst_ffmpeg_avcodec_close (ffmpegaudenc->context);
|
||||
av_free (ffmpegaudenc->context);
|
||||
|
||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
||||
|
@ -203,6 +204,7 @@ gst_ffmpegaudenc_start (GstAudioEncoder * encoder)
|
|||
GstFFMpegAudEncClass *oclass =
|
||||
(GstFFMpegAudEncClass *) G_OBJECT_GET_CLASS (ffmpegaudenc);
|
||||
|
||||
gst_ffmpeg_avcodec_close (ffmpegaudenc->context);
|
||||
if (avcodec_get_context_defaults3 (ffmpegaudenc->context,
|
||||
oclass->in_plugin) < 0) {
|
||||
GST_DEBUG_OBJECT (ffmpegaudenc, "Failed to set context defaults");
|
||||
|
|
|
@ -827,8 +827,10 @@ gst_ffmpeg_cfg_install_property (GstFFMpegVidEncClass * klass, guint base)
|
|||
}
|
||||
}
|
||||
|
||||
if (ctx)
|
||||
if (ctx) {
|
||||
gst_ffmpeg_avcodec_close (ctx);
|
||||
av_free (ctx);
|
||||
}
|
||||
}
|
||||
|
||||
/* returns TRUE if it is a known property for this config system,
|
||||
|
|
|
@ -209,6 +209,7 @@ gst_ffmpegdeinterlace_sink_setcaps (GstPad * pad, GstCaps * caps)
|
|||
ctx->pix_fmt = PIX_FMT_NB;
|
||||
gst_ffmpeg_caps_with_codectype (AVMEDIA_TYPE_VIDEO, caps, ctx);
|
||||
if (ctx->pix_fmt == PIX_FMT_NB) {
|
||||
gst_ffmpeg_avcodec_close (ctx);
|
||||
av_free (ctx);
|
||||
return FALSE;
|
||||
}
|
||||
|
|
|
@ -268,6 +268,7 @@ gst_ffmpegviddec_finalize (GObject * object)
|
|||
GstFFMpegVidDec *ffmpegdec = (GstFFMpegVidDec *) object;
|
||||
|
||||
if (ffmpegdec->context != NULL) {
|
||||
gst_ffmpeg_avcodec_close (ffmpegdec->context);
|
||||
av_free (ffmpegdec->context);
|
||||
ffmpegdec->context = NULL;
|
||||
}
|
||||
|
@ -1591,6 +1592,7 @@ gst_ffmpegviddec_start (GstVideoDecoder * decoder)
|
|||
oclass = (GstFFMpegVidDecClass *) (G_OBJECT_GET_CLASS (ffmpegdec));
|
||||
|
||||
GST_OBJECT_LOCK (ffmpegdec);
|
||||
gst_ffmpeg_avcodec_close (ffmpegdec->context);
|
||||
if (avcodec_get_context_defaults3 (ffmpegdec->context, oclass->in_plugin) < 0) {
|
||||
GST_DEBUG_OBJECT (ffmpegdec, "Failed to set context defaults");
|
||||
GST_OBJECT_UNLOCK (ffmpegdec);
|
||||
|
|
|
@ -263,6 +263,7 @@ gst_ffmpegvidenc_finalize (GObject * object)
|
|||
gst_ffmpeg_cfg_finalize (ffmpegenc);
|
||||
|
||||
/* clean up remaining allocated data */
|
||||
gst_ffmpeg_avcodec_close (ffmpegenc->context);
|
||||
av_free (ffmpegenc->context);
|
||||
avcodec_free_frame (&ffmpegenc->picture);
|
||||
|
||||
|
@ -794,6 +795,7 @@ gst_ffmpegvidenc_start (GstVideoEncoder * encoder)
|
|||
(GstFFMpegVidEncClass *) G_OBJECT_GET_CLASS (ffmpegenc);
|
||||
|
||||
/* close old session */
|
||||
gst_ffmpeg_avcodec_close (ffmpegenc->context);
|
||||
if (avcodec_get_context_defaults3 (ffmpegenc->context, oclass->in_plugin) < 0) {
|
||||
GST_DEBUG_OBJECT (ffmpegenc, "Failed to set context defaults");
|
||||
return FALSE;
|
||||
|
|
Loading…
Reference in a new issue