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

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



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.