mirror of https://git.ffmpeg.org/ffmpeg.git
avformat: call AVOutputFormat->deinit() when freeing the context
Despite the doxy stating that it's called when the muxer is destroyed, this was not true in practice. It's only called by av_write_trailer() and on init() failure. An AVFormatContext may be closed without writing the trailer if errors ocurred while muxing packets, so in order to prevent memory leaks, it should effectively be called when freeing the muxer. Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
parent
27bae5aaca
commit
02cf239196
|
@ -485,6 +485,14 @@ static void flush_if_needed(AVFormatContext *s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void deinit_muxer(AVFormatContext *s)
|
||||||
|
{
|
||||||
|
if (s->oformat && s->oformat->deinit && s->internal->initialized)
|
||||||
|
s->oformat->deinit(s);
|
||||||
|
s->internal->initialized =
|
||||||
|
s->internal->streams_initialized = 0;
|
||||||
|
}
|
||||||
|
|
||||||
int avformat_init_output(AVFormatContext *s, AVDictionary **options)
|
int avformat_init_output(AVFormatContext *s, AVDictionary **options)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
@ -536,8 +544,7 @@ int avformat_write_header(AVFormatContext *s, AVDictionary **options)
|
||||||
return streams_already_initialized;
|
return streams_already_initialized;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
if (s->oformat->deinit)
|
deinit_muxer(s);
|
||||||
s->oformat->deinit(s);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1286,11 +1293,7 @@ fail:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s->oformat->deinit)
|
deinit_muxer(s);
|
||||||
s->oformat->deinit(s);
|
|
||||||
|
|
||||||
s->internal->initialized =
|
|
||||||
s->internal->streams_initialized = 0;
|
|
||||||
|
|
||||||
if (s->pb)
|
if (s->pb)
|
||||||
avio_flush(s->pb);
|
avio_flush(s->pb);
|
||||||
|
|
|
@ -4437,6 +4437,9 @@ void avformat_free_context(AVFormatContext *s)
|
||||||
if (!s)
|
if (!s)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (s->oformat && s->oformat->deinit && s->internal->initialized)
|
||||||
|
s->oformat->deinit(s);
|
||||||
|
|
||||||
av_opt_free(s);
|
av_opt_free(s);
|
||||||
if (s->iformat && s->iformat->priv_class && s->priv_data)
|
if (s->iformat && s->iformat->priv_class && s->priv_data)
|
||||||
av_opt_free(s->priv_data);
|
av_opt_free(s->priv_data);
|
||||||
|
|
Loading…
Reference in New Issue