Commits

pornel  committed 5f1d7ac

Avoid NULL pointer dereference by checking if parent struct has been allocated first

  • Participants
  • Parent commits fc7eb63

Comments (0)

Files changed (1)

File src/gd_topal.c

       }
     }
 success:
-  for (i = 0; i < HIST_C0_ELEMS; i++)
-    {
-      if (cquantize->histogram[i])
-	{
-	  gdFree (cquantize->histogram[i]);
-	}
-    }
-  if (cquantize->histogram)
-    {
-      gdFree (cquantize->histogram);
-    }
-  if (cquantize->fserrors)
-    {
-      gdFree (cquantize->fserrors);
-    }
-  if (cquantize->error_limiter_storage)
-    {
-      gdFree (cquantize->error_limiter_storage);
-    }
+
   if (cquantize)
     {
+      if (cquantize->histogram)
+        {
+          for (i = 0; i < HIST_C0_ELEMS; i++)
+            {
+               if (cquantize->histogram[i])
+                 {
+                    gdFree (cquantize->histogram[i]);
+                 }
+            }
+          gdFree (cquantize->histogram);
+        }
+      if (cquantize->fserrors)
+        {
+          gdFree (cquantize->fserrors);
+        }
+      if (cquantize->error_limiter_storage)
+        {
+          gdFree (cquantize->error_limiter_storage);
+        }
       gdFree (cquantize);
     }
-
 }
 
 #endif