[Task] Fix a memory leak

This was introduced with the previous commit.