[FFmpeg-devel] [PATCH 08/17] avformat/webmdashenc: Fix memleak upon realloc failure

Andreas Rheinhardt andreas.rheinhardt at gmail.com
Tue Mar 17 20:41:43 EET 2020


Andreas Rheinhardt:
> The classical ptr = av_realloc(ptr, size).
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
> ---
>  libavformat/webmdashenc.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/libavformat/webmdashenc.c b/libavformat/webmdashenc.c
> index d2f0e0ec4d..e8b7a07974 100644
> --- a/libavformat/webmdashenc.c
> +++ b/libavformat/webmdashenc.c
> @@ -489,11 +489,12 @@ static int parse_adaptation_sets(AVFormatContext *s)
>              state = parsing_streams;
>          } else if (state == parsing_streams) {
>              struct AdaptationSet *as = &w->as[w->nb_as - 1];
> +            int ret = av_reallocp_array(&as->streams, ++as->nb_streams,
> +                                        sizeof(*as->streams));
> +            if (ret < 0)
> +                return ret;
>              q = p;
>              while (*q != '\0' && *q != ',' && *q != ' ') q++;
> -            as->streams = av_realloc(as->streams, sizeof(*as->streams) * ++as->nb_streams);
> -            if (as->streams == NULL)
> -                return AVERROR(ENOMEM);
>              as->streams[as->nb_streams - 1] = to_integer(p, q - p + 1);
>              if (as->streams[as->nb_streams - 1] < 0 ||
>                  as->streams[as->nb_streams - 1] >= s->nb_streams) {
> 
Ping.

- Andreas


More information about the ffmpeg-devel mailing list