[FFmpeg-devel] [PATCH v3 3/6] avformat/rtspdec: fix mem leaks in connect mode if init fails

Martin Storsjö martin at martin.st
Fri Nov 20 10:23:41 EET 2020


On Mon, 12 Oct 2020, Andriy Gelman wrote:

> From: Andriy Gelman <andriy.gelman at gmail.com>
>
> Fixes #6334
>
> Signed-off-by: Andriy Gelman <andriy.gelman at gmail.com>
> ---
> libavformat/rtspdec.c | 14 +++++++++-----
> 1 file changed, 9 insertions(+), 5 deletions(-)
>
> diff --git a/libavformat/rtspdec.c b/libavformat/rtspdec.c
> index 5a383b5a19..7c617837ca 100644
> --- a/libavformat/rtspdec.c
> +++ b/libavformat/rtspdec.c
> @@ -735,22 +735,26 @@ static int rtsp_read_header(AVFormatContext *s)
>
>         rt->real_setup_cache = !s->nb_streams ? NULL :
>             av_mallocz_array(s->nb_streams, 2 * sizeof(*rt->real_setup_cache));
> -        if (!rt->real_setup_cache && s->nb_streams)
> -            return AVERROR(ENOMEM);
> +        if (!rt->real_setup_cache && s->nb_streams) {
> +            ret = AVERROR(ENOMEM);
> +            goto fail;
> +        }
>         rt->real_setup = rt->real_setup_cache + s->nb_streams;
>
>         if (rt->initial_pause) {
>             /* do not start immediately */
>         } else {
>             if ((ret = rtsp_read_play(s)) < 0) {
> -                ff_rtsp_close_streams(s);
> -                ff_rtsp_close_connections(s);
> -                return ret;
> +                goto fail;
>             }
>         }
>     }
>
>     return 0;
> +
> +fail:
> +    rtsp_read_close(s);
> +    return ret;
> }
> 
> int ff_rtsp_tcp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st,
> -- 
> 2.28.0

Looks ok, assuming that the error codepath has been tested.

// Martin



More information about the ffmpeg-devel mailing list