Ticket #3581: mc-3581-sftp-fix-connection-memleaks-0004.patch

File mc-3581-sftp-fix-connection-memleaks-0004.patch, 2.6 KB (added by and, 9 years ago)
  • src/vfs/sftpfs/connection.c

    From 421e03211d49f6129a02d88b39771763699d8e95 Mon Sep 17 00:00:00 2001
    From: Andreas Mohr <and@gmx.li>
    Date: Sun, 3 Jan 2016 17:36:34 +0000
    Subject: [PATCH 04/05] sftp: fix connection memleaks (cosmetic)
    
    re-order open_connection and reverse re-order close_connection steps
    
    Signed-off-by: Andreas Mohr <and@gmx.li>
    ---
     src/vfs/sftpfs/connection.c | 25 ++++++++++++-------------
     1 file changed, 12 insertions(+), 13 deletions(-)
    
    diff --git a/src/vfs/sftpfs/connection.c b/src/vfs/sftpfs/connection.c
    index b3fe4d0..03a5b7e 100644
    a b sftpfs_open_connection (struct vfs_s_super *super, GError ** mcerror) 
    369369    super_data = (sftpfs_super_data_t *) super->data; 
    370370 
    371371    super_data->session = NULL; 
    372     super_data->socket_handle = -1; 
    373372    super_data->agent = NULL; 
    374373    super_data->sftp_session = NULL; 
    375374 
    376     /* Create a session instance */ 
    377     super_data->session = libssh2_session_init (); 
    378     if (super_data->session == NULL) 
    379         return (-1); 
    380  
    381375    /* 
    382376     * The application code is responsible for creating the socket 
    383377     * and establishing the connection 
    sftpfs_open_connection (struct vfs_s_super *super, GError ** mcerror) 
    386380    if (super_data->socket_handle == -1) 
    387381        return (-1); 
    388382 
     383    /* Create a session instance */ 
     384    super_data->session = libssh2_session_init (); 
     385    if (super_data->session == NULL) 
     386        return (-1); 
     387 
    389388    /* ... start it up. This will trade welcome banners, exchange keys, 
    390389     * and setup crypto, compression, and MAC layers 
    391390     */ 
    sftpfs_close_connection (struct vfs_s_super *super, const char *shutdown_message 
    442441    if (super_data == NULL) 
    443442        return; 
    444443 
     444    if (super_data->sftp_session != NULL) 
     445    { 
     446        libssh2_sftp_shutdown (super_data->sftp_session); 
     447        super_data->sftp_session = NULL; 
     448    } 
     449 
    445450    if (super_data->agent != NULL) 
    446451    { 
    447452        libssh2_agent_disconnect (super_data->agent); 
    sftpfs_close_connection (struct vfs_s_super *super, const char *shutdown_message 
    449454        super_data->agent = NULL; 
    450455    } 
    451456 
    452     if (super_data->sftp_session != NULL) 
    453     { 
    454         libssh2_sftp_shutdown (super_data->sftp_session); 
    455         super_data->sftp_session = NULL; 
    456     } 
     457    super_data->fingerprint = NULL; 
    457458 
    458459    if (super_data->session != NULL) 
    459460    { 
    sftpfs_close_connection (struct vfs_s_super *super, const char *shutdown_message 
    462463        super_data->session = NULL; 
    463464    } 
    464465 
    465     super_data->fingerprint = NULL; 
    466  
    467466    if (super_data->socket_handle != -1) 
    468467    { 
    469468        close (super_data->socket_handle);