mirror of
https://github.com/mihonapp/mihon.git
synced 2024-12-26 02:48:24 +01:00
Add safeguard to prevent ArchiveInputStream from being closed twice (#967)
* fix: Add safeguard to prevent ArchiveInputStream from being closed twice * detekt * lint: Make detekt happy --------- Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com>
This commit is contained in:
parent
c0f9de88e7
commit
e620665dda
@ -5,8 +5,14 @@ import me.zhanghai.android.libarchive.ArchiveEntry
|
||||
import me.zhanghai.android.libarchive.ArchiveException
|
||||
import java.io.InputStream
|
||||
import java.nio.ByteBuffer
|
||||
import kotlin.concurrent.Volatile
|
||||
|
||||
class ArchiveInputStream(buffer: Long, size: Long) : InputStream() {
|
||||
private val lock = Any()
|
||||
|
||||
@Volatile
|
||||
private var isClosed = false
|
||||
|
||||
private val archive = Archive.readNew()
|
||||
|
||||
init {
|
||||
@ -41,6 +47,11 @@ class ArchiveInputStream(buffer: Long, size: Long) : InputStream() {
|
||||
}
|
||||
|
||||
override fun close() {
|
||||
synchronized(lock) {
|
||||
if (isClosed) return
|
||||
isClosed = true
|
||||
}
|
||||
|
||||
Archive.readFree(archive)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user