From a87fdff9e998bb735f576d428720154b9113801c Mon Sep 17 00:00:00 2001 From: James Housley Date: Mon, 9 Jul 2007 15:11:37 +0000 Subject: [PATCH] The variable "packet" needs to be in LIBSSH2_SFTP_HANDLE for re-entry when blocking in libssh2_sftp_close_handle() --- src/libssh2_priv.h | 1 + src/sftp.c | 14 ++++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h index 0aea395..c8a9e5a 100644 --- a/src/libssh2_priv.h +++ b/src/libssh2_priv.h @@ -487,6 +487,7 @@ struct _LIBSSH2_SFTP_HANDLE { /* State variables used in libssh2_sftp_close_handle() */ libssh2_nonblocking_states close_state; unsigned long close_request_id; + unsigned char *close_packet; }; struct _LIBSSH2_SFTP { diff --git a/src/sftp.c b/src/sftp.c index ff00a04..9d3325e 100644 --- a/src/sftp.c +++ b/src/sftp.c @@ -1375,13 +1375,13 @@ LIBSSH2_API int libssh2_sftp_close_handle(LIBSSH2_SFTP_HANDLE *handle) unsigned long data_len, retcode; /* 13 = packet_len(4) + packet_type(1) + request_id(4) + handle_len(4) */ ssize_t packet_len = handle->handle_len + 13; - unsigned char *packet, *s, *data; + unsigned char *s, *data; int rc; if (handle->close_state == libssh2_NB_state_idle) { _libssh2_debug(session, LIBSSH2_DBG_SFTP, "Closing handle"); - s = packet = LIBSSH2_ALLOC(session, packet_len); - if (!packet) { + s = handle->close_packet = LIBSSH2_ALLOC(session, packet_len); + if (!handle->close_packet) { libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate memory for FXP_CLOSE packet", 0); return -1; } @@ -1397,17 +1397,19 @@ LIBSSH2_API int libssh2_sftp_close_handle(LIBSSH2_SFTP_HANDLE *handle) } if (handle->close_state == libssh2_NB_state_created) { - rc = libssh2_channel_write_ex(channel, 0, (char *)packet, packet_len); + rc = libssh2_channel_write_ex(channel, 0, (char *)handle->close_packet, packet_len); if (rc == PACKET_EAGAIN) { return PACKET_EAGAIN; } else if (packet_len != rc) { libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, "Unable to send FXP_CLOSE command", 0); - LIBSSH2_FREE(session, packet); + LIBSSH2_FREE(session, handle->close_packet); + handle->close_packet = NULL; handle->close_state = libssh2_NB_state_idle; return -1; } - LIBSSH2_FREE(session, packet); + LIBSSH2_FREE(session, handle->close_packet); + handle->close_packet = NULL; handle->close_state = libssh2_NB_state_sent; }