Fixed nearly all memory leaks. Some leaks that occur by phtread and libwebsockets need more investigation