Fixed memory leaks

Fixed 4 memory leaks and 1 crash.