Fixed a few memory leaks in error paths

This commit is contained in:
Dan Fandrich 2014-02-18 23:34:31 +01:00
parent 5559ad8fe1
commit 92d686fe19
3 changed files with 11 additions and 0 deletions

View File

@ -408,6 +408,7 @@ packet_x11_open(LIBSSH2_SESSION * session, unsigned char *data,
*
* The input pointer 'data' is pointing to allocated data that this function
* is asked to deal with so on failure OR success, it must be freed fine.
* The only exception is when the return code is LIBSSH2_ERROR_EAGAIN.
*
* This function will always be called with 'datalen' greater than zero.
*/
@ -967,6 +968,7 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
if (!packetp) {
_libssh2_debug(session, LIBSSH2_ERROR_ALLOC,
"memory for packet");
LIBSSH2_FREE(session, data);
session->packAdd_state = libssh2_NB_state_idle;
return LIBSSH2_ERROR_ALLOC;
}

View File

@ -1016,6 +1016,14 @@ session_free(LIBSSH2_SESSION *session)
if (session->scpSend_command) {
LIBSSH2_FREE(session, session->scpSend_command);
}
if (session->sftpInit_sftp) {
LIBSSH2_FREE(session, session->sftpInit_sftp);
}
/* Free payload buffer */
if (session->packet.total_num) {
LIBSSH2_FREE(session, session->packet.payload);
}
/* Cleanup all remaining packets */
while ((pkg = _libssh2_list_first(&session->packets))) {

View File

@ -844,6 +844,7 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session)
if (data_len < 5) {
_libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"Invalid SSH_FXP_VERSION response");
LIBSSH2_FREE(session, data);
goto sftp_init_error;
}