sftp_packet_flush: flush zombies too

As this function is called when the SFTP session is closed, it needs to
also kill all zombies left in the SFTP session to avoid leaking memory
just in case some zombie would still be in there.
This commit is contained in:
Daniel Stenberg 2012-05-12 22:42:40 +02:00
parent a123051200
commit 27ac5aa40d

View File

@ -2174,13 +2174,15 @@ libssh2_sftp_tell64(LIBSSH2_SFTP_HANDLE *handle)
}
/*
* Flush all remaining incoming SFTP packets.
* Flush all remaining incoming SFTP packets and zombies.
*/
static void sftp_packet_flush(LIBSSH2_SFTP *sftp)
{
LIBSSH2_CHANNEL *channel = sftp->channel;
LIBSSH2_SESSION *session = channel->session;
LIBSSH2_SFTP_PACKET *packet = _libssh2_list_first(&sftp->packets);
struct sftp_zombie_requests *zombie =
_libssh2_list_first(&sftp->zombie_requests);
while(packet) {
LIBSSH2_SFTP_PACKET *next;
@ -2194,6 +2196,16 @@ static void sftp_packet_flush(LIBSSH2_SFTP *sftp)
packet = next;
}
while(zombie) {
/* figure out the next node */
struct sftp_zombie_requests *next = _libssh2_list_next(&zombie->node);
/* unlink the current one */
_libssh2_list_remove(&zombie->node);
/* free the memory */
LIBSSH2_FREE(session, zombie);
zombie = next;
}
}
/* sftp_close_handle