----- Original Message -----
From: "Dr S N Henson" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, March 14, 2002 5:39 PM
Subject: Re: Memory Leak
> James Yonan wrote:
> >
> > I have an application which creates and destroys many SSL objects using
> > SSL_new and SSL_free. The SSL objects are bound to memory BIOs rather
> > than sockets. Here is a brief annotation of the relevent sections of
code
> > (with error checks removed):
> >
> > ks->ssl = SSL_new (ssl_ctx);
> >
> > ks->ssl_bio = BIO_new (BIO_f_ssl());
> > ks->ciphertext_in = BIO_new (BIO_s_mem ());
> > ks->ciphertext_out = BIO_new (BIO_s_mem ());
> >
> > if (server)
> > SSL_set_accept_state (ks->ssl);
> > else
> > SSL_set_connect_state (ks->ssl);
> >
> > SSL_set_bio (ks->ssl, ks->ciphertext_in, ks->ciphertext_out);
> > BIO_set_ssl (ks->ssl_bio, ks->ssl, BIO_NOCLOSE);
> >
> > /* DO SOMETHING */
> >
> > SSL_free (ks->ssl);
> >
> > The problem is that each of these iterations causes OpenSSL to leak 10K
or
> > more. At first I thought that maybe the BIOs returned by BIO_new need
to
> > be explicitly freed, but then I saw that OpenSSL is freeing them on the
> > SSL_free call.
> >
> > 98212 file=buffer.c, line=67, number=12, address=0815D738
> > 71750 file=bio_ssl.c, line=108, number=24, address=081B3AB8
> > 32120 file=buffer.c, line=110, number=1868, address=08199A50
> > 72332 file=bio_lib.c, line=73, number=64, address=08170740
> > 701884 bytes leaked in 1960 chunks
> >
> > After many iterations, the amount of memory leaked is substantial. All
of
> > the leaks are occurring at one of these 4 locations (above) in the code
> > (openssl-0.9.6c) which I obtained by building OpenSSL with CRYPTO_MDEBUG
> > defined.
> >
>
> If you are just iterating that code then you aren't freeing those BIOs
> you created.
This code from SSL_free appears to free the BIOs which are associated with
the SSL object through a call to SSL_set_bio. SSL_set_bio sets the wbio and
rbio members of the SSL structure then SSL_free tries to free them. In
fact, if I try to explicitly free those BIOs, the program crashes.
****************
if (s->bbio != NULL)
{
/* If the buffering BIO is in place, pop it off */
if (s->bbio == s->wbio)
{
s->wbio=BIO_pop(s->wbio);
}
BIO_free(s->bbio);
s->bbio=NULL;
}
if (s->rbio != NULL)
BIO_free_all(s->rbio);
if ((s->wbio != NULL) && (s->wbio != s->rbio))
BIO_free_all(s->wbio);
*****************
James Yonan
______________________________________________________________________
OpenSSL Project http://www.openssl.org
Development Mailing List [EMAIL PROTECTED]
Automated List Manager [EMAIL PROTECTED]