From 0b6013a4f621bbc69efa01aa957e1e2253dfeeb9 Mon Sep 17 00:00:00 2001 From: Pierre Schweitzer Date: Sat, 4 Oct 2014 15:41:38 +0000 Subject: [PATCH] [MSPAINT] - Check for correct allocation - Don't leak in case of file opening failure svn path=/trunk/; revision=64524 --- reactos/base/applications/mspaint/dib.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/reactos/base/applications/mspaint/dib.c b/reactos/base/applications/mspaint/dib.c index ee5bcb815e1..b9bcd59e451 100644 --- a/reactos/base/applications/mspaint/dib.c +++ b/reactos/base/applications/mspaint/dib.c @@ -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); -- 2.17.1