[FFmpeg-devel] [PATCH v4 1/9] avformat/utils: Fix memleaks
Michael Niedermayer
michael at niedermayer.cc
Sun Sep 22 15:55:43 EEST 2019
On Fri, Sep 20, 2019 at 10:39:08PM +0200, Andreas Rheinhardt wrote:
> ff_read_packet had several potential memleaks:
> 1. If av_packet_make_refcounted fails, it means that the packet is not
> refcounted, but it could nevertheless carry side data and therefore
> needs to be unreferenced.
> 2. If a packet happens to have an illegal stream index (i.e. one that
> does not correspond to a stream), it should nevertheless be
> unreferenced.
> 3. If putting a packet on a packet list fails, it wasn't unreferenced.
>
> Furthermore, read_frame_internal leaked a packet's (side) data if a
> context update was required and failed.
>
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
> ---
> libavformat/utils.c | 17 +++++++++++++----
> 1 file changed, 13 insertions(+), 4 deletions(-)
>
> diff --git a/libavformat/utils.c b/libavformat/utils.c
> index 3983a3f4ce..652642a71b 100644
> --- a/libavformat/utils.c
> +++ b/libavformat/utils.c
> @@ -872,8 +872,10 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt)
> }
>
> err = av_packet_make_refcounted(pkt);
> - if (err < 0)
> + if (err < 0) {
> + av_packet_unref(pkt);
> return err;
> + }
>
> if ((s->flags & AVFMT_FLAG_DISCARD_CORRUPT) &&
> (pkt->flags & AV_PKT_FLAG_CORRUPT)) {
> @@ -886,6 +888,7 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt)
>
> if (pkt->stream_index >= (unsigned)s->nb_streams) {
> av_log(s, AV_LOG_ERROR, "Invalid stream index %d\n", pkt->stream_index);
> + av_packet_unref(pkt);
> continue;
> }
>
What does generate invalid stream indexes ?
if nothing then this should probably be an av_assert*()
thx
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
"Nothing to hide" only works if the folks in power share the values of
you and everyone you know entirely and always will -- Tom Scott
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20190922/f053648d/attachment.sig>
More information about the ffmpeg-devel
mailing list