Fix a memory leak on converting weight vector to text