LCD LIB

Dependents:   HagridOS5

Fork of RA8875 by David Smart

Revision:
69:636867df24a1
Parent:
61:8f3153bf0baa
Child:
72:ecffe56af969
diff -r ba5d33438fda -r 636867df24a1 GraphicsDisplay.cpp
--- a/GraphicsDisplay.cpp	Sun Aug 17 15:38:51 2014 +0000
+++ b/GraphicsDisplay.cpp	Sun Aug 31 15:54:42 2014 +0000
@@ -439,7 +439,9 @@
             //HexDump("Line", lineBuffer, lineBufSize);
             fwrite(lineBuffer, sizeof(char), lb, Image);
         }
-        fclose(Image);       
+        fclose(Image);
+        free(pixelBuffer);  // don't leak memory.
+        free(lineBuffer);
         INFO("Image closed"); 
         return noerror;
     } else {
@@ -453,6 +455,7 @@
     RGBQUAD * colorPalette = NULL;
     int colorCount;
     uint8_t * lineBuffer = NULL;
+    color_t * pixelBuffer = NULL;
     uint16_t BPP_t;
     uint32_t PixelWidth, PixelHeight;
     unsigned int    i, offset;
@@ -500,10 +503,11 @@
         fclose(Image);
         return(not_enough_ram);
     }
-    color_t * pixelBuffer = (color_t *)malloc(PixelWidth * sizeof(color_t));
+    pixelBuffer = (color_t *)malloc(PixelWidth * sizeof(color_t));
     if (pixelBuffer == NULL) {
-        free(colorPalette);
         free(lineBuffer);
+        if (colorPalette)
+            free(colorPalette);
         fclose(Image);
         return(not_enough_ram);
     }
@@ -562,8 +566,10 @@
     }
     _EndGraphicsStream();
     WindowMax();
+    free(pixelBuffer);      // don't leak memory
     free(lineBuffer);
-    free(colorPalette);
+    if (colorPalette)
+        free(colorPalette);
     return (noerror);
 }