diff options
author | Andreas Rheinhardt <andreas.rheinhardt@gmail.com> | 2020-03-01 00:50:15 +0100 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@gmail.com> | 2020-03-26 02:28:13 +0100 |
commit | d624fb5dada1622f3057b2b35877111a701b3abb (patch) | |
tree | 4fdc6ee16c777b3c4d9abe28e72851bf02ed164d /libavformat | |
parent | 42b000427dfa8d49807e8a756091d7662ba3bf65 (diff) | |
download | ffmpeg-d624fb5dada1622f3057b2b35877111a701b3abb.tar.gz |
avformat/webm_chunk: Add deinit function
This fixes memleaks if an error happens after one of the allocations
in init; or if the trailer isn't written (e.g. because there was an
error when writing a packet).
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Diffstat (limited to 'libavformat')
-rw-r--r-- | libavformat/webm_chunk.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/libavformat/webm_chunk.c b/libavformat/webm_chunk.c index 4188c5c0a5..b27e8c4927 100644 --- a/libavformat/webm_chunk.c +++ b/libavformat/webm_chunk.c @@ -258,13 +258,22 @@ static int webm_chunk_write_trailer(AVFormatContext *s) if (!oc->pb) { ret = chunk_start(s); if (ret < 0) - goto fail; + return ret; } av_write_trailer(oc); - ret = chunk_end(s, 0); -fail: - avformat_free_context(oc); - return ret; + return chunk_end(s, 0); +} + +static void webm_chunk_deinit(AVFormatContext *s) +{ + WebMChunkContext *wc = s->priv_data; + + if (!wc->avf) + return; + + ffio_free_dyn_buf(&wc->avf->pb); + avformat_free_context(wc->avf); + wc->avf = NULL; } #define OFFSET(x) offsetof(WebMChunkContext, x) @@ -296,6 +305,7 @@ AVOutputFormat ff_webm_chunk_muxer = { .write_header = webm_chunk_write_header, .write_packet = webm_chunk_write_packet, .write_trailer = webm_chunk_write_trailer, + .deinit = webm_chunk_deinit, .priv_class = &webm_chunk_class, }; #endif |