Fixed minor memory leaks in error branches, identified by cppcheck.