libmicrohttpd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [libmicrohttpd] Freeing data added to MHD_create_response_from_buffe


From: Gavin Henry
Subject: Re: [libmicrohttpd] Freeing data added to MHD_create_response_from_buffer
Date: Mon, 17 Jan 2022 20:22:53 +0000

>  > If I understand your code, you use MHD_create_response_from_buffer
> with the MHD_RESPMEM_PERSISTENT mode, which, according to the
> documentation [1], means that 'reply' should be static/global, which isn't.
>
> You can either:
> - use MHD_RESPMEM_MUST_FREE and let MHD free 'reply' after use using
> free (if free suits your case)
> - use MHD_RESPMEM_MUST_COPY, then free 'reply' after with your own free
> function
> - or use MHD_create_response_from_buffer_with_free_callback and pass
> your free callback function pointer:
> MHD_create_response_from_buffer_with_free_callback(strlen(reply_data),
> (void *)reply_data, &free)
>
> If you use libc free, I suggest the first case, but if you can use a
> different malloc/free function family, then you will need
> MHD_create_response_from_buffer_with_free_callback. The second option
> can be avoided in your case, since it will duplicate 'reply' content in
> the heap.

Thanks Nicolas! It was right in front of my eyes. I didn't even this
to read about the "mode". I was thinking that was like the daemon
start up as per all the discussions of "mode" at:



-- 
Kind Regards,

Gavin Henry.
https://sentrypeer.org



reply via email to

[Prev in Thread] Current Thread [Next in Thread]