Fix valgrind error.
Correctly handle Task state.