On Wed, Nov 17, 2010 at 9:26 PM, Ken Feng <kfmf...@gmail.com> wrote: > Hi, > > I am a new user of libevent - I ran into the following valgrind error > on my machine: > > Version: libevent-2.0.8-rc > OS: Ubuntu 10.04 LTS amd64 > > Of interest is (bufferevent_sock.c:321) inside: > struct bufferevent *bufferevent_socket_new() > > struct bufferevent_private *bufev_p; > // ... > if ((bufev_p = mm_calloc(1, sizeof(struct bufferevent_private)))== NULL) > // ... > // ---------------------------------------- > > bufev_p doesn't seem to get freed with mm_free() unless there is an error.
Right, because bufev_p is the thing that is actually returned by the bufferevent_socket_new() function. The function allocates a struct bufferevent_private, with an internal struct bufferevent, and on success returns to the user a pointer to the struct bufferevent. Later, when you call bufferevent_free, it upcasts the bufferevent to get the pointer to the actual allocated thing, and frees that: /* Free the actual allocated memory. */ mm_free(((char*)bufev) - bufev->be_ops->mem_offset); Probably, you aren't actually calling bufferevent_free on the bufferevent here. -- Nick *********************************************************************** To unsubscribe, send an e-mail to majord...@freehaven.net with unsubscribe libevent-users in the body.