Hi!

I am working on a BIO-pair setup and ran into a question regarding the
process of free()ing the objects after usage.

Considered the following sequence:

typedef struct {
SSL *con;
BIO *internal_bio;
BIO *network_bio;
... } TLScontext_t;
TLScontext_t *TLScontext;

...

TLScontext->con = SSL_new(ctx);
BIO_new_bio_pair(&TLScontext->internal_bio, BIO_bufsiz,
                 &TLScontext->network_bio, BIO_bufsiz));
SSL_set_bio(TLScontext->con, TLScontext->internal_bio,
            TLScontext->internal_bio);

[perform networking with SSL_accept()/read()/write()/shutdown() on the
 internal side and the TLScontext->network_bio for the socket communication]

I now would call:
BIO_free(TLScontext->internal_bio);
BIO_free(TLScontext->network_bio);
SSL_free(TLScontext->con);

But this seems to be wrong, since the TLScontext->internal_bio is connected
to the SSL connection TLScontext->con.
So when I call SSL_free() it tries to free again the already BIO_free()ed
TLScontext->internal_bio...
The other way round (SSL_free() first) the same problem applies.

Following my analysis, the _correct_ way of releasing the BIOs is:
        /*
         * Free the SSL structure and the BIOs. Warning: the internal_bio is
         * connected to the SSL structure and is automatically freed with
         * it. Do not free it again (core dump)!!
         * Only free the network_bio.
         */
        SSL_free(TLScontext->con);
        BIO_free(TLScontext->network_bio);

with the sequencing (SSL_free() or BIO_free() first) being of no importance...

Did I get this right?

Best regards,
        Lutz
PS. To be part of Postfix/TLS-0.6.10, to be released after straightening
out this issue.
-- 
Lutz Jaenicke                             [EMAIL PROTECTED]
BTU Cottbus               http://www.aet.TU-Cottbus.DE/personen/jaenicke/
Lehrstuhl Allgemeine Elektrotechnik                  Tel. +49 355 69-4129
Universitaetsplatz 3-4, D-03044 Cottbus              Fax. +49 355 69-4153
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
Development Mailing List                       [EMAIL PROTECTED]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to