diff --git a/dlls/gdi32/dib.c b/dlls/gdi32/dib.c
index 677cda5eb2c634180f68c7f3909fb003513c1ef4..440857dc243d7d38421272da1bf0d8dcb833a98c 100644
--- a/dlls/gdi32/dib.c
+++ b/dlls/gdi32/dib.c
@@ -1118,7 +1118,14 @@ HBITMAP WINAPI CreateDIBitmap( HDC hdc, const BITMAPINFOHEADER *header,
 
     if (handle)
     {
-        if (init == CBM_INIT) SetDIBits( hdc, handle, 0, height, bits, data, coloruse );
+        if (init == CBM_INIT)
+        {
+            if (SetDIBits( hdc, handle, 0, height, bits, data, coloruse ) == 0)
+            {
+                DeleteObject( handle );
+                handle = 0;
+            }
+        }
 
         else if (hdc && ((dc = get_dc_ptr( hdc )) != NULL) )
         {