changeset 47720:79efc2c3d832

8185739: Memory leak in BitmapUtil::BitmapToRgn Reviewed-by: serb, psadhukhan
author prr
date Wed, 08 Nov 2017 12:34:59 -0800
parents 3d660bb6b67d
children d2b306a70bf1 f2238a5326e7
files src/java.desktop/windows/native/libawt/windows/awt_BitmapUtil.cpp
diffstat 1 files changed, 16 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.desktop/windows/native/libawt/windows/awt_BitmapUtil.cpp	Wed Nov 08 12:27:40 2017 -0800
+++ b/src/java.desktop/windows/native/libawt/windows/awt_BitmapUtil.cpp	Wed Nov 08 12:34:59 2017 -0800
@@ -246,17 +246,28 @@
     UINT height = abs(bi.bmiHeader.biHeight);
 
     BYTE * buf = (BYTE*)safe_Malloc(bi.bmiHeader.biSizeImage);
+    if (!buf) {
+        ::DeleteDC(hdc);
+        return NULL;
+    }
     bi.bmiHeader.biHeight = -(INT)height;
     ::GetDIBits(hdc, hBitmap, 0, height, buf,
             reinterpret_cast<BITMAPINFO*>(&bi), DIB_RGB_COLORS);
 
     /* reserving memory for the worst case */
     if (!IS_SAFE_SIZE_MUL(width / 2 + 1, height)) {
-        throw std::bad_alloc();
+        ::DeleteDC(hdc);
+        free(buf);
+        return NULL;
     }
     RGNDATA * pRgnData = (RGNDATA *) SAFE_SIZE_STRUCT_ALLOC(safe_Malloc,
             sizeof(RGNDATAHEADER),
             sizeof(RECT), (width / 2 + 1) * height);
+    if (!pRgnData) {
+        ::DeleteDC(hdc);
+        free(buf);
+        return NULL;
+    }
     RGNDATAHEADER * pRgnHdr = (RGNDATAHEADER *) pRgnData;
     pRgnHdr->dwSize = sizeof(RGNDATAHEADER);
     pRgnHdr->iType = RDH_RECTANGLES;
@@ -309,6 +320,10 @@
     UINT height = abs(bi.bmiHeader.biHeight);
 
     BYTE * buf = (BYTE*)safe_Malloc(bi.bmiHeader.biSizeImage);
+    if (!buf) {
+        ::DeleteDC(hdc);
+        return NULL;
+    }
     bi.bmiHeader.biHeight = -(INT)height;
     ::GetDIBits(hdc, hSrcBitmap, 0, height, buf,
             reinterpret_cast<BITMAPINFO*>(&bi), DIB_RGB_COLORS);