Prevent state leak.
Remove redundant code.
Merge pull request #15537 from tgxworld/fix_state_leak

Fix state leak.