Fix memory leak in chat