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

[Libevent-users] Memory leak with keepalive?



  Hello,
  
  Apparently, when using libevent 2 in order to serve HTTP requests,
the evhttp_connection instance isn't properly released if the
"Connection: closed" header is not send.

  Simple test-case:

#include <evhttp.h>
#include <string.h>

void http_dispatcher_cb(struct evhttp_request * const req,
                        void * const event_base)
{
    evhttp_send_reply(req, HTTP_OK, "OK", NULL);
    
    if (strcmp(evhttp_request_get_uri(req), "/shutdown") == 0) {    
        event_base_loopbreak(event_base);
    }
}

int main(void)
{
    struct event_base * const event_base = event_base_new();
    struct evhttp * const event_http = evhttp_new(event_base);
    evhttp_bind_socket(event_http, NULL, 8080);
    evhttp_set_gencb(event_http, http_dispatcher_cb, event_base);
    event_base_dispatch(event_base);
    evhttp_free(event_http);
    event_base_free(event_base);
    
    return 0;
}


  Running a couple of:
  
$ curl http://localhost:8080/blah

  before
  
$ curl http://localhost:8080/shutdown

  leads to Valgrind complaining:
  
4,008 (1,344 direct, 2,664 indirect) bytes in 8 blocks are
definitely lost in loss record 6 of 6
    at 0x4C267CC: calloc (vg_replace_malloc.c:467)
    by 0x4E505F8: evhttp_request_new (http.c:2794)
    by 0x4E512BB: evhttp_associate_new_request_with_connection (http.c:2979)
    by 0x4E520F2: evhttp_send_done (http.c:2024)
    by 0x4E45BE4: bufferevent_writecb (bufferevent_sock.c:290)
    by 0x4E3DC46: event_base_loop (event.c:1221)

  
  Is there anything wrong with the way I am using evhttp or is it a bug in
libevent?

  Tested with today's git tree.
  
  Best regards,

-- 
Frank Denis - j [at] pureftpd.org - http://00f.net - http://www.cotery.com
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.