8013454: [parfait] Memory leak in jdk/src/windows/native/sun/windows/awt_Cursor.cpp
authorpchelko
Wed, 14 Aug 2013 16:17:28 +0400
changeset 19363 0b4d21558b32
parent 19362 9dc631273af7
child 19364 f6324eb18ece
8013454: [parfait] Memory leak in jdk/src/windows/native/sun/windows/awt_Cursor.cpp 8012079: [parfait] possible null pointer dereference in jdk/src/windows/native/sun/windows/awt_Font.cpp Reviewed-by: art, serb
jdk/src/windows/native/sun/windows/awt_Cursor.cpp
jdk/src/windows/native/sun/windows/awt_Font.cpp
--- a/jdk/src/windows/native/sun/windows/awt_Cursor.cpp	Tue Aug 13 15:49:37 2013 -0700
+++ b/jdk/src/windows/native/sun/windows/awt_Cursor.cpp	Wed Aug 14 16:17:28 2013 +0400
@@ -391,9 +391,16 @@
 
     DASSERT(hCursor);
 
-    AwtCursor::setPData(self, ptr_to_jlong(new AwtCursor(env, hCursor, self, xHotSpot,
-                                              yHotSpot, nW, nH, nSS, cols,
-                                              (BYTE *)andMaskPtr)));
+    try {
+        AwtCursor::setPData(self, ptr_to_jlong(new AwtCursor(env, hCursor, self, xHotSpot,
+                                                             yHotSpot, nW, nH, nSS, cols,
+                                                             (BYTE *)andMaskPtr)));
+    } catch (...) {
+        if (cols) {
+            delete[] cols;
+        }
+        throw;
+    }
     CATCH_BAD_ALLOC;
 }
 
--- a/jdk/src/windows/native/sun/windows/awt_Font.cpp	Tue Aug 13 15:49:37 2013 -0700
+++ b/jdk/src/windows/native/sun/windows/awt_Font.cpp	Wed Aug 14 16:17:28 2013 +0400
@@ -510,6 +510,11 @@
     jobject font = env->GetObjectField(fontMetrics, AwtFont::fontID);
     AwtFont* awtFont = AwtFont::GetFont(env, font);
 
+    if (!awtFont) {
+        /* failed to get font */
+        return;
+    }
+
     HDC hDC = ::GetDC(0);
     DASSERT(hDC != NULL);