[cppcheck] Fix memory leak.
[cppcheck] Fix out of bounds writes.