]> granicus.if.org Git - libevent/commitdiff
Fix a case where an ssl bufferevent with CLOSE_ON_FREE didn't close its fd
authorNick Mathewson <nickm@torproject.org>
Thu, 14 Oct 2010 15:41:10 +0000 (11:41 -0400)
committerNick Mathewson <nickm@torproject.org>
Thu, 14 Oct 2010 16:17:24 +0000 (12:17 -0400)
This could happen when we got an SSL with a BIO already set on it.

bufferevent_openssl.c

index cee24aae1eb32b681ff21620fedf11fb38cb0adf..529c1a87703e728ab990ff070e713da9d65f39ee 100644 (file)
@@ -1271,6 +1271,8 @@ bufferevent_openssl_socket_new(struct event_base *base,
        /* Does the SSL already have an fd? */
        BIO *bio = SSL_get_wbio(ssl);
        long have_fd = -1;
+       const int shutdown_flag = !!(options & BEV_OPT_CLOSE_ON_FREE);
+
        if (bio)
                have_fd = BIO_get_fd(bio, NULL);
 
@@ -1286,13 +1288,11 @@ bufferevent_openssl_socket_new(struct event_base *base,
                           This is probably an error on our part.  Fail. */
                        return NULL;
                }
+               (void) BIO_set_close(bio, shutdown_flag);
        } else {
                /* The SSL isn't configured with a BIO with an fd. */
                if (fd >= 0) {
                        /* ... and we have an fd we want to use. */
-                       int shutdown_flag = 0;
-                       if (options & BEV_OPT_CLOSE_ON_FREE)
-                               shutdown_flag = 1;
                        bio = BIO_new_socket(fd, shutdown_flag);
                        SSL_set_bio(ssl, bio, bio);
                } else {