Use std::string destructor to free temporary allocated string

TODO: const_cast<char *>() should be removed.