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