Made project build for all architectures (include arm64) and memory issues

Made project build for all architectures (include arm64)
Fixed some memory leaks that the clang analyzer pointed out