Valgrind Invalid write of size 1 fix?