[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [libmicrohttpd] Memory leak?
From: |
Christian Grothoff |
Subject: |
Re: [libmicrohttpd] Memory leak? |
Date: |
Sun, 31 Oct 2010 21:32:55 +0100 |
User-agent: |
KMail/1.13.2 (Linux/2.6.32-25-generic; KDE/4.4.2; i686; ; ) |
Hi Erik,
Based on your code, I can clearly see that the callback is called, but
obviously with the wrong address. However, the MHD code internally clearly
uses the right address, so the best explanation for the difference would be
some kind of memory corruption going on in between. Have you tried valgrind
on your code? Again, if you can produce a stand-alone *compiling* example
where the issue still arises, I'll be happy to take another look, but so far
this seems to be most likely a bug in the rest of your C++ code. The way you
use the API (from what I can see) seems to be fine.
Happy hacking!
Christian
On Sunday, October 31, 2010 12:00:20 pm Erik Slagter wrote:
> > Other than that, even after a look at the code I cannot explain what
> > you're experiencing (a testcase would be very welcome...).
>
> With r13472 (today) I am having the same issue. Here follow some code
> excerpts. Sorry for the lousy layout due to mail formatting.
>
> I hope this makes sense.
>
> /* start function */
>
> /* ... */
>
> daemon = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION | MHD_USE_IPv6
>
> | MHD_USE_DEBUG,
>
> tcp_port, 0, 0, &HttpServer::access_handler_callback, this,
> MHD_OPTION_NOTIFY_COMPLETED,
> &HttpServer::callback_request_completed, this,
> MHD_OPTION_END);
>
> /* ... */
>
> /* access handler callback */
>
> int HttpServer::access_handler_callback(void * void_http_server,
> struct MHD_Connection * connection,
> const char * url, const char * method,
> const char * version,
> const char * upload_data, size_t * upload_data_size,
> void ** con_cls)
> {
> HttpServer * http_server = (HttpServer *)void_http_server;
>
> if(*con_cls == 0)
> {
> ConnectionData * ncd = new(ConnectionData);
> ncd->callback_count = 0;
> ncd->postprocessor =
> MHD_create_post_processor(connection, 1024,
> callback_postdata_iterator, ncd);
> ncd->magic = ConnectionData::connection_data_magic;
> *con_cls = (void *)ncd;
> fprintf(stderr, "*** new ConnectionData, con_cls = %p,"
> "*con_cls = %p\n", con_cls, *con_cls);
> }
> else
> {
> (**(ConnectionData **)con_cls).callback_count++;
> fprintf(stderr, "*** update ConnectionData, con_cls ="
> " %p, *con_cls = %p, count = %d\n",
> con_cls, *con_cls,
> (**(ConnectionData **)con_cls).callback_count);
> }
>
> /* ... */
>
>
> /* request completed callback */
>
> void * HttpServer::callback_request_completed(void * cls,
> void ** con_cls, struct MHD_Connection *,
> enum MHD_RequestTerminationCode)
> {
> fprintf(stderr, "*** callback_request_completed\n");
> fprintf(stderr, "*** cls = %p, con_cls = %p, *con_cls = %p\n",
> cls, con_cls, con_cls ? *con_cls : con_cls);
>
> if(con_cls && *con_cls)
> {
> ConnectionData * cdp = (ConnectionData *)*con_cls;
>
> if(cdp->magic == ConnectionData::connection_data_magic)
> {
> if(cdp->postprocessor)
> {
> MHD_destroy_post_processor
> (cdp->postprocessor);
> cdp->postprocessor = 0;
> }
>
> fprintf(stderr, "*** delete ConnectionData\n");
> delete(cdp);
> }
> else
> vlog("HttpServer::callback_request_compled: invalid
> magic number
in
> ConnectionData\n");
>
> *con_cls = 0;
> }
>
> return(0);
> }
>
> /* output */
>
> *** new ConnectionData, con_cls = 0x7f0eac0008e8, *con_cls = 0x7f0ea4008900
> *** update ConnectionData, con_cls = 0x7f0eac0008e8, *con_cls =
> 0x7f0ea4008900, count = 1
> *** update ConnectionData, con_cls = 0x7f0eac0008e8, *con_cls =
> 0x7f0ea4008900, count = 2
> *** callback_request_completed
> *** cls = 0x136fc00, con_cls = 0x7f0eac0008c0, *con_cls = (nil)
> *** new ConnectionData, con_cls = 0x7f0eac0008e8, *con_cls = 0x7f0ea4008f40
> *** update ConnectionData, con_cls = 0x7f0eac0008e8, *con_cls =
> 0x7f0ea4008f40, count = 1
> *** update ConnectionData, con_cls = 0x7f0eac0008e8, *con_cls =
> 0x7f0ea4008f40, count = 2
> *** callback_request_completed
> *** cls = 0x136fc00, con_cls = 0x7f0eac0008c0, *con_cls = (nil)