8234323: NULL-check return value of SurfaceData_InitOps on macosx
authormbaesken
Tue, 19 Nov 2019 09:56:43 +0100
changeset 59166 51673a0b6df0
parent 59165 2c55c2fc08f5
child 59196 7567ce83f3b5
8234323: NULL-check return value of SurfaceData_InitOps on macosx Reviewed-by: clanger
src/java.desktop/macosx/native/libawt_lwawt/awt/ImageSurfaceData.m
src/java.desktop/macosx/native/libawt_lwawt/awt/PrinterSurfaceData.m
--- a/src/java.desktop/macosx/native/libawt_lwawt/awt/ImageSurfaceData.m	Wed Nov 20 05:58:19 2019 +0000
+++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/ImageSurfaceData.m	Tue Nov 19 09:56:43 2019 +0100
@@ -1768,6 +1768,10 @@
 PRINT("Java_sun_java2d_OSXOffScreenSurfaceData_initRaster")
 
     ImageSDOps* isdo = (ImageSDOps*)SurfaceData_InitOps(env, bisd, sizeof(ImageSDOps));
+    if (isdo == NULL) {
+        JNU_ThrowOutOfMemoryError(env, "Initialization of SurfaceData failed.");
+        return;
+    }
 
     pthread_mutexattr_t attr;
     pthread_mutexattr_init(&attr);
--- a/src/java.desktop/macosx/native/libawt_lwawt/awt/PrinterSurfaceData.m	Wed Nov 20 05:58:19 2019 +0000
+++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/PrinterSurfaceData.m	Tue Nov 19 09:56:43 2019 +0100
@@ -25,6 +25,7 @@
 
 
 #import "PrinterSurfaceData.h"
+#import "jni_util.h"
 #import <JavaNativeFoundation/JavaNativeFoundation.h>
 
 
@@ -87,6 +88,11 @@
 PRINT("Java_sun_lwawt_macosx_CPrinterSurfaceData_initOps")
 
     PrintSDOps *psdo = (PrintSDOps*)SurfaceData_InitOps(env, jthis, sizeof(PrintSDOps));
+    if (psdo == NULL) {
+        JNU_ThrowOutOfMemoryError(env, "Initialization of SurfaceData failed.");
+        return;
+    }
+
     psdo->nsRef            = (NSGraphicsContext*)jlong_to_ptr(nsRef);
     psdo->width            = width;
     psdo->height        = height;