Skip to content

Commit

Permalink
Merge pull request #4521 from nverwer/fix-resource-leak
Browse files Browse the repository at this point in the history
fix resource leak (and file lock)
  • Loading branch information
line-o authored Aug 25, 2022
2 parents 104ea82 + 103ba4b commit f3424d7
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
public class BinaryValueFromFile extends BinaryValue {

private final Path file;
private final RandomAccessFile fileHandle;
private final FileChannel channel;
private final MappedByteBuffer buf;
private final Optional<BiConsumer<Boolean, Path>> closeListener;
Expand All @@ -61,7 +62,8 @@ protected BinaryValueFromFile(final Expression expression, final BinaryValueMana
super(expression, manager, binaryValueType);
try {
this.file = file;
this.channel = new RandomAccessFile(file.toFile(), "r").getChannel();
this.fileHandle = new RandomAccessFile(file.toFile(), "r");
this.channel = fileHandle.getChannel();
this.buf = channel.map(MapMode.READ_ONLY, 0, channel.size());
this.closeListener = closeListener;
} catch (final IOException ioe) {
Expand Down Expand Up @@ -129,6 +131,7 @@ public void close() throws IOException {
boolean closed = false;
try {
channel.close();
fileHandle.close();
closed = true;
} finally {
final boolean finalClosed = closed;
Expand Down

0 comments on commit f3424d7

Please sign in to comment.