Hello,
I'm using libmicrohttpd10 on a Raspberry Pi using Raspbian, the server
running has a http daemon for a house automation daemon written in C.
I'm trying to get rid of all the memory leaks I can find, but it seems
that some are related to libmicrohttpd and I still can't find them.
I initialize libmicrohttpd with the flags MHD_USE_THREAD_PER_CONNECTION
and MHD_USE_SELECT_INTERNALLY on, then when a connection enters, I build
the response and fill the buffer with a char* allocated with malloc.
The response is created with the flag MHD_RESPMEM_MUST_FREE, so the
buffer is freed by libmicrohttpd if I undertand the documentation properly.
You can see my code there:
https://github.com/babelouest/angharad/blob/master/angharad.c
Line 45 is the MHD_start_daemon call, line 199 is the function called,
then lines 741 and 1006 are the functions used for POST requests.
There may probably be something wrong with my code but I don't see
where. I have my memory consumption growing up, no matter what I try to
free everything that is supposed to be dynamically allocated.
In my investigation, when I run the webapplication that calls all the
initial REST commands called DEVICES, OVERVIEW, ACTIONS, SCRIPTS and
SCHEDULES, most of the calls are simultaneous, the memory consumption
increases by 10 to 20Ko. But when I run each call individually, and
check the memory consumption after each call, I see no increase at all,
I think the problem may be in my use of libmicrohttpd. Do you have an
idea where ?
Also, I have another question about variables. I have 3 variables that
must be passed to the function ran by libmicrohttpd, but I couldn't find
a way to pass additional variables to this function, so I had to use
them as global variables. Is there a way to do that more efficiently ?
Thanks in advance for your help.
/Nicolas