diff mbox series

[FFmpeg-devel,18/20] avcodec/snow: Only allocate x_coeffs for decoder

Message ID AS8P250MB07443DD38FDF8C327D3068B78F209@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM
State New
Headers show
Series [FFmpeg-devel,1/8] configure: Remove dependencies of inexistant rtjpeg decoder | 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 Oct. 10, 2022, 3:13 a.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/snow.c    | 17 +++--------------
 libavcodec/snowdec.c |  9 +++++++++
 2 files changed, 12 insertions(+), 14 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/snow.c b/libavcodec/snow.c
index dcd6d67ad5..52ab39bfd4 100644
--- a/libavcodec/snow.c
+++ b/libavcodec/snow.c
@@ -538,13 +538,14 @@  int ff_snow_common_init_after_header(AVCodecContext *avctx) {
                     b->parent= &s->plane[plane_index].band[level-1][orientation];
                 if (s->spatial_dwt_buffer) { /* Equivalently: if s is encoder */
                     b->buf = s->spatial_dwt_buffer + offset;
-                }
+                } else {
                 //FIXME avoid this realloc
                 av_freep(&b->x_coeff);
                 b->x_coeff = av_calloc((b->width + 1) * b->height + 1,
                                        sizeof(*b->x_coeff));
                 if (!b->x_coeff)
                     return AVERROR(ENOMEM);
+                }
             }
             w= (w+1)>>1;
             h= (h+1)>>1;
@@ -598,26 +599,14 @@  int ff_snow_frame_start(SnowContext *s){
 
 av_cold void ff_snow_common_end(SnowContext *s)
 {
-    int plane_index, level, orientation, i;
-
     av_freep(&s->spatial_idwt_buffer);
     av_freep(&s->temp_idwt_buffer);
 
     av_freep(&s->block);
     av_freep(&s->scratchbuf);
 
-    for(i=0; i<MAX_REF_FRAMES; i++){
+    for (int i = 0; i < MAX_REF_FRAMES; i++)
         av_frame_free(&s->last_picture[i]);
-    }
-
-    for(plane_index=0; plane_index < MAX_PLANES; plane_index++){
-        for(level=MAX_DECOMPOSITIONS-1; level>=0; level--){
-            for(orientation=level ? 1 : 0; orientation<4; orientation++){
-                SubBand *b= &s->plane[plane_index].band[level][orientation];
 
-                av_freep(&b->x_coeff);
-            }
-        }
-    }
     av_frame_free(&s->current_picture);
 }
diff --git a/libavcodec/snowdec.c b/libavcodec/snowdec.c
index 17c7ccaf2c..13948398b0 100644
--- a/libavcodec/snowdec.c
+++ b/libavcodec/snowdec.c
@@ -793,6 +793,15 @@  static av_cold int decode_end(AVCodecContext *avctx)
 
     ff_snow_common_end(s);
 
+    for (int plane_index = 0; plane_index < MAX_PLANES; plane_index++){
+        for (int level = MAX_DECOMPOSITIONS - 1; level >= 0; level--) {
+            for (int orientation = level ? 1 : 0; orientation < 4; orientation++){
+                SubBand *b = &s->plane[plane_index].band[level][orientation];
+
+                av_freep(&b->x_coeff);
+            }
+        }
+    }
     av_frame_free(&s->mconly_picture);
 
     s->avmv_size = 0;