1
1

Fixed a few memory leaks in error paths

Этот коммит содержится в:
Dan Fandrich 2014-02-18 23:34:31 +01:00
родитель 5559ad8fe1
Коммит 92d686fe19
3 изменённых файлов: 11 добавлений и 0 удалений

Просмотреть файл

@ -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 * 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. * 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. * 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) { if (!packetp) {
_libssh2_debug(session, LIBSSH2_ERROR_ALLOC, _libssh2_debug(session, LIBSSH2_ERROR_ALLOC,
"memory for packet"); "memory for packet");
LIBSSH2_FREE(session, data);
session->packAdd_state = libssh2_NB_state_idle; session->packAdd_state = libssh2_NB_state_idle;
return LIBSSH2_ERROR_ALLOC; return LIBSSH2_ERROR_ALLOC;
} }

Просмотреть файл

@ -1016,6 +1016,14 @@ session_free(LIBSSH2_SESSION *session)
if (session->scpSend_command) { if (session->scpSend_command) {
LIBSSH2_FREE(session, 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 */ /* Cleanup all remaining packets */
while ((pkg = _libssh2_list_first(&session->packets))) { while ((pkg = _libssh2_list_first(&session->packets))) {

Просмотреть файл

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