diff mbox

[FFmpeg-devel,02/23] avformat/matroskaenc: Fix potential leak of cached packet

Message ID 20191106024922.19228-2-andreas.rheinhardt@gmail.com
State Accepted
Commit 4470ab1e0ee1c36cca83f161567177145f412605
Headers show

Commit Message

Andreas Rheinhardt Nov. 6, 2019, 2:49 a.m. UTC
If mkv_write_trailer() is not called, the cached audio packet might
leak; so unref it in mkv_deinit().

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
When I initially wrote the deinit function, I was under the impression
that the user always has to call av_write_trailer(). Therefore this has
been forgotten.

 libavformat/matroskaenc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Michael Niedermayer Nov. 24, 2019, 3:03 p.m. UTC | #1
On Wed, Nov 06, 2019 at 03:49:01AM +0100, Andreas Rheinhardt wrote:
> If mkv_write_trailer() is not called, the cached audio packet might
> leak; so unref it in mkv_deinit().
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
> When I initially wrote the deinit function, I was under the impression
> that the user always has to call av_write_trailer(). Therefore this has
> been forgotten.
> 
>  libavformat/matroskaenc.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)

will apply

thx

[...]
diff mbox

Patch

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 90400de191..de57e474be 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -390,6 +390,8 @@  static void mkv_deinit(AVFormatContext *s)
 {
     MatroskaMuxContext *mkv = s->priv_data;
 
+    av_packet_unref(&mkv->cur_audio_pkt);
+
     ffio_free_dyn_buf(&mkv->cluster_bc);
     ffio_free_dyn_buf(&mkv->info_bc);
     ffio_free_dyn_buf(&mkv->tracks_bc);
@@ -2534,7 +2536,6 @@  static int mkv_write_trailer(AVFormatContext *s)
     // check if we have an audio packet cached
     if (mkv->cur_audio_pkt.size > 0) {
         ret = mkv_write_packet_internal(s, &mkv->cur_audio_pkt, 0);
-        av_packet_unref(&mkv->cur_audio_pkt);
         if (ret < 0) {
             av_log(s, AV_LOG_ERROR,
                    "Could not write cached audio packet ret:%d\n", ret);