Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of RA8875 by
Revision 69:636867df24a1, committed 2014-08-31
- Comitter:
- WiredHome
- Date:
- Sun Aug 31 15:54:42 2014 +0000
- Parent:
- 62:ba5d33438fda
- Child:
- 70:4cb28f9472fc
- Commit message:
- Eliminate possibility of memory leak.
Changed in this revision
| GraphicsDisplay.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- 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);
}
