Fix several memory leaks