Various bugs and memory leaks

Fixed a missing DeleteCriticalSection
Fixed a leak when getting host names