Fixed SIGSEGV when dropping Channel from memory due to memory corruption
This commit is contained in:
parent
26f2aeaaf6
commit
21c64d390d
@ -42,17 +42,15 @@ class SshProcess : Process() {
|
||||
check(!isRunning())
|
||||
println("exitValue called")
|
||||
|
||||
channel.close()
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
override fun destroy() {
|
||||
if (channel.isOpen()) {
|
||||
channel.close()
|
||||
}
|
||||
closeChannel()
|
||||
}
|
||||
|
||||
println("Destroy called")
|
||||
fun closeChannel() {
|
||||
channel.close()
|
||||
}
|
||||
|
||||
private fun isRunning(): Boolean {
|
||||
|
@ -12,20 +12,20 @@ private const val NOT_EXPLICIT_PORT = -1
|
||||
class SshRemoteSession @Inject constructor(
|
||||
private val credentialsStateManager: CredentialsStateManager,
|
||||
) : RemoteSession {
|
||||
private var session: Session? = null
|
||||
|
||||
private lateinit var session: Session
|
||||
private lateinit var process: SshProcess
|
||||
override fun exec(commandName: String, timeout: Int): Process {
|
||||
println("Running command $commandName")
|
||||
|
||||
val session = this.session ?: throw Exception("Session is null")
|
||||
val process = SshProcess()
|
||||
process = SshProcess()
|
||||
|
||||
process.setup(session, commandName)
|
||||
return process
|
||||
}
|
||||
|
||||
override fun disconnect() {
|
||||
session?.disconnect()
|
||||
process.closeChannel()
|
||||
session.disconnect()
|
||||
}
|
||||
|
||||
fun setup(uri: URIish) {
|
||||
|
@ -5,10 +5,13 @@ import Session
|
||||
import com.jetpackduba.gitnuro.ssh.libssh.streams.SshChannelInputErrStream
|
||||
import com.jetpackduba.gitnuro.ssh.libssh.streams.SshChannelInputStream
|
||||
import com.jetpackduba.gitnuro.ssh.libssh.streams.SshChannelOutputStream
|
||||
import java.util.concurrent.Semaphore
|
||||
|
||||
class ChannelWrapper internal constructor(sshSession: Session) {
|
||||
private val channel = Channel.new(sshSession)
|
||||
|
||||
private var isClosed = false
|
||||
private var closeMutex = Semaphore(1)
|
||||
val outputStream = SshChannelOutputStream(channel)
|
||||
val inputStream = SshChannelInputStream(channel)
|
||||
val errorOutputStream = SshChannelInputErrStream(channel)
|
||||
@ -26,7 +29,15 @@ class ChannelWrapper internal constructor(sshSession: Session) {
|
||||
}
|
||||
|
||||
fun close() {
|
||||
channel.closeChannel()
|
||||
channel.close()
|
||||
closeMutex.acquire()
|
||||
try {
|
||||
if (!isClosed) {
|
||||
channel.closeChannel()
|
||||
channel.close()
|
||||
isClosed = true
|
||||
}
|
||||
} finally {
|
||||
closeMutex.release()
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user