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

Re: [Libevent-users] leak in be_pair_flush



Can put this up as a pull request on github to review and accept
On Thu, Jul 23, 2015 at 6:56 PM Bill Vaughan <billvaughan@xxxxxxxxx> wrote:
Hi all,

I added bufferevent pairs to my project a few weeks ago as it was perfect for what I needed. Got it all working nicely but valgrind was reporting a leak. I finally tracked down the culprit to the bufferevent pair flush code.

Here is the patch for libevent 2.0.22. The lock was being taken and not released if the mode was BEV_NORMAL.

[bvaughan@dev-client tproxy]$ git diff
diff --git a/libevent-2.0.22-stable/bufferevent_pair.c b/libevent-2.0.22-stable/bufferevent_pair.c
index e9ed9f5..2a77dc7 100644
--- a/libevent-2.0.22-stable/bufferevent_pair.c
+++ b/libevent-2.0.22-stable/bufferevent_pair.c
@@ -284,14 +284,15 @@ be_pair_flush(struct bufferevent *bev, short iotype,
Â{
    struct bufferevent_pair *bev_p = upcast(bev);
    struct bufferevent *partner;
- Â Â Â incref_and_lock(bev);
+
    if (!bev_p->partner)
        return -1;
Â
- Â Â Â partner = downcast(bev_p->partner);
+ Â if (mode == BEV_NORMAL)
+ Â Â Âreturn 0;
Â
- Â Â Â if (mode == BEV_NORMAL)
- Â Â Â Â Â Â Â return 0;
+ Â Â Â incref_and_lock(bev);
+ Â partner = downcast(bev_p->partner);
Â
    if ((iotype & EV_READ) != 0)
        be_pair_transfer(partner, bev, 1);


Thanks,
-Bill