src/hotspot/share/prims/jniCheck.cpp
changeset 53712 e7d81a810546
parent 51467 12997ebbc0d8
child 57829 58891103f9cc
child 58678 9cf78a70fa4f
--- a/src/hotspot/share/prims/jniCheck.cpp	Fri Feb 08 05:46:11 2019 -0900
+++ b/src/hotspot/share/prims/jniCheck.cpp	Fri Feb 08 20:51:55 2019 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2019, 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
@@ -418,21 +418,20 @@
   size_t sz;
   void* orig_result = check_wrapped_array(thr, fn_name, obj, carray, &sz);
   switch (mode) {
+  // As we never make copies, mode 0 and JNI_COMMIT are the same.
   case 0:
-    memcpy(orig_result, carray, sz);
-    GuardedMemory::free_copy(carray);
-    break;
   case JNI_COMMIT:
     memcpy(orig_result, carray, sz);
     break;
   case JNI_ABORT:
-    GuardedMemory::free_copy(carray);
     break;
   default:
     tty->print_cr("%s: Unrecognized mode %i releasing array "
         PTR_FORMAT " elements " PTR_FORMAT, fn_name, mode, p2i(obj), p2i(carray));
     NativeReportJNIFatalError(thr, "Unrecognized array release mode");
   }
+  // We always need to release the copy we made with GuardedMemory
+  GuardedMemory::free_copy(carray);
   return orig_result;
 }