]> granicus.if.org Git - php/commitdiff
Move freeing of truecolor pixels to a function
authorChristoph M. Becker <cmbecker69@gmx.de>
Mon, 3 Oct 2016 10:11:46 +0000 (12:11 +0200)
committerChristoph M. Becker <cmbecker69@gmx.de>
Mon, 3 Oct 2016 10:11:46 +0000 (12:11 +0200)
We port <https://github.com/libgd/libgd/commit/81675d39>.

ext/gd/libgd/gd_topal.c

index 5b848556561213a98b1528dd80681f4838e23eeb..a92a7acb17a43c182927cdb5fae0a96203830b3b 100644 (file)
@@ -1442,6 +1442,19 @@ int gdImageTrueColorToPalette (gdImagePtr im, int dither, int colorsWanted)
        return gdImageTrueColorToPaletteBody(im, dither, colorsWanted, 0);
 }
 
+static void free_truecolor_image_data(gdImagePtr oim)
+{
+  int i;
+  oim->trueColor = 0;
+  /* Junk the truecolor pixels */
+  for (i = 0; i < oim->sy; i++)
+    {
+      gdFree (oim->tpixels[i]);
+    }
+  gdFree (oim->tpixels);
+  oim->tpixels = 0;
+}
+
 /*
  * Module initialization routine for 2-pass color quantization.
  */
@@ -1605,16 +1618,11 @@ static int gdImageTrueColorToPaletteBody (gdImagePtr oim, int dither, int colors
 
   /* Success! Get rid of the truecolor image data. */
   conversionSucceeded = TRUE;
-  if (!cimP) {
-    oim->trueColor = 0;
-    /* Junk the truecolor pixels */
-    for (i = 0; i < oim->sy; i++)
-      {
-        gdFree (oim->tpixels[i]);
-      }
-    gdFree (oim->tpixels);
-    oim->tpixels = 0;
-  }
+  if (!cimP)
+    {
+      free_truecolor_image_data(oim);
+    }
+
   goto freeQuantizeData;
   /* Tediously free stuff. */
 outOfMemory: