Skip to content

Commit

Permalink
Don't keep ref to the dict if not loaded successfully
Browse files Browse the repository at this point in the history
  • Loading branch information
luben committed Nov 4, 2019
1 parent 7d4d544 commit 190e4f2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/main/java/com/github/luben/zstd/ZstdCompressCtx.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,16 @@ public void loadDict(ZstdDictCompress dict) {
if (nativePtr == 0) {
throw new IllegalStateException("Compression context is closed");
}
// keep a reference to the ditionary so it's not garbage collected
compression_dict = dict;

acquireSharedLock();
dict.acquireSharedLock();
try {
long result = loadCDictFast0(dict);
if (Zstd.isError(result)) {
throw new ZstdException(result);
}
// keep a reference to the dictionary so it's not garbage collected
compression_dict = dict;
} finally {
dict.releaseSharedLock();
releaseSharedLock();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/github/luben/zstd/ZstdDecompressCtx.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ public void loadDict(ZstdDictDecompress dict) {
if (nativePtr == 0) {
throw new IllegalStateException("Decompression context is closed");
}
// keep a reference to the ditionary so it's not garbage collected
decompression_dict = dict;
acquireSharedLock();
dict.acquireSharedLock();
try {
long result = loadDDictFast0(dict);
if (Zstd.isError(result)) {
throw new ZstdException(result);
}
// keep a reference to the dictionary so it's not garbage collected
decompression_dict = dict;
} finally {
dict.releaseSharedLock();
releaseSharedLock();
Expand Down

0 comments on commit 190e4f2

Please sign in to comment.