After some investigation I've figured out that the memory leak isn't caused
by running Openssl in threads. However, after about 200 connections, may
vary, the used memory increases with around 70 kb. Is this normal? I guessed
it's allocated by the openssl library

2009/5/6 Fabian Bergmark <fabian.bergm...@gmail.com>

> Okey. Now i got no more memory leaks when I put the SSL code in main.
> However, if i try to put the exact same code in a thread the memory leak is
> back.
>
> Here is the essential code I'm using;
>
> void lcserver::start()
> {
> SSL_library_init();
> SSL_load_error_strings();
> method = SSLv23_server_method();
> ctx = SSL_CTX_new(method);
>
> Some windows socket code...
>
> while(acceptsocket = accept(listensocket,(sockaddr*)&sin,&len))
> {
> struct clientinfo *client;
> client = new struct
> clientinfo(acceptsocket,sin.sin_addr.s_addr,clientid++,this,rooms[0]->getthis(),ctx);
> client->M1();
> }
> }
>
> void clientinfo::M1()
> {
> CreateThread(0,0,(LPTHREAD_START_ROUTINE)M2,(LPVOID)this,0,0);
> }
>
> void clientinfo::M2(LPVOID param)
> {
>     clientinfo* Call = (clientinfo*)param;
>     Call->listenfor();
>     delete Call;
>     return;
> }
>
> void clientinfo::listenfor()
> {
> SSL_set_bio(ssl,bio,bio);
> SSL_accept(ssl);
> while(SSL_shutdown(ssl) == 0)
> ;
> SSL_free(ssl);
> ERR_remove_state(0);
> }
>
> Just running this code which shouldn't leave any allocated memory, about 12
> kb ram is still allocated.
>
>
> 2009/5/5 Nikos Balkanas <nbalka...@gmail.com>
>
>  Hi,
>>
>> Check the return value of SSL_shutdown(ssl). Sometimes it needs up to 4
>> iterations to complete due to internal state machine. It completes when
>> the value != 0. Hope it helps.
>>
>> BR,
>> Nikos
>>
>> ----- Original Message -----
>>  *From:* Fabian Bergmark <fabian.bergm...@gmail.com>
>> *To:* openssl-users@openssl.org
>> *Sent:* Tuesday, May 05, 2009 9:13 PM
>> *Subject:* Openssl Memory leak
>>
>> Hi
>>
>> I am currently writing a Chat application using the Openssl library for
>> encryption. It's a multi-thread application and every client is managed by a
>> different thread.
>> However, ever since I implemented Openssl there seams to be a memory leak
>> of around 10 kb.
>> My openssl-code code is looking like following:
>>
>> SSL_set_bio(ssl,bio,bio);
>> SSL_accept(ssl);
>> SSL_shutdown(ssl);
>> SSL_free(ssl);
>>
>> where bio and ssl is class objects where BIO is set like
>>
>> bio = BIO_new_socket(s,BIO_NOCLOSE)
>>
>> The increased memory does not occur before SSL_accept(ssl). The first time
>> a client connect about a 100 kb is allocated, which I suppose is due to some
>> initialising function. For each new client about 0-20 kb are still allocated
>> after
>>
>> SSL_shutdown(ssl);
>> SSL_free(ssl);
>>
>> is issued. Is there some cleanup functions im forgetting?
>>
>> I am using windows btw.
>>
>>
>

Reply via email to