Fixed some valgrind warnings due to raw pointers passing.