diff src/libgfx.c @ 834:9623b9b548d4

Reallocation fixes.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 11 Jul 2014 18:06:30 +0300
parents 1e5cf1144f36
children e7019bd83cca
line wrap: on
line diff
--- a/src/libgfx.c	Fri Jul 11 18:02:59 2014 +0300
+++ b/src/libgfx.c	Fri Jul 11 18:06:30 2014 +0300
@@ -1639,14 +1639,22 @@
         // If halfbrite is used, duplicate the palette
         if (iff.camg & IFF_CAMG_HALFBRITE)
         {
+            void *ptmp;
+
             if (iff.ncolors > 128)
             {
                 dmError("ILBM: Halfbrite enabled, but ncolors > 128.\n");
                 return DMERR_NOT_SUPPORTED;
             }
 
-            if ((iff.pal = dmRealloc(iff.pal, sizeof(DMColor) * iff.ncolors * 2)) == NULL)
+            if ((ptmp = dmRealloc(iff.pal, sizeof(DMColor) * iff.ncolors * 2)) == NULL)
+            {
+                dmFree(iff.pal);
+                iff.pal = NULL;
                 return DMERR_MALLOC;
+            }
+            else
+                iff.pal = ptmp;
             
             for (i = 0; i < iff.ncolors; i++)
             {