avformat/flacenc: Fix memleak when writing attached pictures fails

The FLAC muxer currently stores an attached picture corresponding to an
AVStream in AVStream.priv_data. The AVPacket contained therein is
unreferenced after it has been written. The AVPacket structure itself is
then freed generically as AVStream.priv_data.

And this can lead to memleaks if an attached picture is not written:
It might be because the trailer is never written or because writing
a previous attached picture failed in case error_recognition is set
to explode.

Therefore free the packets properly (i.e. with av_packet_free())
in the muxer's deinit function.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
(cherry picked from commit 029cf6a91c)
This commit is contained in:
Andreas Rheinhardt 2020-11-20 17:36:39 +01:00
parent eb5c81f373
commit e30b61c261
1 changed files with 2 additions and 0 deletions

View File

@ -346,6 +346,8 @@ static void flac_deinit(struct AVFormatContext *s)
FlacMuxerContext *c = s->priv_data;
ff_packet_list_free(&c->queue, &c->queue_end);
for (unsigned i = 0; i < s->nb_streams; i++)
av_packet_free((AVPacket **)&s->streams[i]->priv_data);
}
static int flac_write_packet(struct AVFormatContext *s, AVPacket *pkt)