diff mbox series

[FFmpeg-devel,2/7] avcodec/iff: Avoid redundant frees

Message ID DB6PR0101MB22143275EB7E870A4320337C8F869@DB6PR0101MB2214.eurprd01.prod.exchangelabs.com
State Accepted
Commit 46b586e5b262052f09dfd22d06356c875203c245
Headers show
Series [FFmpeg-devel,1/7] avcodec/iff: Split extract_header into extradata and packet part | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Andreas Rheinhardt July 12, 2022, 10:27 a.m. UTC
This code is only called once during init, so none of the buffers
here have been allocated already.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/iff.c | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/iff.c b/libavcodec/iff.c
index 4abbed8dfb..f14644471b 100644
--- a/libavcodec/iff.c
+++ b/libavcodec/iff.c
@@ -246,8 +246,6 @@  static int extract_header(AVCodecContext *const avctx)
         if (s->masking == MASK_HAS_MASK) {
             if (s->bpp >= 8 && !s->ham) {
                 avctx->pix_fmt = AV_PIX_FMT_RGB32;
-                av_freep(&s->mask_buf);
-                av_freep(&s->mask_palbuf);
                 if (s->bpp > 16) {
                     av_log(avctx, AV_LOG_ERROR, "bpp %d too large for palette\n", s->bpp);
                     return AVERROR(ENOMEM);
@@ -256,10 +254,8 @@  static int extract_header(AVCodecContext *const avctx)
                 if (!s->mask_buf)
                     return AVERROR(ENOMEM);
                 s->mask_palbuf = av_malloc((2 << s->bpp) * sizeof(uint32_t) + AV_INPUT_BUFFER_PADDING_SIZE);
-                if (!s->mask_palbuf) {
-                    av_freep(&s->mask_buf);
+                if (!s->mask_palbuf)
                     return AVERROR(ENOMEM);
-                }
             }
             s->bpp++;
         } else if (s->masking != MASK_NONE && s->masking != MASK_HAS_TRANSPARENT_COLOR) {
@@ -273,9 +269,6 @@  static int extract_header(AVCodecContext *const avctx)
         if (s->video_size && s->planesize * s->bpp * avctx->height > s->video_size)
             return AVERROR_INVALIDDATA;
 
-        av_freep(&s->ham_buf);
-        av_freep(&s->ham_palbuf);
-
         if (s->ham) {
             int i, count = FFMIN(palette_size / 3, 1 << s->ham);
             int ham_count;
@@ -291,10 +284,8 @@  static int extract_header(AVCodecContext *const avctx)
 
             ham_count = 8 * (1 << s->ham);
             s->ham_palbuf = av_malloc(extra_space * (ham_count << !!(s->masking == MASK_HAS_MASK)) * sizeof (uint32_t) + AV_INPUT_BUFFER_PADDING_SIZE);
-            if (!s->ham_palbuf) {
-                av_freep(&s->ham_buf);
+            if (!s->ham_palbuf)
                 return AVERROR(ENOMEM);
-            }
 
             if (count) { // HAM with color palette attached
                 // prefill with black and palette and set HAM take direct value mask to zero