<commit_before>#include "sshchannel.h"
#include "sshclient.h"
#include <QCoreApplication>

Q_LOGGING_CATEGORY(sshchannel, "ssh.channel", QtWarningMsg)

SshChannel::SshChannel(QObject *client):
    QObject(client),
    sshChannel(nullptr),
    sshClient(nullptr)
{

}

SshChannel::SshChannel(SshClient *client) :
    QObject(client),
    sshChannel(nullptr),
    sshClient(client)
{
}

SshChannel::~SshChannel()
{
    stopChannel();
}

void SshChannel::stopChannel()
{
    if (sshChannel == nullptr)
        return;

    int ret = qssh2_channel_close(sshChannel);

    if(ret)
    {
        qCDebug(sshchannel) << "Failed to channel_close: LIBSSH2_ERROR_SOCKET_SEND";
        return;
    }

    ret = qssh2_channel_wait_closed(sshChannel);
    if(ret)
    {
        qCDebug(sshchannel) << "Failed to channel_wait_closed";
        return;
    }

    ret = qssh2_channel_free(sshChannel);
    if(ret)
    {
        qCDebug(sshchannel) << "Failed to channel_free";
        return;
    }
    sshChannel = nullptr;
}
<commit_msg>Fix a possible segfault in destructor of sshchannel.<commit_after>#include "sshchannel.h"
#include "sshclient.h"
#include <QCoreApplication>

Q_LOGGING_CATEGORY(sshchannel, "ssh.channel", QtWarningMsg)

SshChannel::SshChannel(QObject *client):
    QObject(client),
    sshChannel(nullptr),
    sshClient(nullptr)
{

}

SshChannel::SshChannel(SshClient *client) :
    QObject(client),
    sshChannel(nullptr),
    sshClient(client)
{
}

SshChannel::~SshChannel()
{
    stopChannel();
}

void SshChannel::stopChannel()
{
    if (sshChannel == nullptr)
        return;

    LIBSSH2_CHANNEL *tempChannel = sshChannel;
    sshChannel = nullptr;

    int ret = qssh2_channel_close(tempChannel);

    if(ret)
    {
        qCDebug(sshchannel) << "Failed to channel_close: LIBSSH2_ERROR_SOCKET_SEND";
        return;
    }

    ret = qssh2_channel_wait_closed(tempChannel);
    if(ret)
    {
        qCDebug(sshchannel) << "Failed to channel_wait_closed";
        return;
    }

    ret = qssh2_channel_free(tempChannel);
    if(ret)
    {
        qCDebug(sshchannel) << "Failed to channel_free";
        return;
    }
}

{'fraction_non_alphanumeric': 0.11891385767790262, 'fraction_numerical': 0.004213483146067416, 'mean_word_length': 3.4520833333333334, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7446332', 'n_tokens_mistral': 790, 'n_tokens_neox': 753, 'n_words': 120}