The examples out there all show, how to connect using libssh2 -- and it all starts with
calling socket(), and then applying connect() to the file-descriptor. You then call libssh2_session_handshake() with the connected socket and use continue using libssh2 API.
At the end one is supposed to call libssh2_session_disconnect() -- followed by libssh2_session_free() -- but nowhere does it explicitly say, whether the initialized (and connected) socket underneath the session is properly closed by that, or whether it remains my responsibility to deal with it.
My program opens a large number of connections, and I'd like to avoid leaking the file-descriptors for each...
Having run my program under
valgrind --track-fds=yes ..., I can confirm, that the sockets remain open... This is unfortunate, because there is no API-call to get the SSH2_SESSION's socket back -- one has to keep track of them separately.I added an argument to my own
newsession()function for that purpose:and modified the callers of
newsession()to explicitly close the sockets.I wish, I didn't have to do all that...