From 2c37aef2d80cf7f1d959414bd3ad3dd35947c894 Mon Sep 17 00:00:00 2001
From: hniksic <devnull@localhost>
Date: Fri, 30 Nov 2001 00:57:03 -0800
Subject: [PATCH] [svn] Don't forget to shutdown the SSL structure if the
 socket times out. Submitted by T. Bharath in
 <3B3DEBC7.2537186A@responsenetworks.com>.

---
 src/ChangeLog |  5 +++++
 src/http.c    | 22 +++++++++++++---------
 2 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index 15c0db94..47a852a2 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
+2001-11-30  T. Bharath  <TBharath@responsenetworks.com>
+
+	* http.c (persistent_available_p): Call SHUTDOWN_SSL if
+	test_socket_open fails.
+
 2001-11-30  Hrvoje Niksic  <hniksic@arsdigita.com>
 
 	* progress.c (display_image): Just print one CR to reset the
diff --git a/src/http.c b/src/http.c
index 9043527a..500e4b9f 100644
--- a/src/http.c
+++ b/src/http.c
@@ -374,6 +374,15 @@ register_persistent (const char *host, unsigned short port, int fd
   DEBUGP (("Registered fd %d for persistent reuse.\n", fd));
 }
 
+#ifdef HAVE_SSL
+# define SHUTDOWN_SSL(ssl) do {		\
+  if (ssl)				\
+    shutdown_ssl (ssl);			\
+} while (0)
+#else
+# define SHUTDOWN_SSL(ssl) 
+#endif
+
 /* Return non-zero if a persistent connection is available for
    connecting to HOST:PORT.  */
 
@@ -429,21 +438,16 @@ persistent_available_p (const char *host, unsigned short port
          let's invalidate the persistent connection before returning
          0.  */
       CLOSE (pc_last_fd);
+#ifdef HAVE_SSL
+      SHUTDOWN_SSL (pc_last_ssl);
+      pc_last_ssl = NULL;
+#endif
       invalidate_persistent ();
       return 0;
     }
   return 1;
 }
 
-#ifdef HAVE_SSL
-# define SHUTDOWN_SSL(ssl) do {		\
-  if (ssl)				\
-    shutdown_ssl (ssl);			\
-} while (0)
-#else
-# define SHUTDOWN_SSL(ssl) 
-#endif
-
 /* The idea behind these two CLOSE macros is to distinguish between
    two cases: one when the job we've been doing is finished, and we
    want to close the connection and leave, and two when something is