// Compile with: gcc -o microhttpd-bug -fsanitize=address -Ideps/libmicrohttpd/src/include microhttpd-bug.c deps/libmicrohttpd/src/microhttpd/.libs/libmicrohttpd.a #include #include #include #include #define PORT 5050 #define INACTIVITY_TIMEOUT 15 #include static enum MHD_Result handle_request(void* cls, struct MHD_Connection* connection, const char* url, const char* method, const char* version, const char* upload_data, size_t* upload_data_size, void** ptr) { return MHD_NO; } static void request_completed(void* cls, struct MHD_Connection* connection, void** ptr, enum MHD_RequestTerminationCode toe) { *ptr = NULL; } int main(int argc, char* argv[]) { struct sockaddr_in addr; socklen_t addrlen; memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); addr.sin_port = htons(PORT); struct MHD_Daemon* d = MHD_start_daemon( MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_EPOLL | MHD_USE_ERROR_LOG, PORT, NULL, NULL, &handle_request, NULL, MHD_OPTION_SOCK_ADDR, &addr, MHD_OPTION_CONNECTION_TIMEOUT, INACTIVITY_TIMEOUT, MHD_OPTION_NOTIFY_COMPLETED, &request_completed, MHD_OPTION_END ); if (d == NULL) return 1; (void)getc(stdin); MHD_stop_daemon(d); return 0; }