Added free's for allocated memory