Subject: Re: blocking redone committed

Re: blocking redone committed

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Tue, 31 Mar 2009 10:45:40 +0200 (CEST)

On Tue, 31 Mar 2009, Yang Tse wrote:

> And after some convoluted memory allocation logging I can confirm that on
> this platform in all cases the leaked memory is the block that you've
> already pointed out previously which is allocated at sftp.c:621 for
> session->sftpInit_sftp.
>
> And except for the case of a failure inside sftp_init() I've been unable to
> find any other location where this memory is actually deallocated. I guess
> that this could probably be done in sftp_shutdown() or session_free().

It is slightly complicated:

  * At line src/sftp.c:702 the sftpInit_sftp handle is stored in the channel
    struct together with the associated libssh2_sftp_dtor function.

  * When channel_close() is called (which in libcurl's case should happen when
    libssh2_channel_free() gets called) it calls the previously stored callback
    and that function (libssh2_sftp_dtor) then frees the data.

Quite clearly it's not called and thus it doesn't free the data.

This would happen if the condition on src/channel.c:2450 never evaluates true,
as then it'll simply skip the channel close phase.

Perhaps you could apply the following debug-patch to see what happens:

diff -u -r1.83 channel.c
--- channel.c 29 Mar 2009 22:09:29 -0000 1.83
+++ channel.c 31 Mar 2009 08:44:07 -0000
@@ -2449,6 +2449,8 @@
      /* Allow channel freeing even when the socket has lost its connection */
      if (!channel->local.close
          && (session->socket_state == LIBSSH2_SOCKET_CONNECTED)) {
+ fprintf(stderr, "%s: channel_close\n",
+ channel->local.close, session->socket_state);
          rc = channel_close(channel);
          if(rc == PACKET_EAGAIN)
              return rc;
@@ -2458,6 +2460,10 @@
              return -1;
          }
      }
+ else {
+ fprintf(stderr, "%s: local.close: %d socket_state: %d\n",
+ channel->local.close, session->socket_state);_
+ }

      channel->free_state = libssh2_NB_state_idle;

-- 
  / daniel.haxx.se
------------------------------------------------------------------------------
_______________________________________________
libssh2-devel mailing list
libssh2-devel_at_lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libssh2-devel
Received on 2009-03-31