The MHD_create_response_from_callback() function takes an argument for a freeing function that should clean up the closure/context of the callback that produces the response, however, in the current code-flow this gets called early enough to trip up another thread that tries to write to the client. In the current implementation this freeing is omitted, resulting in a memory leak.