Fix memory leak and failure in test_kstate.
Also make test_kstate non-flaky.
Change-Id: Ie318042f04b26f08198645f5f0a75f9e6f1b84a4
Merge "Fix memory leak and failure in test_kstate. Also make test_kstate non-flaky. Change-Id: Ie318042f04b26f08198645f5f0a75f9e6f1b84a4"