8193234: When using -Xcheck:jni an internally allocated buffer can leak

Reviewed-by: shade, hseigel
This commit is contained in:
David Holmes 2019-02-08 20:51:55 -05:00
parent f14d0ac7b4
commit 3e904a4801

@ -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 @@ static void* check_wrapped_array_release(JavaThread* thr, const char* fn_name,
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;
}