Skip to content

Commit 3aa4cba

Browse files
committedOct 11, 2023
8316975: Memory leak in MTLSurfaceData
Reviewed-by: prr
1 parent 54861df commit 3aa4cba

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed
 

‎src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLSurfaceData.m

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -296,19 +296,19 @@ static jboolean MTLSurfaceData_initTexture(BMTLSDOps *bmtlsdo, jboolean isOpaque
296296
BMTLSDOps *bmtlsdo = (BMTLSDOps *)SurfaceData_InitOps(env, mtlsd, sizeof(BMTLSDOps));
297297
MTLSDOps *mtlsdo = (MTLSDOps *)malloc(sizeof(MTLSDOps));
298298

299+
if (mtlsdo == NULL) {
300+
JNU_ThrowOutOfMemoryError(env, "Initialization of SurfaceData failed.");
301+
return;
302+
}
303+
299304
J2dTraceLn1(J2D_TRACE_INFO, "MTLSurfaceData_initOps p=%p", bmtlsdo);
300305
J2dTraceLn1(J2D_TRACE_INFO, " pPeerData=%p", jlong_to_ptr(pPeerData));
301306
J2dTraceLn1(J2D_TRACE_INFO, " layerPtr=%p", jlong_to_ptr(layerPtr));
302307
J2dTraceLn2(J2D_TRACE_INFO, " xoff=%d, yoff=%d", (int)xoff, (int)yoff);
303308

304309
gc = (*env)->NewGlobalRef(env, gc);
305310
if (gc == NULL) {
306-
JNU_ThrowOutOfMemoryError(env, "Initialization of SurfaceData failed.");
307-
return;
308-
}
309-
310-
if (mtlsdo == NULL) {
311-
(*env)->DeleteGlobalRef(env, gc);
311+
free(mtlsdo);
312312
JNU_ThrowOutOfMemoryError(env, "Initialization of SurfaceData failed.");
313313
return;
314314
}

0 commit comments

Comments
 (0)
Please sign in to comment.