#182: Various memory leaks
-------------------------------+--------------------------------------------
Reporter: john@… | Owner: bagder
Type: defect | Status: assigned
Priority: normal | Milestone: 1.2.6
Component: API | Version: 1.2.6
Resolution: | Keywords:
Blocks: | Blocked By:
-------------------------------+--------------------------------------------
Comment (by john@…):
Sorry I found some lines of code that set '''session->socket_state'''.
The main socket write/read functions '''_libssh2_recv'''
'''and_libssh2_send''' are only called in '''session.c''' and
'''transport.c'''. I have added the following to detect failures and mark
the socket_state as bad (disconnected). The assumption here is that any
error, other than EAGAIN, is due to a failed socket. Are you happy with
this assumption ?
'''diff -u session.c'''
--- session.c Thu Apr 29 22:55:49 2010
+++ /usr2/other/libssh2/libssh2-1.2.6/src/session.c Wed Jun 23
12:04:19 2010
@@ -129,6 +129,7 @@
return LIBSSH2_ERROR_EAGAIN;
}
+ session->socket_state = LIBSSH2_SOCKET_DISCONNECTED; /* show
socket disconnected */
/* Some kinda error */
session->banner_TxRx_state = libssh2_NB_state_idle;
session->banner_TxRx_total_send = 0;
@@ -243,6 +244,7 @@
session->banner_TxRx_total_send += ret;
return LIBSSH2_ERROR_EAGAIN;
}
+ session->socket_state = LIBSSH2_SOCKET_DISCONNECTED; /* show
socket disconnected */
session->banner_TxRx_state = libssh2_NB_state_idle;
session->banner_TxRx_total_send = 0;
return LIBSSH2_ERROR_SOCKET_NONE;
'''diff -u transport.c'''
--- transport.c Sun Apr 25 18:35:43 2010
+++ /usr2/other/libssh2/libssh2-1.2.6/src/transport.c Wed Jun 23
12:03:32 2010
@@ -393,6 +393,7 @@
LIBSSH2_SESSION_BLOCK_INBOUND;
return LIBSSH2_ERROR_EAGAIN;
}
+ session->socket_state = LIBSSH2_SOCKET_DISCONNECTED; /*
show socket disconnected */
return LIBSSH2_ERROR_SOCKET_NONE;
}
@@ -666,6 +667,7 @@
else if (rc < 0) {
/* nothing was sent */
if (errno != EAGAIN) {
+ session->socket_state = LIBSSH2_SOCKET_DISCONNECTED; /* show
socket disconnected */
/* send failure! */
return LIBSSH2_ERROR_SOCKET_NONE;
}
@@ -846,6 +848,7 @@
p->ototal_num = total_length;
return LIBSSH2_ERROR_EAGAIN;
}
+ session->socket_state = LIBSSH2_SOCKET_DISCONNECTED; /* show
socket disconnected */
return LIBSSH2_ERROR_SOCKET_NONE;
}
Once the '''session->socket_state''' has been marked as
LIBSSH2_SOCKET_DISCONNECTED the call to '''libssh2_channel_free''' works,
releasing the memory.
-- Ticket URL: <http://trac.libssh2.org/ticket/182#comment:4> libssh2 <http://trac.libssh2.org/> C library for writing portable SSH2 clients _______________________________________________ libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-develReceived on 2010-06-23