Skip to content

Commit f3424d7

Browse files
authored
Merge pull request #4521 from nverwer/fix-resource-leak
fix resource leak (and file lock)
2 parents 104ea82 + 103ba4b commit f3424d7

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

exist-core/src/main/java/org/exist/xquery/value/BinaryValueFromFile.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
public class BinaryValueFromFile extends BinaryValue {
5050

5151
private final Path file;
52+
private final RandomAccessFile fileHandle;
5253
private final FileChannel channel;
5354
private final MappedByteBuffer buf;
5455
private final Optional<BiConsumer<Boolean, Path>> closeListener;
@@ -61,7 +62,8 @@ protected BinaryValueFromFile(final Expression expression, final BinaryValueMana
6162
super(expression, manager, binaryValueType);
6263
try {
6364
this.file = file;
64-
this.channel = new RandomAccessFile(file.toFile(), "r").getChannel();
65+
this.fileHandle = new RandomAccessFile(file.toFile(), "r");
66+
this.channel = fileHandle.getChannel();
6567
this.buf = channel.map(MapMode.READ_ONLY, 0, channel.size());
6668
this.closeListener = closeListener;
6769
} catch (final IOException ioe) {
@@ -129,6 +131,7 @@ public void close() throws IOException {
129131
boolean closed = false;
130132
try {
131133
channel.close();
134+
fileHandle.close();
132135
closed = true;
133136
} finally {
134137
final boolean finalClosed = closed;

0 commit comments

Comments
 (0)