[Libevent-users] EVHTTP memory issue.

Matti Savolainen matti.savolainen at dynamoid.com
Tue May 20 01:26:23 EDT 2008


Hi,

I have been using evhttp for some time now for a project involving large 
POST datas. But now in production use I have noticed it leaking memory 
so I valgrinder it a bit. I am not sure if it is me using it wrong or if 
there is a bug somewhere there.
Basicly it uses more and more memory as it handles requests.
So here is the relevan valgrind outputs:

==14643== 4,096 bytes in 4 blocks are indirectly lost in loss record 7 of 13
==14643==    at 0x4A1B95B: realloc (vg_replace_malloc.c:306)
==14643==    by 0x4C56E84: evbuffer_expand (in 
/usr/local/lib/libevent-1.4.so.2.0.0)
==14643==    by 0x4C56F21: evbuffer_add (in 
/usr/local/lib/libevent-1.4.so.2.0.0)
==14643==    by 0x4C59B0E: evhttp_make_header (in 
/usr/local/lib/libevent-1.4.so.2.0.0)
==14643==    by 0x4C5A824: evhttp_request_dispatch (in 
/usr/local/lib/libevent-1.4.so.2.0.0)
==14643==    by 0x4C5ABB0: evhttp_connectioncb (in 
/usr/local/lib/libevent-1.4.so.2.0.0)
==14643==    by 0x4C54E5D: event_process_active (in 
/usr/local/lib/libevent-1.4.so.2.0.0)
==14643==    by 0x4C5518F: event_base_loop (in 
/usr/local/lib/libevent-1.4.so.2.0.0)
==14643==    by 0x4C54FF6: event_loop (in 
/usr/local/lib/libevent-1.4.so.2.0.0)
==14643==    by 0x4C54EA6: event_dispatch (in 
/usr/local/lib/libevent-1.4.so.2.0.0)
==14643==    by 0x405753: main (main.cpp:8)


==14643== 6,144 bytes in 18 blocks are indirectly lost in loss record 8 
of 13
==14643==    at 0x4A1B858: malloc (vg_replace_malloc.c:149)
==14643==    by 0x4A1B8D2: realloc (vg_replace_malloc.c:306)
==14643==    by 0x4C56E84: evbuffer_expand (in 
/usr/local/lib/libevent-1.4.so.2.0.0)
==14643==    by 0x4C5713F: evbuffer_read (in 
/usr/local/lib/libevent-1.4.so.2.0.0)
==14643==    by 0x4C5B964: evhttp_read_header (in 
/usr/local/lib/libevent-1.4.so.2.0.0)
==14643==    by 0x4C54E5D: event_process_active (in 
/usr/local/lib/libevent-1.4.so.2.0.0)
==14643==    by 0x4C5518F: event_base_loop (in 
/usr/local/lib/libevent-1.4.so.2.0.0)
==14643==    by 0x4C54FF6: event_loop (in 
/usr/local/lib/libevent-1.4.so.2.0.0)
==14643==    by 0x4C54EA6: event_dispatch (in 
/usr/local/lib/libevent-1.4.so.2.0.0)
==14643==    by 0x405753: main (main.cpp:8)

==14643== 67,108,864 bytes in 2 blocks are still reachable in loss 
record 13 of 13
==14643==    at 0x4A1B95B: realloc (vg_replace_malloc.c:306)
==14643==    by 0x4C56E84: evbuffer_expand (in 
/usr/local/lib/libevent-1.4.so.2.0.0)
==14643==    by 0x4C5713F: evbuffer_read (in 
/usr/local/lib/libevent-1.4.so.2.0.0)
==14643==    by 0x4C5A43D: evhttp_read (in 
/usr/local/lib/libevent-1.4.so.2.0.0)
==14643==    by 0x4C54E5D: event_process_active (in 
/usr/local/lib/libevent-1.4.so.2.0.0)
==14643==    by 0x4C5518F: event_base_loop (in 
/usr/local/lib/libevent-1.4.so.2.0.0)
==14643==    by 0x4C54FF6: event_loop (in 
/usr/local/lib/libevent-1.4.so.2.0.0)
==14643==    by 0x4C54EA6: event_dispatch (in 
/usr/local/lib/libevent-1.4.so.2.0.0)
==14643==    by 0x405753: main (main.cpp:8)

The way I use evhttp is basicly:
evhttp_start
evhttp_set_gencb
In the callback:
Copy the data for later use from EVBUFFER_DATA(request->input_buffer)
add headers to output_headers: Content-Length: 0, Connection: close, and 
a Location:
evhttp_send_reply with HTTP_MOVEPERM
evhttp_send_reply_end


--
Matti Savolainen








More information about the Libevent-users mailing list