mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
8292279: (fs) Use try-with-resources to release NativeBuffer
Reviewed-by: alanb
This commit is contained in:
parent
a25e1dc53c
commit
1d9c2f7a6e
13 changed files with 61 additions and 168 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 2022, 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
|
||||
|
@ -36,13 +36,9 @@ class LinuxNativeDispatcher extends UnixNativeDispatcher {
|
|||
* FILE *setmntent(const char *filename, const char *type);
|
||||
*/
|
||||
static long setmntent(byte[] filename, byte[] type) throws UnixException {
|
||||
NativeBuffer pathBuffer = NativeBuffers.asNativeBuffer(filename);
|
||||
NativeBuffer typeBuffer = NativeBuffers.asNativeBuffer(type);
|
||||
try {
|
||||
try (NativeBuffer pathBuffer = NativeBuffers.asNativeBuffer(filename);
|
||||
NativeBuffer typeBuffer = NativeBuffers.asNativeBuffer(type)) {
|
||||
return setmntent0(pathBuffer.address(), typeBuffer.address());
|
||||
} finally {
|
||||
typeBuffer.release();
|
||||
pathBuffer.release();
|
||||
}
|
||||
}
|
||||
private static native long setmntent0(long pathAddress, long typeAddress)
|
||||
|
@ -53,11 +49,8 @@ class LinuxNativeDispatcher extends UnixNativeDispatcher {
|
|||
*/
|
||||
|
||||
static int getmntent(long fp, UnixMountEntry entry, int buflen) throws UnixException {
|
||||
NativeBuffer buffer = NativeBuffers.getNativeBuffer(buflen);
|
||||
try {
|
||||
try (NativeBuffer buffer = NativeBuffers.getNativeBuffer(buflen)) {
|
||||
return getmntent0(fp, entry, buffer.address(), buflen);
|
||||
} finally {
|
||||
buffer.release();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue