[MSPAINT]
authorPierre Schweitzer <pierre@reactos.org>
Sat, 4 Oct 2014 15:41:38 +0000 (15:41 +0000)
committerPierre Schweitzer <pierre@reactos.org>
Sat, 4 Oct 2014 15:41:38 +0000 (15:41 +0000)
- Check for correct allocation
- Don't leak in case of file opening failure

svn path=/trunk/; revision=64524

reactos/base/applications/mspaint/dib.c

index ee5bcb8..b9bcd59 100644 (file)
@@ -72,11 +72,17 @@ SaveDIBToFile(HBITMAP hBitmap, LPTSTR FileName, HDC hDC, LPSYSTEMTIME time, int
     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);