mirror of
https://git.mihon.tech/mihonapp/mihon
synced 2024-11-24 22:25:53 +03: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
1 changed files with 11 additions and 0 deletions
|
@ -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 a new issue