changeset 53220:56fbb14251ca

8215411: some GetByteArrayElements calls miss corresponding Release Reviewed-by: dholmes, jcbeyler
author mbaesken
date Wed, 19 Dec 2018 10:30:43 +0100
parents f15af1e2c683
children fd2e8f941ded
files src/java.base/macosx/native/libosxsecurity/KeystoreImpl.m src/jdk.attach/windows/native/libattach/VirtualMachineImpl.c src/jdk.hotspot.agent/windows/native/libsaproc/sawindbg.cpp
diffstat 3 files changed, 16 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/macosx/native/libosxsecurity/KeystoreImpl.m	Tue Dec 18 16:50:35 2018 +0000
+++ b/src/java.base/macosx/native/libosxsecurity/KeystoreImpl.m	Wed Dec 19 10:30:43 2018 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -578,13 +578,15 @@
         cssmPerror("_addItemToKeychain: SecKeychainItemImport", err);
     }
 
-    (*env)->ReleaseByteArrayElements(env, rawDataObj, rawData, JNI_ABORT);
-
     if (createdItems != NULL) {
         CFRelease(createdItems);
     }
 
 errOut:
+    if (rawData) {
+        (*env)->ReleaseByteArrayElements(env, rawDataObj, rawData, JNI_ABORT);
+    }
+
     if (passwordStrRef) CFRelease(passwordStrRef);
     if (passwordChars) {
         // clear the password and release
--- a/src/jdk.attach/windows/native/libattach/VirtualMachineImpl.c	Tue Dec 18 16:50:35 2018 +0000
+++ b/src/jdk.attach/windows/native/libattach/VirtualMachineImpl.c	Wed Dec 19 10:30:43 2018 +0100
@@ -457,12 +457,11 @@
     if (pCode == NULL) {
         JNU_ThrowIOExceptionWithLastError(env, "VirtualAllocEx failed");
         VirtualFreeEx(hProcess, pData, 0, MEM_RELEASE);
+        (*env)->ReleaseByteArrayElements(env, stub, stubCode, JNI_ABORT);
         return;
     }
     WriteProcessMemory( hProcess, (LPVOID)pCode, (LPCVOID)stubCode, (SIZE_T)stubLen, NULL );
-    if (isCopy) {
-        (*env)->ReleaseByteArrayElements(env, stub, stubCode, JNI_ABORT);
-    }
+    (*env)->ReleaseByteArrayElements(env, stub, stubCode, JNI_ABORT);
 
     /*
      * Create thread in target process to execute code
--- a/src/jdk.hotspot.agent/windows/native/libsaproc/sawindbg.cpp	Tue Dec 18 16:50:35 2018 +0000
+++ b/src/jdk.hotspot.agent/windows/native/libsaproc/sawindbg.cpp	Wed Dec 19 10:30:43 2018 +0100
@@ -722,19 +722,25 @@
 
   IDebugDataSpaces* ptrIDebugDataSpaces = (IDebugDataSpaces*) env->GetLongField(obj,
                                                        ptrIDebugDataSpaces_ID);
-  CHECK_EXCEPTION_(0);
+  if (env->ExceptionOccurred()) {
+     env->ReleaseByteArrayElements(byteArray, bytePtr, JNI_ABORT);
+     return 0;
+  }
 
   ULONG bytesRead;
   if (ptrIDebugDataSpaces->ReadVirtual((ULONG64) address, (PVOID) bytePtr,
                                   (ULONG)numBytes, &bytesRead) != S_OK) {
-     THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: ReadVirtual failed!", 0);
+     env->ReleaseByteArrayElements(byteArray, bytePtr, JNI_ABORT);
+     throwNewDebuggerException(env, "Windbg Error: ReadVirtual failed!");
+     return 0;
   }
 
   if (bytesRead != numBytes) {
+     env->ReleaseByteArrayElements(byteArray, bytePtr, JNI_ABORT);
      return 0;
   }
+  env->ReleaseByteArrayElements(byteArray, bytePtr, 0);
 
-  env->ReleaseByteArrayElements(byteArray, bytePtr, 0);
   CHECK_EXCEPTION_(0);
 
   return byteArray;