@@ -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);
}
@@ -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;
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavcodec/snow.c | 17 +++-------------- libavcodec/snowdec.c | 9 +++++++++ 2 files changed, 12 insertions(+), 14 deletions(-)