Fix valgrind InvalidRead error