fix memory leak and support utf8 charset

fix memory leak and support utf8 charset