Discussion:
Libevent memory leak?
Andrei Chirila
2011-07-11 08:35:46 UTC
Permalink
Hello,

I'm using libevent in some programs and I came across a memory leak in
libevent. I'm wondering if I'm the one doing something wrong or it's really
something in libevent.

Valgrind reports:

***@virtual-machine:~/src/tests$ valgrind --leak-check=full
--show-reachable=yes ./test_event.exe
==18888== Memcheck, a memory error detector
==18888== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==18888== Using Valgrind-3.6.0.SVN-Debian and LibVEX; rerun with -h for
copyright info
==18888== Command: ./test_event.exe
==18888==
==18888==
==18888== HEAP SUMMARY:
==18888== in use at exit: 80 bytes in 2 blocks
==18888== total heap usage: 40 allocs, 38 frees, 4,350 bytes allocated
==18888==
==18888== 40 bytes in 1 blocks are still reachable in loss record 1 of 2
==18888== at 0x4C2815C: malloc (vg_replace_malloc.c:236)
==18888== by 0x4D1759: evthread_posix_lock_alloc (evthread_pthread.c:48)
==18888== by 0x4C8341: evsig_init (signal.c:174)
==18888== by 0x4C7AD2: epoll_init (epoll.c:142)
==18888== by 0x4B9184: event_base_new_with_config (event.c:601)
==18888== by 0x4B92A4: event_base_new (event.c:439)
==18888== by 0x404181: main (test_event.c:11)
==18888==
==18888== 40 bytes in 1 blocks are still reachable in loss record 2 of 2
==18888== at 0x4C2815C: malloc (vg_replace_malloc.c:236)
==18888== by 0x4D1759: evthread_posix_lock_alloc (evthread_pthread.c:48)
==18888== by 0x4D1361: evutil_secure_rng_init (evutil_rand.c:102)
==18888== by 0x4D09EE: evdns_base_new (evdns.c:3756)
==18888== by 0x404196: main (test_event.c:12)
==18888==
==18888== LEAK SUMMARY:
==18888== definitely lost: 0 bytes in 0 blocks
==18888== indirectly lost: 0 bytes in 0 blocks
==18888== possibly lost: 0 bytes in 0 blocks
==18888== still reachable: 80 bytes in 2 blocks
==18888== suppressed: 0 bytes in 0 blocks
==18888==
==18888== For counts of detected and suppressed errors, rerun with: -v
==18888== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 4 from 4)

Test program:

#include <stdlib.h>
#include <event2/event.h>
#include <event2/dns.h>

int main() {
if(evthread_use_pthreads() < 0) {
fprintf(stderr, "Could not enable pthreads support in libevent\n");
exit(1);
}

struct event_base *ebp = event_base_new();
struct evdns_base *dns = evdns_base_new(ebp, 1);
evdns_base_free(dns, 1);
event_base_free(ebp);
return 0;
}

Thank you,
Andrei Chirila
--
Mobile: +49 151 42647382
e-Mail: ***@gmail.com
Mark Ellzey
2011-07-11 15:55:16 UTC
Permalink
Post by Andrei Chirila
Hello,
I'm using libevent in some programs and I came across a memory leak in
libevent. I'm wondering if I'm the one doing something wrong or it's really
something in libevent.
What version are you using? I just browsed through the code and the
symbols don't match newest ver line wise.
***********************************************************************
To unsubscribe, send an e-mail to ***@freehaven.net with
unsubscribe libevent-users in the body.
Andrei Chirila
2011-07-11 16:01:41 UTC
Permalink
Hello,

Thank you for your interest.

$ git describe
release-2.0.12-stable-125-g3312403

Andrei
Post by Andrei Chirila
Post by Andrei Chirila
Hello,
I'm using libevent in some programs and I came across a memory leak in
libevent. I'm wondering if I'm the one doing something wrong or it's
really
Post by Andrei Chirila
something in libevent.
What version are you using? I just browsed through the code and the
symbols don't match newest ver line wise.
***********************************************************************
unsubscribe libevent-users in the body.
--
Mobile: +49 151 42647382
e-Mail: ***@gmail.com
Andrei Chirila
2011-07-11 16:06:22 UTC
Permalink
Hello,

