Removed unnecessary c_str()
Added free() call for every malloc()