Message ID | 20200904172026.28217-2-andreas.rheinhardt@gmail.com |
---|---|
State | Accepted |
Commit | ceeba2ac2b6f03ffbb13c64c6fbef21eb52be405 |
Headers | show |
Series | [FFmpeg-devel,1/6] avcodec/bink: Fix memleak upon init failure | expand |
Context | Check | Description |
---|---|---|
andriy/default | pending | |
andriy/make | success | Make finished |
andriy/make_fate | success | Make fate finished |
On 9/4/20, Andreas Rheinhardt <andreas.rheinhardt@gmail.com> wrote: > Saves allocations, checks for the allocations as well as frees. > > Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> > --- > libavcodec/bink.c | 15 ++++++++------- > 1 file changed, 8 insertions(+), 7 deletions(-) > LGTM > diff --git a/libavcodec/bink.c b/libavcodec/bink.c > index c7ef333bd4..9fdfa37395 100644 > --- a/libavcodec/bink.c > +++ b/libavcodec/bink.c > @@ -178,17 +178,20 @@ static void init_lengths(BinkContext *c, int width, > int bw) > static av_cold int init_bundles(BinkContext *c) > { > int bw, bh, blocks; > + uint8_t *tmp; > int i; > > bw = (c->avctx->width + 7) >> 3; > bh = (c->avctx->height + 7) >> 3; > blocks = bw * bh; > > + tmp = av_calloc(blocks, 64 * BINKB_NB_SRC); > + if (!tmp) > + return AVERROR(ENOMEM); > for (i = 0; i < BINKB_NB_SRC; i++) { > - c->bundle[i].data = av_mallocz(blocks * 64); > - if (!c->bundle[i].data) > - return AVERROR(ENOMEM); > - c->bundle[i].data_end = c->bundle[i].data + blocks * 64; > + c->bundle[i].data = tmp; > + tmp += blocks * 64; > + c->bundle[i].data_end = tmp; > } > > return 0; > @@ -201,9 +204,7 @@ static av_cold int init_bundles(BinkContext *c) > */ > static av_cold void free_bundles(BinkContext *c) > { > - int i; > - for (i = 0; i < BINKB_NB_SRC; i++) > - av_freep(&c->bundle[i].data); > + av_freep(&c->bundle[0].data); > } > > /** > -- > 2.20.1 > > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel > > To unsubscribe, visit link above, or email > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
diff --git a/libavcodec/bink.c b/libavcodec/bink.c index c7ef333bd4..9fdfa37395 100644 --- a/libavcodec/bink.c +++ b/libavcodec/bink.c @@ -178,17 +178,20 @@ static void init_lengths(BinkContext *c, int width, int bw) static av_cold int init_bundles(BinkContext *c) { int bw, bh, blocks; + uint8_t *tmp; int i; bw = (c->avctx->width + 7) >> 3; bh = (c->avctx->height + 7) >> 3; blocks = bw * bh; + tmp = av_calloc(blocks, 64 * BINKB_NB_SRC); + if (!tmp) + return AVERROR(ENOMEM); for (i = 0; i < BINKB_NB_SRC; i++) { - c->bundle[i].data = av_mallocz(blocks * 64); - if (!c->bundle[i].data) - return AVERROR(ENOMEM); - c->bundle[i].data_end = c->bundle[i].data + blocks * 64; + c->bundle[i].data = tmp; + tmp += blocks * 64; + c->bundle[i].data_end = tmp; } return 0; @@ -201,9 +204,7 @@ static av_cold int init_bundles(BinkContext *c) */ static av_cold void free_bundles(BinkContext *c) { - int i; - for (i = 0; i < BINKB_NB_SRC; i++) - av_freep(&c->bundle[i].data); + av_freep(&c->bundle[0].data); } /**
Saves allocations, checks for the allocations as well as frees. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> --- libavcodec/bink.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)