Fix memory leak, and remove useless copy