From 46f59112d929cbaee1d20dde42e906aa1d575dd4 Mon Sep 17 00:00:00 2001 From: James Housley Date: Thu, 19 Jul 2007 15:02:37 +0000 Subject: [PATCH] * After setting the error to the error string from in the packet, set the pointer to NULL so it can't be double freed. * On session cleanup be sure to free the last error if it needs to be --- src/scp.c | 4 ++++ src/session.c | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/scp.c b/src/scp.c index e098bb5..cf17ee3 100644 --- a/src/scp.c +++ b/src/scp.c @@ -184,10 +184,12 @@ LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_recv(LIBSSH2_SESSION *session, const ch */ LIBSSH2_FREE(session, session->scpRecv_err_msg); session->scpRecv_err_msg = NULL; + libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Unknown error while getting error string", 0); goto scp_recv_error; } libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, session->scpRecv_err_msg, 1); + session->scpRecv_err_msg = NULL; goto scp_recv_error; } @@ -504,6 +506,7 @@ libssh2_scp_send_ex(LIBSSH2_SESSION *session, const char *path, int mode, size_t /* previous call set libssh2_session_last_error(), pass it through */ LIBSSH2_FREE(session, session->scpSend_command); session->scpSend_command = NULL; + libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Unknown error while getting error string", 0); goto scp_send_error; } LIBSSH2_FREE(session, session->scpSend_command); @@ -640,6 +643,7 @@ libssh2_scp_send_ex(LIBSSH2_SESSION *session, const char *path, int mode, size_t } libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, session->scpSend_err_msg, 1); + session->scpSend_err_msg = NULL; goto scp_send_error; } } diff --git a/src/session.c b/src/session.c index b809b75..2b444be 100644 --- a/src/session.c +++ b/src/session.c @@ -805,7 +805,18 @@ LIBSSH2_API int libssh2_session_free(LIBSSH2_SESSION *session) if (session->scpSend_command) { LIBSSH2_FREE(session, session->scpSend_command); } + if (session->scpRecv_err_msg) { + LIBSSH2_FREE(session, session->scpRecv_err_msg); + } + if (session->scpSend_err_msg) { + LIBSSH2_FREE(session, session->scpSend_err_msg); + } + /* Free the error message, if we ar supposed to */ + if (session->err_msg && session->err_should_free) { + LIBSSH2_FREE(session, session->err_msg); + } + /* Cleanup any remaining packets */ while (session->packets.head) { LIBSSH2_PACKET *tmp = session->packets.head;