On Wed, 29 Jun 2016, Gou Lingfeng wrote:

My guess is that connections and session handles highly depend on one another (connection and disconnection need session data), but connection reusing needs some independence of connections.

I think you're right - and thanks a bunch for your excellent analysis and step by step description. It really made me understand the issue.

I think the freeing of the 'req.protop' in the disconnect function is totally wrong. The connection gets disconnected, it should not clear data in the easy handle just because of that.

See attachment for my suggested fix. I believe the free'ing should've been removed before already, we have just been lucky (or perhaps unlucky) that nobody else ran into this problem (or at least reported it) before.

--

 / daniel.haxx.se
From 7fef4e32a1952e70b9457dbe49804e8c61cc3e58 Mon Sep 17 00:00:00 2001
From: Daniel Stenberg <[email protected]>
Date: Wed, 29 Jun 2016 23:11:43 +0200
Subject: [PATCH] conn: don't free easy handle data in handler->disconnect

Reported-by: Gou Lingfeng
Bug: https://curl.haxx.se/mail/lib-2016-06/0139.html
---
 lib/smb.c | 1 -
 lib/ssh.c | 4 ----
 2 files changed, 5 deletions(-)

diff --git a/lib/smb.c b/lib/smb.c
index 2ddbb20..56a38c2 100644
--- a/lib/smb.c
+++ b/lib/smb.c
@@ -903,11 +903,10 @@ static CURLcode smb_disconnect(struct connectdata *conn, bool dead)
   Curl_safefree(smbc->recv_buf);
 
   /* smb_done is not always called, so cleanup the request */
   if(req) {
     Curl_safefree(req->share);
-    Curl_safefree(conn->data->req.protop);
   }
 
   return CURLE_OK;
 }
 
diff --git a/lib/ssh.c b/lib/ssh.c
index e72b756..7bc3136 100644
--- a/lib/ssh.c
+++ b/lib/ssh.c
@@ -3055,12 +3055,10 @@ static CURLcode scp_disconnect(struct connectdata *conn, bool dead_connection)
 {
   CURLcode result = CURLE_OK;
   struct ssh_conn *ssh = &conn->proto.sshc;
   (void) dead_connection;
 
-  Curl_safefree(conn->data->req.protop);
-
   if(ssh->ssh_session) {
     /* only if there's a session still around to use! */
 
     state(conn, SSH_SESSION_DISCONNECT);
 
@@ -3218,12 +3216,10 @@ static CURLcode sftp_disconnect(struct connectdata *conn, bool dead_connection)
   CURLcode result = CURLE_OK;
   (void) dead_connection;
 
   DEBUGF(infof(conn->data, "SSH DISCONNECT starts now\n"));
 
-  Curl_safefree(conn->data->req.protop);
-
   if(conn->proto.sshc.ssh_session) {
     /* only if there's a session still around to use! */
     state(conn, SSH_SFTP_SHUTDOWN);
     result = ssh_block_statemach(conn, FALSE);
   }
-- 
2.8.1

-------------------------------------------------------------------
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette:  https://curl.haxx.se/mail/etiquette.html

Reply via email to