[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [Libevent-users] Memory won't be freed in SSL connection.



Thanks for your reply.

My sample code is like as yours.
I have try some release functions are mentioned in Openssl faq (http://www.openssl.org/support/faq.html#PROG13) , but nothing improve.

The memory usage is different between 'summary of valgrind' and 'top'.
And I cannot locate the 'lost' memory even use the valgrind. (Neither belong leak nor reachable)

After analysis by tcmalloc, they are in the 'heap freelist', that is to say the memoy already be freed but didn't retrun to OS.

I think it is caused by stormy test, I use ab to test ssl server with 10k connections per second. There are a lot of memory fragment remain in the freelist.

The tcmalloc library provide a function to release these memory forcedly or raise the free frequency.
Ref: http://google-perftools.googlecode.com/svn/trunk/doc/tcmalloc.html


Brian


2011/3/8 Nick Mathewson <nickm@xxxxxxxxxxxxx>
2011/2/21 林宇舜 Yu-Shun Lin <ys.ncku@xxxxxxxxx>:
> Hi all,
>
> I construct SSL connection by using
>   bev1 = bufferevent_socket_new(... fd ..., BEV_OPT_CLOSE_ON_FREE)
>   bev2 = bufferevent_openssl_filter_new(... bev ..., BEV_OPT_CLOSE_ON_FREE)
>   bufferevent_setcb(bev2, read_cb, ..., event_cb...)
> And close connection by bufferevent_free(bev) in event callback.
>
> But the memory seems only increased, don't be released.
> These memory is reachable, because I terminate the program gracefully by
> using event_base_loopexit() and event_base_free(), the memory can be
> released.
>
> Does bufferevent over SSL has any catch mechanism?
> How to release them or limit the maximun size?
> Or I miss some destruct functions?
>

What you're describing is supposed to work.  I just gave it a shot
with a minimal example, and it seems to work for me (looking for
reachable memory with valgrind).  If you could write a quick example
that demonstrates the problem you're seeing, I'd be glad to check it
out.



Here's the code that I used to test out your question:
#include <assert.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/socket.h>

#include <openssl/ssl.h>
#include <openssl/rand.h>
#include <openssl/err.h>
#include <openssl/evp.h>
#include <openssl/conf.h>
#include <event2/event.h>
#include <event2/bufferevent.h>
#include <event2/bufferevent_ssl.h>

int main(int c, char **v)
{
 SSL *ssl;
 SSL_CTX *ctx;
 struct event_base *base;
 struct bufferevent *bev1, *bev2;
 int fd[2];
 SSL_load_error_strings();
 SSL_library_init();
 RAND_poll();
 ctx = SSL_CTX_new(TLSv1_method());
 assert(ctx);
 ssl = SSL_new(ctx);
 assert(ssl);
 base = event_base_new();
 assert(base);
 socketpair(AF_UNIX, SOCK_STREAM, 0, fd);
 bev1 = bufferevent_socket_new(base, fd[0], BEV_OPT_CLOSE_ON_FREE);
 assert(bev1);
 bev2 = bufferevent_openssl_filter_new(base, bev1, ssl,
                                       BUFFEREVENT_SSL_CONNECTING,
                                       BEV_OPT_CLOSE_ON_FREE);

 bufferevent_free(bev2);
 event_base_free(base);
 SSL_CTX_free(ctx);

 /* Make most library-scoped openssl things get freed so they don't
confuse valgrind */
 EVP_cleanup();
 ERR_remove_state(0);
 ERR_free_strings();
 CONF_modules_unload(1);
 CRYPTO_cleanup_all_ex_data();


 return 0;
}
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.