Subject: Blocking/non-blocking and session disconnect

Blocking/non-blocking and session disconnect

From: Paulo Caetano <>
Date: Sat, 26 May 2012 19:18:36 +0100


I've been experimenting with ssh2_exec.c, and while reading the
mailing list "sftp functions leaking memory?" thread, I realized this
example may suffer from the same problem.

On line 142, we've got this:

    /* tell libssh2 we want it all done non-blocking */
    libssh2_session_set_blocking(session, 0);
Then, on the "shutdown" tag, we've got this:
                               "Normal Shutdown, Thank you for playing");
AFAICT, blocking is still off, so shutdown should be like this:
    while (libssh2_session_disconnect(session, "Normal Shutdown, Thank
you for playing") == LIBSSH2_ERROR_EAGAIN)
    while (libssh2_session_free(session) == LIBSSH2_ERROR_EAGAIN)
I've added no error cheking. Looking at session_disconnect() in
session.c, I was left with the impression that it only returns an
error if description (reason for disconnection) length > 256.
Otherwise, it always returns either LIBSSH2_ERROR_EAGAIN or 0.
Could you pls confirm if my reasoning is correct, so I may submit a
patch for this example?
Paulo Caetano
Received on 2012-05-26