[FFmpeg-devel,2/2] avcodec/jpeg2000dec: Free lengthinc earlier

Submitted by Michael Niedermayer on Dec. 17, 2017, 10:35 p.m.

Details

Message ID 20171217223526.20983-2-michael@niedermayer.cc
State New
Headers show

Commit Message

Michael Niedermayer Dec. 17, 2017, 10:35 p.m.
Reduces memory needed
---
 libavcodec/jpeg2000dec.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Michael Niedermayer Dec. 21, 2017, 1:04 p.m.
On Sun, Dec 17, 2017 at 11:35:26PM +0100, Michael Niedermayer wrote:
> Reduces memory needed
> ---
>  libavcodec/jpeg2000dec.c | 3 +++
>  1 file changed, 3 insertions(+)

applied

[...]

Patch hide | download patch | download mbox

diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c
index a9633fb9d1..d510004114 100644
--- a/libavcodec/jpeg2000dec.c
+++ b/libavcodec/jpeg2000dec.c
@@ -1044,6 +1044,8 @@  static int jpeg2000_decode_packet(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile,
         nb_code_blocks = prec->nb_codeblocks_height * prec->nb_codeblocks_width;
         for (cblkno = 0; cblkno < nb_code_blocks; cblkno++) {
             Jpeg2000Cblk *cblk = prec->cblk + cblkno;
+            if (!cblk->nb_terminationsinc && !cblk->lengthinc)
+                continue;
             for (cwsno = 0; cwsno < cblk->nb_lengthinc; cwsno ++) {
                 if (cblk->data_allocated < cblk->length + cblk->lengthinc[cwsno] + 4) {
                     size_t new_size = FFMAX(2*cblk->data_allocated, cblk->length + cblk->lengthinc[cwsno] + 4);
@@ -1073,6 +1075,7 @@  static int jpeg2000_decode_packet(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile,
                     cblk->data_start[cblk->nb_terminations] = cblk->length;
                 }
             }
+            av_freep(&cblk->lengthinc);
         }
     }
     return 0;