Fixed a few memory free errors and other off by one error in string copy.

A few off by one errors were causing free() errors and were fixed.