Free readBuffer if the writeBuffer allocation fails

Signed-off-by: Graham <gpe@openrs2.dev>
Graham 4 years ago
parent 8cdd33a1dd
commit 5e447f31d6
  1. 14
      cache/src/main/java/dev/openrs2/cache/BufferedFileChannel.kt

@ -17,12 +17,22 @@ public class BufferedFileChannel(
) : Flushable, Closeable { ) : Flushable, Closeable {
private var size = channel.size() private var size = channel.size()
private val readBuffer = alloc.buffer(readBufferSize, readBufferSize) private val readBuffer: ByteBuf
private var readPos = -1L private var readPos = -1L
private val writeBuffer = alloc.buffer(writeBufferSize, writeBufferSize) private val writeBuffer: ByteBuf
private var writePos = -1L private var writePos = -1L
init {
val buf = alloc.buffer(readBufferSize, readBufferSize)
try {
writeBuffer = alloc.buffer(writeBufferSize, writeBufferSize)
readBuffer = buf.retain()
} finally {
buf.release()
}
}
public fun read(pos: Long, dest: ByteBuf, len: Int) { public fun read(pos: Long, dest: ByteBuf, len: Int) {
require(pos >= 0) require(pos >= 0)
require(len <= dest.writableBytes()) require(len <= dest.writableBytes())

Loading…
Cancel
Save