I just tried with the latest:

$ git describe
release-2.0.12-stable-162-g7d08a28

Valgrind still reports memory leaks:

$ valgrind --leak-check=full --show-reachable=yes ./test_event.exe
==2705== Memcheck, a memory error detector
==2705== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==2705== Using Valgrind-3.6.0.SVN-Debian and LibVEX; rerun with -h for
copyright info
==2705== Command: ./test_event.exe
==2705==
==2705==
==2705== HEAP SUMMARY:
==2705== in use at exit: 120 bytes in 3 blocks
==2705== total heap usage: 41 allocs, 38 frees, 4,390 bytes allocated
==2705==
==2705== 40 bytes in 1 blocks are still reachable in loss record 1 of 3
==2705== at 0x4C2815C: malloc (vg_replace_malloc.c:236)
==2705== by 0x4D1B99: evthread_posix_lock_alloc (evthread_pthread.c:48)
==2705== by 0x4B5092: event_global_setup_locks_ (event.c:2830)
==2705== by 0x4D198C: evthread_use_pthreads (evthread_pthread.c:187)
==2705== by 0x404145: main (test_event.c:6)
==2705==
==2705== 40 bytes in 1 blocks are still reachable in loss record 2 of 3
==2705== at 0x4C2815C: malloc (vg_replace_malloc.c:236)
==2705== by 0x4D1B99: evthread_posix_lock_alloc (evthread_pthread.c:48)
==2705== by 0x4C8CF3: evsig_global_setup_locks_ (signal.c:440)
==2705== by 0x4B50A5: event_global_setup_locks_ (event.c:2832)
==2705== by 0x4D198C: evthread_use_pthreads (evthread_pthread.c:187)
==2705== by 0x404145: main (test_event.c:6)
==2705==
==2705== 40 bytes in 1 blocks are still reachable in loss record 3 of 3
==2705== at 0x4C2815C: malloc (vg_replace_malloc.c:236)
==2705== by 0x4D1B99: evthread_posix_lock_alloc (evthread_pthread.c:48)
==2705== by 0x4C7423: evutil_secure_rng_global_setup_locks_
(evutil_rand.c:106)
==2705== by 0x4B50D6: event_global_setup_locks_ (event.c:2834)
==2705== by 0x4D198C: evthread_use_pthreads (evthread_pthread.c:187)
==2705== by 0x404145: main (test_event.c:6)
==2705==
==2705== LEAK SUMMARY:
==2705== definitely lost: 0 bytes in 0 blocks
==2705== indirectly lost: 0 bytes in 0 blocks
==2705== possibly lost: 0 bytes in 0 blocks
==2705== still reachable: 120 bytes in 3 blocks
==2705== suppressed: 0 bytes in 0 blocks
==2705==
==2705== For counts of detected and suppressed errors, rerun with: -v
==2705== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 4 from 4)


Thank you,
Andrei Chirila
Post by Andrei Chirila
Hello,
Thank you for your interest.
$ git describe
release-2.0.12-stable-125-g3312403
Andrei
Post by Andrei Chirila
Post by Andrei Chirila
Hello,
I'm using libevent in some programs and I came across a memory leak in
libevent. I'm wondering if I'm the one doing something wrong or it's
really
Post by Andrei Chirila
something in libevent.
What version are you using? I just browsed through the code and the
symbols don't match newest ver line wise.
***********************************************************************
unsubscribe libevent-users in the body.
--
Mobile: +49 151 42647382
--
Mobile: +49 151 42647382
e-Mail: ***@gmail.com
Mark Ellzey
2011-07-11 16:20:29 UTC
Permalink
Ah, this is a global lock.

Unfortunately there doesn't seem to be a way to free that, is it a big
issue? this is small, one time allocat, and handled by dtor's.

