Add missing calls to free() when the code goes down failure paths.

This was found using cppcheck.