Add null pointer validation caught by valgrind.