[scheduling] Fix use-after-free bug in task pinning implementation.