Skip to content

Commit

Permalink
Add safeguard to prevent ArchiveInputStream from being closed twice (#…
Browse files Browse the repository at this point in the history
…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>
  • Loading branch information
null2264 and AntsyLich authored Jun 30, 2024
1 parent c0f9de8 commit e620665
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -41,6 +47,11 @@ class ArchiveInputStream(buffer: Long, size: Long) : InputStream() {
}

override fun close() {
synchronized(lock) {
if (isClosed) return
isClosed = true
}

Archive.readFree(archive)
}

Expand Down

0 comments on commit e620665

Please sign in to comment.