]> git.imager.perl.org - imager.git/commitdiff
translate_errdiff() could leak memory on failure
authorTony Cook <tony@develop-help.com>
Sat, 23 Feb 2019 03:45:41 +0000 (14:45 +1100)
committerTony Cook <tony@develop-help.com>
Sat, 23 Feb 2019 03:45:41 +0000 (14:45 +1100)
Introduced when I added error handling

CID 185565

quant.c

diff --git a/quant.c b/quant.c
index 01ec8fcd38e91e1932e4520cfffb5a8ee9472d19..c798080c5b70be2a254e11c341242cc7d6a472fb 100644 (file)
--- a/quant.c
+++ b/quant.c
@@ -1389,14 +1389,14 @@ translate_errdiff(i_quantize *quant, i_img *img, i_palidx *out) {
   for (i = 0; i < maph * mapw; ++i) {
     if (map[i] < 0) {
       i_push_errorf(0, "errdiff_map values must be non-negative, errdiff[%d] is negative", i);
-      return 0;
+      goto fail;
     }
     difftotal += map[i];
   }
 
   if (!difftotal) {
     i_push_error(0, "error diffusion map must contain some non-zero values");
-    return 0;
+    goto fail;
   }
 
   errw = img->xsize+mapw;
@@ -1459,6 +1459,11 @@ translate_errdiff(i_quantize *quant, i_img *img, i_palidx *out) {
   myfree(err);
 
   return 1;
+
+ fail:
+  CF_CLEANUP;
+
+  return 0;
 }
 /* Prescan finds the boxes in the image that have the highest number of colors 
    and that result is used as the initial value for the vectores */