fix handle leak and invalid std::string usage