[FFmpeg-devel] [PATCH] oggdec: add various malloc and NULL checks

Reimar Döffinger Reimar.Doeffinger at gmx.de
Tue May 24 20:28:57 CEST 2011


On Tue, May 24, 2011 at 04:18:10PM +0200, Stefano Sabatini wrote:
> ---
>  libavformat/oggdec.c |   19 +++++++++++++++----
>  1 files changed, 15 insertions(+), 4 deletions(-)
> 
> diff --git a/libavformat/oggdec.c b/libavformat/oggdec.c
> index 92da175..61a71c6 100644
> --- a/libavformat/oggdec.c
> +++ b/libavformat/oggdec.c
> @@ -59,9 +59,12 @@ static const struct ogg_codec * const ogg_codecs[] = {
>  static int ogg_save(AVFormatContext *s)
>  {
>      struct ogg *ogg = s->priv_data;
> +    int i;
>      struct ogg_state *ost =
>          av_malloc(sizeof (*ost) + (ogg->nstreams-1) * sizeof (*ogg->streams));
> -    int i;
> +
> +    if (!ost)
> +        return AVERROR(ENOMEM);
>      ost->pos = avio_tell (s->pb);
>      ost->curidx = ogg->curidx;
>      ost->next = ogg->state;
> @@ -71,6 +74,8 @@ static int ogg_save(AVFormatContext *s)
>      for (i = 0; i < ogg->nstreams; i++){
>          struct ogg_stream *os = ogg->streams + i;
>          os->buf = av_malloc (os->bufsize);
> +        if (!os->buf)
> +            return AVERROR(ENOMEM);

Leaks ost and up to ogg->nstreams - 1 buffers and
probably also potentially leaves os->buf half pointing
to newly allocated and old buffers.
The rest looks ok from a quick glance.


More information about the ffmpeg-devel mailing list