diff --git a/src/main/java/com/github/luben/zstd/ZstdDictCompress.java b/src/main/java/com/github/luben/zstd/ZstdDictCompress.java index 6c2850c..547b004 100644 --- a/src/main/java/com/github/luben/zstd/ZstdDictCompress.java +++ b/src/main/java/com/github/luben/zstd/ZstdDictCompress.java @@ -95,7 +95,7 @@ public ZstdDictCompress(ByteBuffer dict, int level, boolean byReference) { throw new IllegalStateException("ZSTD_createCDict failed"); } if (byReference) { - sharedDict = dict; // ensures the dict is not garbage collected while this object remains, and flags that we should not use native free. + sharedDict = dict; // ensures the dict is not garbage collected while this object remains. } // Ensures that even if ZstdDictCompress is created and published through a race, no thread could observe // nativePtr == 0. @@ -110,12 +110,9 @@ int level() { @Override void doClose() { if (nativePtr != 0) { - if (sharedDict == null) { - free(); - } else { - sharedDict = null; - } + free(); nativePtr = 0; + sharedDict = null; } } } diff --git a/src/main/java/com/github/luben/zstd/ZstdDictDecompress.java b/src/main/java/com/github/luben/zstd/ZstdDictDecompress.java index 9026315..1c732de 100644 --- a/src/main/java/com/github/luben/zstd/ZstdDictDecompress.java +++ b/src/main/java/com/github/luben/zstd/ZstdDictDecompress.java @@ -86,7 +86,7 @@ public ZstdDictDecompress(ByteBuffer dict, boolean byReference) { throw new IllegalStateException("ZSTD_createDDict failed"); } if (byReference) { - sharedDict = dict; // ensures the dict is not garbage collected while this object remains, and flags that we should not use native free. + sharedDict = dict; // ensures the dict is not garbage collected while this object remains } // Ensures that even if ZstdDictDecompress is created and published through a race, no thread could observe // nativePtr == 0. @@ -97,12 +97,9 @@ public ZstdDictDecompress(ByteBuffer dict, boolean byReference) { @Override void doClose() { if (nativePtr != 0) { - if (sharedDict == null) { - free(); - } else { - sharedDict = null; - } + free(); nativePtr = 0; + sharedDict = null; } } }