// Close closes the underlying connection.
// Close will return an error if it is invoked on a partially or already closed connection.
func (h HTTPSConn) Close() error {
	if (h.ctx != nil) && (h.sslInst != nil) && (h.sslBio != nil) {
		SSL_CTX_free(h.ctx)
		h.ctx = nil
		SSL_free(h.sslInst)
		h.sslInst = nil
		bio.BIO_free_all(h.sslBio)
		h.sslBio = nil
		return nil
	}

	if (h.ctx != nil) || (h.sslInst != nil) || (h.sslBio != nil) {
		return errors.New("HTTPSConn in partially closed state, not all objects freed, unable to close further")
	}

	return errors.New("Attempted to close already closed HTTPSConn")
}
			var sslInst SSL
			var conn bio.BIO
			var host, hostport string

			BeforeEach(func() {
				ctx = SSL_CTX_new(SSLv23_method())
				Expect(ctx).NotTo(BeNil())
				SSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, nil)
				SSL_CTX_set_verify_depth(ctx, 4)
				Expect(SSL_CTX_load_verify_locations(ctx, "", "/etc/ssl/certs")).To(Equal(1))
				sslInst = SSL_new(ctx)
				Expect(sslInst).NotTo(BeNil())
			})

			AfterEach(func() {
				bio.BIO_free_all(conn)
				SSL_free(sslInst)
				SSL_CTX_free(ctx)
			})

			It("Connects to a known site", func() {
				host = "www.random.org"
				hostport = "www.random.org:443"

				/* Setup the connect BIO, since we're a client */
				conn = bio.BIO_new_ssl_connect(ctx)
				Expect(conn).NotTo(BeNil())
				Expect(bio.BIO_set_conn_hostname(conn, hostport)).To(BeEquivalentTo(1))
				Expect(bio.BIO_get_conn_hostname(conn)).To(Equal(hostport))

				/* Setup SSL */