summaryrefslogtreecommitdiffstats
path: root/libavformat/matroskaenc.c
diff options
context:
space:
mode:
authorJun Zhao <barryjzhao@tencent.com>2019-04-04 23:47:46 +0800
committerJun Zhao <barryjzhao@tencent.com>2019-04-09 09:16:07 +0800
commit0a347ff4222345c88b93d7962a696f0e9aae7ca2 (patch)
treeae7ceee81c40f37f5ef17a132e930fd03b81095e /libavformat/matroskaenc.c
parentbb5efd1727eeecc9be8f1402810c7ab72344eed3 (diff)
downloadffmpeg-streaming-0a347ff4222345c88b93d7962a696f0e9aae7ca2.zip
ffmpeg-streaming-0a347ff4222345c88b93d7962a696f0e9aae7ca2.tar.gz
lavf/matroskaenc: Fix memory leak after write trailer
Fix memory leak after write trailer for #7827, only store a audio packet whose buffer has size greater than zero in cur_audio_pkt. Audio packets with size zero, but with side-data currently lead to memleaks, in the Matroska muxer, because they are not properly freed: They are currently put into an AVPacket in the MatroskaMuxContext to ensure that the necessary audio is always available for a new cluster, but are only written and freed when their size is > 0. As the only use we have for such packets consists in updating the CodecPrivate it makes no sense to store these packets at all and this is how this commit solves the memleak. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@googlemail.com> Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
Diffstat (limited to 'libavformat/matroskaenc.c')
-rw-r--r--libavformat/matroskaenc.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index b9f99c4..06f3aeb 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -2534,7 +2534,8 @@ static int mkv_write_packet(AVFormatContext *s, AVPacket *pkt)
// buffer an audio packet to ensure the packet containing the video
// keyframe's timecode is contained in the same cluster for WebM
if (codec_type == AVMEDIA_TYPE_AUDIO) {
- ret = av_packet_ref(&mkv->cur_audio_pkt, pkt);
+ if (pkt->size > 0)
+ ret = av_packet_ref(&mkv->cur_audio_pkt, pkt);
} else
ret = mkv_write_packet_internal(s, pkt, 0);
return ret;
OpenPOWER on IntegriCloud