Commit 27de0ad0 authored by Lefebvre, Jordan's avatar Lefebvre, Jordan

#2. Cleaning memory defects.

parent 3d94b5c0
Pipeline #100419 failed with stages
in 5 minutes and 17 seconds
......@@ -246,7 +246,10 @@ ssize_t SFTPFile::write(QString str)
// success
QString SFTPFile::read(size_t nBytes)
{
char* buf = new char[nBytes + 1];
if (nBytes == 0) return QString();
char* buf = new char[nBytes + 1];
// initialize buff
memset(&buf[0], 0, nBytes);
buf[nBytes] = '\0';
ssize_t nBytesRead = sftp_read(p->file, buf, nBytes);
if (nBytesRead < 0)
......@@ -352,6 +355,9 @@ SFTPAttributes* SFTPDir::next()
retVal->extended_data =
QString(ssh_string_get_char(sftpResult->extended_data));
// release memory
sftp_attributes_free(sftpResult);
return retVal;
}
......@@ -382,7 +388,6 @@ class SessionImpl
if (session != nullptr)
{
ssh_free(session);
ssh_finalize();
}
}
}; // class SessionImpl
......@@ -410,18 +415,16 @@ QString Session::host() const
{
// This may not be necessary
assert_ssh_session(p->session, "host() -- Session is not allocated.");
char* host_name;
char* host_name = nullptr;
QString host;
int rv = ssh_options_get(p->session, SSH_OPTIONS_HOST, &host_name);
if (rv == SSH_OK)
{
QString host = host_name;
delete host_name;
return host;
}
else
{
return QString("");
host = host_name;
}
if (host_name != nullptr) ssh_string_free_char(host_name);
return host;
}
void Session::setLogVerbosity(SessionVerbosity level)
{
......@@ -445,18 +448,15 @@ QString Session::user() const
{
// This may not be necessary
assert_ssh_session(p->session, "user() -- Session is not allocated.");
char* user_name;
char* user_name = nullptr;
QString user;
int rv = ssh_options_get(p->session, SSH_OPTIONS_USER, &user_name);
if (rv == SSH_OK)
{
QString user = user_name;
delete user_name;
return user;
}
else
{
return QString("");
user = user_name;
}
if (user_name != nullptr) ssh_string_free_char(user_name);
return user;
}
void Session::setProxyCommand(QString command)
......@@ -479,6 +479,7 @@ bool Session::connect()
radix_tagged_line("Attempting connection.");
// attempt a connection
int rc = ssh_connect(p->session);
radix_tagged_line("\tConnect return: " << rc);
return (rc == SSH_OK);
}
}
......@@ -498,7 +499,7 @@ bool Session::disconnect()
{
assert_ssh_session(p->session, "disconnect() -- Session is not allocated.");
radix_tagged_line("disconnect()");
if (ssh_is_connected(p->session) != 0)
if (isConnected())
{
radix_tagged_line("Disconnecting session.");
ssh_disconnect(p->session);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment