May somebody please answer this question? The documentation is
confusing and contradictory, and the issue is important (memory leak
or crash if the bad choice is made).

Thanks.

2014-07-15 14:01 GMT+02:00 Iñaki Baz Castillo <i...@aliax.net>:
> Hi, I'm a bit confused about how to free a BIO pair associated to a SSL.
>
> The doc at https://www.openssl.org/docs/crypto/BIO_s_bio.html clearly says:
>
> ----------------------------
> Both halves of a BIO pair should be freed. That is even if one half is
> implicit freed due to a BIO_free_all() or SSL_free() call the other
> half needs to be freed.
>
> EXAMPLE
>
> BIO *internal_bio, *network_bio;
> BIO_new_bio_pair(internal_bio, 0, network_bio, 0);
> SSL_set_bio(ssl, internal_bio, internal_bio);
> ...
> SSL_free(ssl);                /* implicitly frees internal_bio */
> BIO_free(network_bio);
> ----------------------------
>
>
> Is it true that I must call to BIO_free(network_bio)? The SSL_free()
> code "seems" to do it by itself!:
>
> --------------------------
> void SSL_free(SSL *s)
> {
>    ...
>    if (s->rbio != NULL)
>        BIO_free_all(s->rbio);
>    if ((s->wbio != NULL) && (s->wbio != s->rbio))
>        BIO_free_all(s->wbio);
> --------------------------
>
> In my code I get an obvious crash if I call BIO_free(internal_bio)
> after SSL_free(ssl), but I do NOT get a crash if I call
> BIO_free(network_bio).
>
>
> Anyhow in my code I do not use BIO_new_bio_pair() but instead:
>
> ------------------------
> BIO* internal_bio = BIO_new(BIO_s_mem());
> BIO* network_bio = BIO_new(BIO_s_mem());
> SSL_set_bio(ssl, internal_bio, network_bio);
>
> void destroy() {
>   if (ssl) {
>       SSL_free(ssl);
>   }
>
>
>   // This does NOT crash but, should I do it or not? leak otherwise?
>   if (write_bio) {
>       BIO_free(write_bio);
>   }
> }
> ------------------------
>
>
> Thanks a lot.
>
>
>
>
> --
> Iñaki Baz Castillo
> <i...@aliax.net>



-- 
Iñaki Baz Castillo
<i...@aliax.net>
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@openssl.org
Automated List Manager                           majord...@openssl.org

Reply via email to