Open YingHan-Chen opened 4 years ago
First of all, the HTTP request answering strings has 2 types.
For fixed length type, we can create a memory space with pre-defined maximum size. The memory space can be on the stack or heap. It should be pre-allocated and reused.
For unfixed length type, allocate the memory on the heap. If the memory is not enough, print the OOM error message. However, we would not be able to know the exact message from answering strings. Hence we should classify the HTTP request answering strings and print out the type of it.
After some code checking, the memory of HTTP request answering string should be allocated from the heap, no matter the length is fixed or not. The reason is we have to free the memory space at the last step. Free the memory space from the stack causes undefined behavior.
The new implementation would be quite simple.
Just log the error message out of memory
.
Currently, we allocate memory from the heap for the response pages, but it will fail when the system out of memory.
We could const char* string for the response pages. Reference example code https://www.gnu.org/software/libmicrohttpd/tutorial.html#Example-programs