Author: gschneider
Date: Sat Aug 22 18:56:28 2009
New Revision: 42856
URL: 
http://svn.reactos.org/svn/reactos?rev=42856&view=rev
Log:
- Handle failed memory allocation in CreateDIBitmap, check initialize option before
allocating and copying
Modified:
    trunk/reactos/dll/win32/gdi32/objects/bitmap.c
Modified: trunk/reactos/dll/win32/gdi32/objects/bitmap.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/gdi32/objects/bi…
==============================================================================
--- trunk/reactos/dll/win32/gdi32/objects/bitmap.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/gdi32/objects/bitmap.c [iso-8859-1] Sat Aug 22 18:56:28 2009
@@ -501,11 +501,18 @@
      hBmp = GetStockObject(DEFAULT_BITMAP);
   else
   {
-     if ( Bits )
+     if ( Bits && Init == CBM_INIT )
      {
         pvSafeBits = RtlAllocateHeap(GetProcessHeap(), 0, cjBmpScanSize);
-        if ( pvSafeBits )
+        if (pvSafeBits == NULL)
+        {
+            hBmp = NULL;
+            goto Exit;
+        }
+        else
+        {
            RtlCopyMemory( pvSafeBits, Bits, cjBmpScanSize);
+        }
      }
      hBmp = NtGdiCreateDIBitmapInternal(hDC,
@@ -520,7 +527,7 @@
                                         0,
                                         0);
-     if ( Bits )
+     if ( Bits && Init == CBM_INIT )
         RtlFreeHeap(RtlGetProcessHeap(), 0, pvSafeBits);
   }
 Exit: