Corrected valgrind errors due to a misuse of resize