Author: pschweitzer
Date: Sat Oct 4 15:41:38 2014
New Revision: 64524
URL:
http://svn.reactos.org/svn/reactos?rev=64524&view=rev
Log:
[MSPAINT]
- Check for correct allocation
- Don't leak in case of file opening failure
Modified:
trunk/reactos/base/applications/mspaint/dib.c
Modified: trunk/reactos/base/applications/mspaint/dib.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mspaint/…
==============================================================================
--- trunk/reactos/base/applications/mspaint/dib.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/mspaint/dib.c [iso-8859-1] Sat Oct 4 15:41:38 2014
@@ -72,11 +72,17 @@
bi.biYPelsPerMeter = vRes;
buffer = HeapAlloc(GetProcessHeap(), 0, imgDataSize);
+ if (!buffer)
+ return;
+
GetDIBits(hDC, hBitmap, 0, bm.bmHeight, buffer, (LPBITMAPINFO) & bi,
DIB_RGB_COLORS);
hFile = CreateFile(FileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
FILE_FLAG_SEQUENTIAL_SCAN, NULL);
if (hFile == INVALID_HANDLE_VALUE)
+ {
+ HeapFree(GetProcessHeap(), 0, buffer);
return;
+ }
WriteFile(hFile, &bf, sizeof(BITMAPFILEHEADER), &dwBytesWritten, NULL);
WriteFile(hFile, &bi, sizeof(BITMAPINFOHEADER), &dwBytesWritten, NULL);