diff --git a/src/main/java/net/openhft/chronicle/hash/impl/VanillaChronicleHash.java b/src/main/java/net/openhft/chronicle/hash/impl/VanillaChronicleHash.java index dec6ed9c3..b9b1a873f 100644 --- a/src/main/java/net/openhft/chronicle/hash/impl/VanillaChronicleHash.java +++ b/src/main/java/net/openhft/chronicle/hash/impl/VanillaChronicleHash.java @@ -129,7 +129,7 @@ public abstract class VanillaChronicleHash implements //noinspection ResultOfMethodCallIgnored file.createNewFile(); } - ChronicleMap result = null; + VanillaChronicleMap result = null; RandomAccessFile raf = CanonicalRandomAccessFiles.acquire(file); try { if (raf.length() > 0) @@ -1461,8 +1461,11 @@ public final class ChronicleMapBuilder implements return result = openWithExistingFile(file, raf, recover, overrideBuilderConfig); } } finally { - if (result == null) + if (result != null) { + result.registerRafReleaser(); + } else { CanonicalRandomAccessFiles.release(file); + } } } @@ -1558,7 +1561,7 @@ public final class ChronicleMapBuilder implements return LongHashFunction.xx_r39().hashBytes(headerBuffer, SIZE_WORD_OFFSET, headerSize + 4); } - private ChronicleMap createWithNewFile( + private VanillaChronicleMap createWithNewFile( VanillaChronicleMap map, File file, RandomAccessFile raf, ByteBuffer headerBuffer, int headerSize) throws IOException { FileChannel fileChannel = raf.getChannel(); @@ -1569,7 +1572,7 @@ public final class ChronicleMapBuilder implements return map; } - private ChronicleMap openWithExistingFile( + private VanillaChronicleMap openWithExistingFile( File file, RandomAccessFile raf, boolean recover, boolean overrideBuilderConfig) throws IOException { try {