From 1ec8e7aa8a6ee79c58d5c9fb5e28579cbff2a1cd Mon Sep 17 00:00:00 2001 From: Petr Pchelko Date: Thu, 8 May 2014 16:50:42 +0400 Subject: [PATCH] 8036917: [macosx] Native memory leaks Reviewed-by: serb, azvegint --- jdk/src/macosx/native/sun/awt/CImage.m | 33 +++++++++++++------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/jdk/src/macosx/native/sun/awt/CImage.m b/jdk/src/macosx/native/sun/awt/CImage.m index b6db3458047..e4ef6306031 100644 --- a/jdk/src/macosx/native/sun/awt/CImage.m +++ b/jdk/src/macosx/native/sun/awt/CImage.m @@ -76,17 +76,17 @@ static void CImage_CopyNSImageIntoArray static NSBitmapImageRep* CImage_CreateImageRep(JNIEnv *env, jintArray buffer, jint width, jint height) { - NSBitmapImageRep* imageRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL - pixelsWide:width - pixelsHigh:height - bitsPerSample:8 - samplesPerPixel:4 - hasAlpha:YES - isPlanar:NO - colorSpaceName:NSDeviceRGBColorSpace - bitmapFormat:NSAlphaFirstBitmapFormat - bytesPerRow:width*4 // TODO: use explicit scanStride - bitsPerPixel:32]; + NSBitmapImageRep* imageRep = [[[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL + pixelsWide:width + pixelsHigh:height + bitsPerSample:8 + samplesPerPixel:4 + hasAlpha:YES + isPlanar:NO + colorSpaceName:NSDeviceRGBColorSpace + bitmapFormat:NSAlphaFirstBitmapFormat + bytesPerRow:width*4 // TODO: use explicit scanStride + bitsPerPixel:32] autorelease]; jint *imgData = (jint *)[imageRep bitmapData]; if (imgData == NULL) return 0L; @@ -115,9 +115,8 @@ JNF_COCOA_ENTER(env); NSBitmapImageRep* imageRep = CImage_CreateImageRep(env, buffer, width, height); if (imageRep) { - NSImage *nsImage = [[[NSImage alloc] initWithSize:NSMakeSize(width, height)] retain]; + NSImage *nsImage = [[NSImage alloc] initWithSize:NSMakeSize(width, height)]; [nsImage addRepresentation:imageRep]; - [imageRep release]; result = ptr_to_jlong(nsImage); } @@ -160,7 +159,7 @@ JNF_COCOA_ENTER(env); (*env)->ReleaseIntArrayElements(env, widths, ws, JNI_ABORT); } if ([reps count]) { - NSImage *nsImage = [[[NSImage alloc] initWithSize:NSMakeSize(0, 0)] retain]; + NSImage *nsImage = [[NSImage alloc] initWithSize:NSMakeSize(0, 0)]; [nsImage addRepresentations: reps]; result = ptr_to_jlong(nsImage); } @@ -184,7 +183,7 @@ JNF_COCOA_ENTER(env); IconRef iconRef; if (noErr == GetIconRef(kOnSystemDisk, kSystemIconsCreator, selector, &iconRef)) { - image = [[[NSImage alloc] initWithIconRef:iconRef] retain]; + image = [[NSImage alloc] initWithIconRef:iconRef]; ReleaseIconRef(iconRef); } @@ -206,7 +205,7 @@ JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CImage_nativeCreateNSImageFromFile JNF_COCOA_ENTER(env); NSString *path = JNFNormalizedNSStringForPath(env, file); - image = [[[NSImage alloc] initByReferencingFile:path] retain]; + image = [[NSImage alloc] initByReferencingFile:path]; JNF_COCOA_EXIT(env); @@ -435,7 +434,7 @@ JNIEXPORT jbyteArray JNICALL Java_sun_lwawt_macosx_CImage_nativeGetPlatformImage JNF_COCOA_ENTER(env); - NSBitmapImageRep* imageRep = [CImage_CreateImageRep(env, buffer, width, height) autorelease]; + NSBitmapImageRep* imageRep = CImage_CreateImageRep(env, buffer, width, height); if (imageRep) { NSData *tiffImage = [imageRep TIFFRepresentation]; jsize tiffSize = (jsize)[tiffImage length];