fix memory leaks with string append