libmicrohttpd
[Top][All Lists]
Advanced

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

Re: [libmicrohttpd] MHD_RESPMEM_PERSISTENT


From: Miguel Sancho
Subject: Re: [libmicrohttpd] MHD_RESPMEM_PERSISTENT
Date: Tue, 24 Jan 2017 17:22:43 +0100

Hi Silvio, thanks for answering,

> Could you show what error and how the buffer was assigned?

The error is that the downloaded binary file from the MHD server with the MHD_RESPMEM_PERSISTENT option is corrupt:
  • Same size as the original
  • The initial bytes are ok
  • but from a certain point file contents are set to '0'. The free(buffer) seems to impact the content downloaded in the http response, I do not how because free() is after the MHD_destroy_response()
  • Buffer is correctly downloaded when using the MHD_RESPMEM_MUST_COPY option but I wanted to minimize the memory impacts
The buffer is allocated by the MHD server with malloc, simplifying:
             unsigned char* buffer = (unsigned char*)malloc(dataSize);
             memcpy(buffer, data, dataSize);

Another thing I observe is that if I remove the free(buffer), the file is correctly downloaded. However this solution is not valid because in this case I have a memory leak:
            response = MHD_create_response_from_buffer(
                                 size,(void*)buffer,MHD_RESPMEM_PERSISTENT);
            ret = MHD_queue_response (connection, 200, response);       
            MHD_destroy_response (response);
            //free(buffer);   // Memory Leak!


Thanks

Miguel

reply via email to

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