mirror of
https://github.com/reactos/reactos.git
synced 2025-02-25 01:39:30 +00:00
[MSPAINT]
- Check for correct allocation - Don't leak in case of file opening failure svn path=/trunk/; revision=64524
This commit is contained in:
parent
b02e9a73fd
commit
0b6013a4f6
1 changed files with 6 additions and 0 deletions
|
@ -72,11 +72,17 @@ SaveDIBToFile(HBITMAP hBitmap, LPTSTR FileName, HDC hDC, LPSYSTEMTIME time, int
|
||||||
bi.biYPelsPerMeter = vRes;
|
bi.biYPelsPerMeter = vRes;
|
||||||
|
|
||||||
buffer = HeapAlloc(GetProcessHeap(), 0, imgDataSize);
|
buffer = HeapAlloc(GetProcessHeap(), 0, imgDataSize);
|
||||||
|
if (!buffer)
|
||||||
|
return;
|
||||||
|
|
||||||
GetDIBits(hDC, hBitmap, 0, bm.bmHeight, buffer, (LPBITMAPINFO) & bi, DIB_RGB_COLORS);
|
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);
|
hFile = CreateFile(FileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
|
||||||
if (hFile == INVALID_HANDLE_VALUE)
|
if (hFile == INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
HeapFree(GetProcessHeap(), 0, buffer);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
WriteFile(hFile, &bf, sizeof(BITMAPFILEHEADER), &dwBytesWritten, NULL);
|
WriteFile(hFile, &bf, sizeof(BITMAPFILEHEADER), &dwBytesWritten, NULL);
|
||||||
WriteFile(hFile, &bi, sizeof(BITMAPINFOHEADER), &dwBytesWritten, NULL);
|
WriteFile(hFile, &bi, sizeof(BITMAPINFOHEADER), &dwBytesWritten, NULL);
|
||||||
|
|
Loading…
Reference in a new issue