Fri, 08 Feb 2019 20:51:55 -0500
8193234: When using -Xcheck:jni an internally allocated buffer can leak
Reviewed-by: shade, hseigel
src/share/vm/prims/jniCheck.cpp | file | annotate | diff | comparison | revisions |
1.1 --- a/src/share/vm/prims/jniCheck.cpp Tue Jul 18 09:53:54 2017 +0200 1.2 +++ b/src/share/vm/prims/jniCheck.cpp Fri Feb 08 20:51:55 2019 -0500 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -428,21 +428,20 @@ 1.11 size_t sz; 1.12 void* orig_result = check_wrapped_array(thr, fn_name, obj, carray, &sz); 1.13 switch (mode) { 1.14 + // As we never make copies, mode 0 and JNI_COMMIT are the same. 1.15 case 0: 1.16 - memcpy(orig_result, carray, sz); 1.17 - GuardedMemory::free_copy(carray); 1.18 - break; 1.19 case JNI_COMMIT: 1.20 memcpy(orig_result, carray, sz); 1.21 break; 1.22 case JNI_ABORT: 1.23 - GuardedMemory::free_copy(carray); 1.24 break; 1.25 default: 1.26 tty->print_cr("%s: Unrecognized mode %i releasing array " 1.27 PTR_FORMAT " elements " PTR_FORMAT, fn_name, mode, p2i(obj), p2i(carray)); 1.28 NativeReportJNIFatalError(thr, "Unrecognized array release mode"); 1.29 } 1.30 + // We always need to release the copy we made with GuardedMemory 1.31 + GuardedMemory::free_copy(carray); 1.32 return orig_result; 1.33 } 1.34