Fixes for memory leaks

Created with free "DrMemory" tool