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) |
369 | 369 | super_data = (sftpfs_super_data_t *) super->data; |
370 | 370 | |
371 | 371 | super_data->session = NULL; |
372 | | super_data->socket_handle = -1; |
373 | 372 | super_data->agent = NULL; |
374 | 373 | super_data->sftp_session = NULL; |
375 | 374 | |
376 | | /* Create a session instance */ |
377 | | super_data->session = libssh2_session_init (); |
378 | | if (super_data->session == NULL) |
379 | | return (-1); |
380 | | |
381 | 375 | /* |
382 | 376 | * The application code is responsible for creating the socket |
383 | 377 | * and establishing the connection |
… |
… |
sftpfs_open_connection (struct vfs_s_super *super, GError ** mcerror) |
386 | 380 | if (super_data->socket_handle == -1) |
387 | 381 | return (-1); |
388 | 382 | |
| 383 | /* Create a session instance */ |
| 384 | super_data->session = libssh2_session_init (); |
| 385 | if (super_data->session == NULL) |
| 386 | return (-1); |
| 387 | |
389 | 388 | /* ... start it up. This will trade welcome banners, exchange keys, |
390 | 389 | * and setup crypto, compression, and MAC layers |
391 | 390 | */ |
… |
… |
sftpfs_close_connection (struct vfs_s_super *super, const char *shutdown_message |
442 | 441 | if (super_data == NULL) |
443 | 442 | return; |
444 | 443 | |
| 444 | if (super_data->sftp_session != NULL) |
| 445 | { |
| 446 | libssh2_sftp_shutdown (super_data->sftp_session); |
| 447 | super_data->sftp_session = NULL; |
| 448 | } |
| 449 | |
445 | 450 | if (super_data->agent != NULL) |
446 | 451 | { |
447 | 452 | libssh2_agent_disconnect (super_data->agent); |
… |
… |
sftpfs_close_connection (struct vfs_s_super *super, const char *shutdown_message |
449 | 454 | super_data->agent = NULL; |
450 | 455 | } |
451 | 456 | |
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; |
457 | 458 | |
458 | 459 | if (super_data->session != NULL) |
459 | 460 | { |
… |
… |
sftpfs_close_connection (struct vfs_s_super *super, const char *shutdown_message |
462 | 463 | super_data->session = NULL; |
463 | 464 | } |
464 | 465 | |
465 | | super_data->fingerprint = NULL; |
466 | | |
467 | 466 | if (super_data->socket_handle != -1) |
468 | 467 | { |
469 | 468 | close (super_data->socket_handle); |