1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-24 07:42:17 +00:00

ad_ffmpeg: free resources on init failure

ad_ffmpeg init() function did not free resources if opening failed.
Outside code (dec_audio.c) does not automatically call uninit() if
init() returns failure, and the uninit function would have crashed in
some cases had it been called (it did freed lavc_context->extradata,
but lavc_context could have been NULL after early init failure). Add
explicit calls to uninit() after failure and make uninit function safe
to call at any point.
This commit is contained in:
Uoti Urpala 2011-08-21 23:04:20 +03:00
parent 68df2b2b3f
commit a24e333fca

View File

@ -157,6 +157,7 @@ static int init(sh_audio_t *sh_audio)
/* open it */
if (avcodec_open(lavc_context, lavc_codec) < 0) {
mp_tmsg(MSGT_DECAUDIO, MSGL_ERR, "Could not open codec.\n");
uninit(sh_audio);
return 0;
}
mp_msg(MSGT_DECAUDIO, MSGL_V, "INFO: libavcodec \"%s\" init OK!\n",
@ -183,6 +184,7 @@ static int init(sh_audio_t *sh_audio)
if (++tries >= 5) {
mp_msg(MSGT_DECAUDIO, MSGL_ERR,
"ad_ffmpeg: initial decode failed\n");
uninit(sh_audio);
return 0;
}
}
@ -198,6 +200,7 @@ static int init(sh_audio_t *sh_audio)
case SAMPLE_FMT_FLT:
break;
default:
uninit(sh_audio);
return 0;
}
return 1;
@ -206,13 +209,18 @@ static int init(sh_audio_t *sh_audio)
static void uninit(sh_audio_t *sh)
{
struct priv *ctx = sh->context;
if (!ctx)
return;
AVCodecContext *lavc_context = ctx->avctx;
if (avcodec_close(lavc_context) < 0)
mp_tmsg(MSGT_DECVIDEO, MSGL_ERR, "Could not close codec.\n");
av_freep(&lavc_context->extradata);
av_freep(&lavc_context);
if (lavc_context) {
if (avcodec_close(lavc_context) < 0)
mp_tmsg(MSGT_DECVIDEO, MSGL_ERR, "Could not close codec.\n");
av_freep(&lavc_context->extradata);
av_freep(&lavc_context);
}
talloc_free(ctx);
sh->context = NULL;
}
static int control(sh_audio_t *sh, int cmd, void *arg, ...)