Skip to content

Commit

Permalink
Fix to issue Jeruntu#8 - Fixed crash
Browse files Browse the repository at this point in the history
This removes the reference counting on libssh2_init() and libssh2_exit()
If a instance of Ssh2Client is ever created, then connection is mad with QCoreApplication to exit libssh2 using libssh2_exit()
  • Loading branch information
vpicaver committed Jul 9, 2021
1 parent ea99091 commit 7c45dcc
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/Ssh2Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ SOFTWARE.

#include <QtCore/QTimer>
#include <QtNetwork/QHostAddress>
#include <QCoreApplication>

using namespace qlibssh2;

Expand All @@ -42,19 +43,17 @@ std::atomic<size_t> ssh2_initializations_count(0);

void initializeSsh2()
{
if (ssh2_initializations_count == 0)
if (ssh2_initializations_count == 0) {
libssh2_init(0);
QObject::connect(QCoreApplication::instance(), &QCoreApplication::aboutToQuit,
QCoreApplication::instance(), []()
{
libssh2_exit();
});
}
ssh2_initializations_count++;
};

void freeSsh2()
{
if (ssh2_initializations_count == 1)
libssh2_exit();
if (ssh2_initializations_count > 0)
ssh2_initializations_count--;
};

ssize_t libssh_recv(int socket, void* buffer, size_t length, int flags, void** abstract)
{
Q_UNUSED(socket);
Expand Down Expand Up @@ -104,7 +103,6 @@ Ssh2Client::~Ssh2Client()
closeSession();
if (state() == ConnectedState)
waitForDisconnected();
freeSsh2();
}

void Ssh2Client::connectToHost(const QString& hostName, qint16 port)
Expand Down

0 comments on commit 7c45dcc

Please sign in to comment.