***********************************************************************
To unsubscribe, send an e-mail to ***@freehaven.net with
unsubscribe libevent-users in the body.
Andrei Chirila
2011-07-11 16:26:14 UTC
Permalink
It's no big issue, I was just wondering if this was in my usage or it's
generic libevent.

I have some programs which get tested under valgrind, and valgrind complains
about libevent, so maybe a global event_library_cleanup() would be enough. I
don't have enough knowledge of the internals, but if anyone would be
interested in reviewing such piece of code, I think I can get it done. I
suppose it's just adding free functions for any module (evsig, secure_rng)
and calling them from the global free.

Andrei
Post by Mark Ellzey
Ah, this is a global lock.
Unfortunately there doesn't seem to be a way to free that, is it a big
issue? this is small, one time allocat, and handled by dtor's.
***********************************************************************
unsubscribe libevent-users in the body.
--
Mobile: +49 151 42647382
e-Mail: ***@gmail.com
Mark Ellzey
2011-07-11 16:26:28 UTC
Permalink
Post by Andrei Chirila
Hello,
Try compiling with --disable-debug-mode
***********************************************************************
To unsubscribe, send an e-mail to ***@freehaven.net with
unsubscribe libevent-users in the body.
Mark Ellzey
2011-07-11 16:30:58 UTC
Permalink
int
event_global_setup_locks_(const int enable_locks)
{
#ifndef _EVENT_DISABLE_DEBUG_MODE
EVTHREAD_SETUP_GLOBAL_LOCK(_event_debug_map_lock, 0);
#endif

is your issue. so yeah, --disable-debug-mode will fix that problem.
Post by Mark Ellzey
Post by Andrei Chirila
Hello,
Try compiling with --disable-debug-mode
***********************************************************************
unsubscribe libevent-users in the body.
***********************************************************************
To unsubscribe, send an e-mail to ***@freehaven.net with
unsubscribe libevent-users in the body.
Andrei Chirila
2011-07-11 16:48:23 UTC
Permalink
Hi Mark,

I tried the following:

./configure --disable-debug-mode
make clean all
copy my libs to the right places and compile test_event.c

This is the result:

$ valgrind --leak-check=full --show-reachable=yes ./test_event.exe
==28671== Memcheck, a memory error detector
==28671== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==28671== Using Valgrind-3.6.0.SVN-Debian and LibVEX; rerun with -h for
copyright info
==28671== Command: ./test_event.exe
==28671==
==28671==
==28671== HEAP SUMMARY:
==28671== in use at exit: 80 bytes in 2 blocks
==28671== total heap usage: 40 allocs, 38 frees, 4,350 bytes allocated
==28671==
==28671== 40 bytes in 1 blocks are still reachable in loss record 1 of 2
==28671== at 0x4C2815C: malloc (vg_replace_malloc.c:236)
==28671== by 0x4D1309: evthread_posix_lock_alloc (evthread_pthread.c:48)
==28671== by 0x4C8463: evsig_global_setup_locks_ (signal.c:440)
==28671== by 0x4B50F7: event_global_setup_locks_ (event.c:2832)
==28671== by 0x4D10FC: evthread_use_pthreads (evthread_pthread.c:187)
==28671== by 0x404145: main (test_event.c:6)
==28671==
==28671== 40 bytes in 1 blocks are still reachable in loss record 2 of 2
==28671== at 0x4C2815C: malloc (vg_replace_malloc.c:236)
==28671== by 0x4D1309: evthread_posix_lock_alloc (evthread_pthread.c:48)
==28671== by 0x4C6B93: evutil_secure_rng_global_setup_locks_
(evutil_rand.c:106)
==28671== by 0x4B510E: event_global_setup_locks_ (event.c:2834)
==28671== by 0x4D10FC: evthread_use_pthreads (evthread_pthread.c:187)
==28671== by 0x404145: main (test_event.c:6)
==28671==
==28671== LEAK SUMMARY:
==28671== definitely lost: 0 bytes in 0 blocks
==28671== indirectly lost: 0 bytes in 0 blocks
==28671== possibly lost: 0 bytes in 0 blocks
==28671== still reachable: 80 bytes in 2 blocks
==28671== suppressed: 0 bytes in 0 blocks
==28671==
==28671== For counts of detected and suppressed errors, rerun with: -v
==28671== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 4 from 4)


