jpeg2000: fix null pointer dereference in case of malloc failure
authorMichael Niedermayer <michaelni@gmx.at>
Fri, 23 Aug 2013 15:50:12 +0000 (17:50 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Fri, 23 Aug 2013 16:06:54 +0000 (18:06 +0200)
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
libavcodec/jpeg2000.c

index 77bf34e..36e6ff1 100644 (file)
@@ -507,17 +507,19 @@ void ff_jpeg2000_cleanup(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty)
         Jpeg2000ResLevel *reslevel = comp->reslevel + reslevelno;
 
         for (bandno = 0; bandno < reslevel->nbands; bandno++) {
-            Jpeg2000Band *band = reslevel->band + bandno;
-            for (precno = 0; precno < reslevel->num_precincts_x * reslevel->num_precincts_y; precno++) {
-                if (band->prec) {
-                    Jpeg2000Prec *prec = band->prec + precno;
-                    av_freep(&prec->zerobits);
-                    av_freep(&prec->cblkincl);
-                    av_freep(&prec->cblk);
+            if (reslevel->band) {
+                Jpeg2000Band *band = reslevel->band + bandno;
+                for (precno = 0; precno < reslevel->num_precincts_x * reslevel->num_precincts_y; precno++) {
+                    if (band->prec) {
+                        Jpeg2000Prec *prec = band->prec + precno;
+                        av_freep(&prec->zerobits);
+                        av_freep(&prec->cblkincl);
+                        av_freep(&prec->cblk);
+                    }
                 }
-            }
 
-            av_freep(&band->prec);
+                av_freep(&band->prec);
+            }
         }
         av_freep(&reslevel->band);
     }