]> git.imager.perl.org - imager.git/blobdiff - gif.c
RT 58761: fix Imager->new(data => $data)
[imager.git] / gif.c
diff --git a/gif.c b/gif.c
index be4e874f19c8575b227c4b7016febb07a11086c4..ae365372661426a7e3ac980eae3c2944b3e9313c 100644 (file)
--- a/gif.c
+++ b/gif.c
@@ -554,6 +554,8 @@ i_img **i_readgif_multi_low(GifFileType *GifFile, int *count, int page) {
       free_images(results, *count);
       DGifCloseFile(GifFile);
       myfree(GifRow);
+      if (comment)
+       myfree(comment);
       return NULL;
     }
     
@@ -565,6 +567,8 @@ i_img **i_readgif_multi_low(GifFileType *GifFile, int *count, int page) {
         free_images(results, *count);
        DGifCloseFile(GifFile);
        myfree(GifRow);
+       if (comment)
+         myfree(comment);
        return NULL;
       }
 
@@ -582,6 +586,8 @@ i_img **i_readgif_multi_low(GifFileType *GifFile, int *count, int page) {
          free_images(results, *count);
          DGifCloseFile(GifFile);
          myfree(GifRow);
+         if (comment)
+           myfree(comment);
          return NULL;
        }
        
@@ -593,12 +599,17 @@ i_img **i_readgif_multi_low(GifFileType *GifFile, int *count, int page) {
          mm_log((1, "i_readgif: image size exceeds limits\n"));
          DGifCloseFile(GifFile);
          myfree(GifRow);
+         if (comment)
+           myfree(comment);
          return NULL;
        }
        img = i_img_pal_new(Width, Height, channels, 256);
        if (!img) {
          free_images(results, *count);
          DGifCloseFile(GifFile);
+         if (comment)
+           myfree(comment);
+         myfree(GifRow);
          return NULL;
        }
        /* populate the palette of the new image */
@@ -673,6 +684,8 @@ i_img **i_readgif_multi_low(GifFileType *GifFile, int *count, int page) {
          free_images(results, *count);        
          DGifCloseFile(GifFile);
          myfree(GifRow);
+         if (comment)
+           myfree(comment);
          return(0);
        }
        
@@ -687,6 +700,8 @@ i_img **i_readgif_multi_low(GifFileType *GifFile, int *count, int page) {
                free_images(results, *count);
                DGifCloseFile(GifFile);
                myfree(GifRow);
+               if (comment)
+                 myfree(comment);
                return NULL;
              }
 
@@ -714,6 +729,8 @@ i_img **i_readgif_multi_low(GifFileType *GifFile, int *count, int page) {
              free_images(results, *count);
              DGifCloseFile(GifFile);
              myfree(GifRow);
+             if (comment)
+               myfree(comment);
              return NULL;
            }
            
@@ -737,6 +754,8 @@ i_img **i_readgif_multi_low(GifFileType *GifFile, int *count, int page) {
        if (page != -1) {
          myfree(GifRow);
          DGifCloseFile(GifFile);
+         if (comment)
+           myfree(comment);
          return results;
        }
       }
@@ -751,6 +770,8 @@ i_img **i_readgif_multi_low(GifFileType *GifFile, int *count, int page) {
            free_images(results, *count);
            myfree(GifRow);
            DGifCloseFile(GifFile);
+           if (comment) 
+             myfree(comment);
            return NULL;
          }
        }
@@ -769,9 +790,15 @@ i_img **i_readgif_multi_low(GifFileType *GifFile, int *count, int page) {
        gif_push_error();
        i_push_error(0, "Reading extension record");
         free_images(results, *count);
+       myfree(GifRow);
        DGifCloseFile(GifFile);
+       if (comment)
+         myfree(comment);
        return NULL;
       }
+      /* possibly this should be an error, but "be liberal in what you accept" */
+      if (!Extension)
+       break;
       if (ExtCode == 0xF9) {
         got_gce = 1;
         if (Extension[1] & 1)
@@ -788,7 +815,10 @@ i_img **i_readgif_multi_low(GifFileType *GifFile, int *count, int page) {
             gif_push_error();
             i_push_error(0, "reading loop extension");
             free_images(results, *count);
-            DGifCloseFile(GifFile);
+           myfree(GifRow);
+           DGifCloseFile(GifFile);
+           if (comment)
+             myfree(comment);
             return NULL;
           }
           if (Extension && *Extension == 3) {
@@ -815,7 +845,10 @@ i_img **i_readgif_multi_low(GifFileType *GifFile, int *count, int page) {
          gif_push_error();
          i_push_error(0, "reading next block of extension");
           free_images(results, *count);
+         myfree(GifRow);
          DGifCloseFile(GifFile);
+         if (comment)
+           myfree(comment);
          return NULL;
        }
       }
@@ -1436,7 +1469,7 @@ static int do_ns_loop(GifFileType *gf, i_img *img)
     subblock[2] = loop_count / 256;
     if (EGifPutExtensionLast(gf, APPLICATION_EXT_FUNC_CODE, 3, subblock) == GIF_ERROR) {
       gif_push_error();
-      i_push_error(0, "writing loop extention sub-block");
+      i_push_error(0, "writing loop extension sub-block");
       return 0;
     }
   }