From 115be88e5dcc9e8ededc324f8b565ab6d35ebc9d Mon Sep 17 00:00:00 2001 From: "vladimir.kuznetsov" Date: Wed, 1 Feb 2023 09:56:55 +0300 Subject: [PATCH] added check for nullptr in sshclient --- client/core/sshclient.cpp | 5 ++++- client/core/sshclient.h | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/client/core/sshclient.cpp b/client/core/sshclient.cpp index a1a55538..89d6ddcb 100644 --- a/client/core/sshclient.cpp +++ b/client/core/sshclient.cpp @@ -26,7 +26,7 @@ namespace libssh { // qDebug() << "Failed to initialize ssh"; // return ErrorCode::InternalError; // } - if (m_session != NULL) { + if (m_session == nullptr) { m_session = ssh_new(); if (m_session == NULL) { @@ -80,6 +80,7 @@ namespace libssh { ssh_disconnect(m_session); } ssh_free(m_session); + m_session = nullptr; } } @@ -186,6 +187,7 @@ namespace libssh { ssh_channel_close(m_channel); } ssh_channel_free(m_channel); + m_channel = nullptr; } qDebug() << ssh_get_error(m_session); return fromLibsshErrorCode(ssh_get_error_code(m_session)); @@ -285,6 +287,7 @@ namespace libssh { auto errorCode = fromLibsshSftpErrorCode(sftp_get_error(m_sftpSession)); if (m_sftpSession != NULL) { sftp_free(m_sftpSession); + m_sftpSession = nullptr; } qDebug() << ssh_get_error(m_session); return errorCode; diff --git a/client/core/sshclient.h b/client/core/sshclient.h index 06f7a261..912748f0 100644 --- a/client/core/sshclient.h +++ b/client/core/sshclient.h @@ -42,9 +42,9 @@ namespace libssh { ErrorCode fromLibsshErrorCode(int errorCode); ErrorCode fromLibsshSftpErrorCode(int errorCode); - ssh_session m_session {}; - ssh_channel m_channel {}; - sftp_session m_sftpSession {}; + ssh_session m_session = nullptr; + ssh_channel m_channel = nullptr; + sftp_session m_sftpSession = nullptr; signals: void writeToChannelFinished(); void sftpFileCopyFinished();