Don't touch TLS specific things w/o RS_ENABLE_TLS.
[radsecproxy.git] / lib / conn.c
index c60ecf9..36893bc 100644 (file)
 int
 conn_close (struct rs_connection **connp)
 {
-  int r;
+  int r = 0;
   assert (connp);
   assert (*connp);
-  r = rs_conn_destroy (*connp);
-  if (!r)
+  if ((*connp)->is_connected)
+    r = rs_conn_disconnect (*connp);
+  if (r == RSE_OK)
     *connp = NULL;
   return r;
 }
@@ -125,16 +126,25 @@ rs_conn_destroy (struct rs_connection *conn)
 
   if (conn->is_connected)
     err = rs_conn_disconnect (conn);
+
+#if defined (RS_ENABLE_TLS)
+  if (conn->tls_ssl) /* FIXME: Free SSL strucxt in rs_conn_disconnect?  */
+    SSL_free (conn->tls_ssl);
+  if (conn->tls_ctx)
+    SSL_CTX_free (conn->tls_ctx);
+#endif
+
   if (conn->tev)
     event_free (conn->tev);
   if (conn->bev)
     bufferevent_free (conn->bev);
+  if (conn->rev)
+    event_free (conn->rev);
+  if (conn->wev)
+    event_free (conn->wev);
   if (conn->evb)
     event_base_free (conn->evb);
 
-  /* TODO: free tls_ctx  */
-  /* TODO: free tls_ssl  */
-
   rs_free (conn->ctx, conn);
 
   return err;