Skip to content

Commit dfc9322

Browse files
committed
xerial#88: Applied a patch from @ewencp to fix missing reference problem of CachedBufferAllocator
1 parent 7b86642 commit dfc9322

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

src/main/java/org/xerial/snappy/buffer/CachedBufferAllocator.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,16 @@ public CachedBufferAllocator(int bufferSize) {
2929
}
3030

3131
public static synchronized CachedBufferAllocator getAllocator(int bufferSize) {
32-
if(!queueTable.containsKey(bufferSize)) {
33-
queueTable.put(bufferSize, new SoftReference<CachedBufferAllocator>(new CachedBufferAllocator(bufferSize)));
32+
CachedBufferAllocator result = null;
33+
34+
if (queueTable.containsKey(bufferSize)) {
35+
result = queueTable.get(bufferSize).get();
36+
}
37+
if (result == null) {
38+
result = new CachedBufferAllocator(bufferSize);
39+
queueTable.put(bufferSize, new SoftReference<CachedBufferAllocator>(result));
3440
}
35-
return queueTable.get(bufferSize).get();
41+
return result;
3642
}
3743

3844
@Override

0 commit comments

Comments
 (0)