As far as I can see, if I disable debug mode, only this line:
2830 EVTHREAD_SETUP_GLOBAL_LOCK(_event_debug_map_lock, 0);
is ignored.

To completely get rid of leaks, I would have to disable thread support
(which in my programs I use).

Maybe I'm missing something? It's
./configure --disable-debug-mode
enough to disable debug, or there are more flags which I missed?

Thank you,
Andrei
Post by Mark Ellzey
int
event_global_setup_locks_(const int enable_locks)
{
#ifndef _EVENT_DISABLE_DEBUG_MODE
EVTHREAD_SETUP_GLOBAL_LOCK(_event_debug_map_lock, 0);
#endif
is your issue. so yeah, --disable-debug-mode will fix that problem.
Post by Mark Ellzey
Post by Andrei Chirila
Hello,
Try compiling with --disable-debug-mode
***********************************************************************
unsubscribe libevent-users in the body.
***********************************************************************
unsubscribe libevent-users in the body.
--
Mobile: +49 151 42647382
e-Mail: ***@gmail.com
Mark Ellzey
2011-07-11 17:33:04 UTC
Permalink
Yeah I see it now - not a huge issue but I will submit a patch here
soon.

***********************************************************************
To unsubscribe, send an e-mail to ***@freehaven.net with
unsubscribe libevent-users in the body.
Andrei Chirila
2011-07-11 18:10:02 UTC
Permalink
Hi Mark,

Thank you for your interest in this issue.

Best regards,
Andrei
Post by Mark Ellzey
Yeah I see it now - not a huge issue but I will submit a patch here
soon.
***********************************************************************
unsubscribe libevent-users in the body.
--
Mobile: +49 151 42647382
e-Mail: ***@gmail.com
Mark Ellzey
2011-07-11 18:40:06 UTC
Permalink
Nick,

Are the github repo's out of sync? I can't seem to find the most recent
branch, libevent/master libevent/patches-2.0, nmathewson/* all seem to
be out of sync.

In any case, patch for the global locks issue attached.
Post by Andrei Chirila
Hi Mark,
Thank you for your interest in this issue.
Best regards,
Andrei
Post by Mark Ellzey
Yeah I see it now - not a huge issue but I will submit a patch here
soon.
***********************************************************************
unsubscribe libevent-users in the body.
--
Mobile: +49 151 42647382
Nick Mathewson
2011-07-12 04:20:16 UTC
Permalink
Post by Mark Ellzey
Nick,
Are the github repo's out of sync? I can't seem to find the most recent
branch, libevent/master libevent/patches-2.0, nmathewson/* all seem to
be out of sync.
Yeah. The canonical location for master/patches-2.0 is still
sourceforge. Any other mirror of it may lag behind for a while.
Post by Mark Ellzey
In any case, patch for the global locks issue attached.
Looks like a good start; see the comments on your pull request.

cheers,
--
Nick
***********************************************************************
To unsubscribe, send an e-mail to ***@freehaven.net with
unsubscribe libevent-users in the body.
Mark Ellzey
2011-07-12 16:39:25 UTC
Permalink
Post by Nick Mathewson
Looks like a good start; see the comments on your pull request.
Updated per request.


***********************************************************************
To unsubscribe, send an e-mail to ***@freehaven.net with
unsubscribe libevent-users in the body.

Mark Ellzey
2011-07-11 16:05:46 UTC
Permalink
Post by Andrei Chirila
Hello,
I'm using libevent in some programs and I came across a memory leak in
libevent. I'm wondering if I'm the one doing something wrong or it's really
something in libevent.
Ah, this seems to be fixed recently, I don't see it in the latest
release, but *is* fixed in develop.
***********************************************************************
To unsubscribe, send an e-mail to ***@freehaven.net with
unsubscribe libevent-users in the body.
Loading...