[FFmpeg-devel] [PATCH 5/9] lavf/oggdec: rework allocations in ogg_new_streams().
Reimar Döffinger
Reimar.Doeffinger at gmx.de
Sat Sep 15 01:30:09 CEST 2012
On Sat, Sep 15, 2012 at 01:20:44AM +0200, Clément Bœsch wrote:
> ---
> libavformat/oggdec.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/libavformat/oggdec.c b/libavformat/oggdec.c
> index 05aeddd..451e392 100644
> --- a/libavformat/oggdec.c
> +++ b/libavformat/oggdec.c
> @@ -169,14 +169,18 @@ static int ogg_new_stream(AVFormatContext *s, uint32_t serial, int new_avstream)
> AVStream *st;
> struct ogg_stream *os;
>
> - ogg->streams = av_realloc (ogg->streams,
> - ogg->nstreams * sizeof (*ogg->streams));
> + ogg->streams = av_realloc_f(ogg->streams, ogg->nstreams,
> + sizeof(*ogg->streams));
> + if (!ogg->streams)
> + return AVERROR(ENOMEM);
> memset (ogg->streams + idx, 0, sizeof (*ogg->streams));
> os = ogg->streams + idx;
> os->serial = serial;
> os->bufsize = DECODER_BUFFER_SIZE;
> os->buf = av_malloc(os->bufsize + FF_INPUT_BUFFER_PADDING_SIZE);
> os->header = -1;
> + if (!os->buf)
> + return AVERROR(ENOMEM);
I don't think nstreams should be incremented in the failure case?
Also the realloc is not fully correct, it will still leak memory on
failure (sorry if some later patch addresses this, just going through in
order)
More information about the ffmpeg-devel
mailing list