[FFmpeg-devel] [PATCH V1] lavf/matroskaenc: Fix memory leak after write trailer

Andreas Rheinhardt andreas.rheinhardt at googlemail.com
Thu Apr 4 14:28:00 EEST 2019


Hendrik Leppkes:
> On Thu, Apr 4, 2019 at 11:25 AM Jun Zhao <mypopydev at gmail.com> wrote:
>>
>> From: Jun Zhao <barryjzhao at tencent.com>
>>
>> Fix memory leak after write trailer for #7827
>>
>> Signed-off-by: Jun Zhao <barryjzhao at tencent.com>
>> ---
>>  libavformat/matroskaenc.c |    2 +-
>>  1 files changed, 1 insertions(+), 1 deletions(-)
>>
>> diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
>> index b9f99c4..22ba93a 100644
>> --- a/libavformat/matroskaenc.c
>> +++ b/libavformat/matroskaenc.c
>> @@ -2571,13 +2571,13 @@ 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);
>>              return ret;
>>          }
>>      }
>> +    av_packet_unref(&mkv->cur_audio_pkt);
>>
> 
> Won't this leak instead when the error path above is triggered?

Yes, it will.

> Also, whats in the packet if it has a size of 0?
> 
It contains side-data which is used to update the extradata (the md5
and number of samples etc. that is part of the flac STREAMINFO header).

- Andreas


More information about the ffmpeg-devel mailing list