Simplify and fix destroy_context()

Before this CL, destroy_context() walked the context table list twice:
once to find the context with the right handle, once to find the
previous handle. Not only it was inefficient, it also created cycles in
the list if somehow to contexts with duplicate handles were inserted
into the list.
This CL fixes it by finding the previous context by walking the list
only, and relying on the fact that if such previous context is found,
then previous->next is the one to kill.

BUG=b:111417778
TEST=boot, login on a device with tcsd; restart cryptohomed, verify that
     can logout & login after that.

Change-Id: I2fbda2ec39fce5fa9603cb89a30b254c95136590
Reviewed-on: https://chromium-review.googlesource.com/1155980
Commit-Ready: Andrey Pronin <apronin@chromium.org>
Tested-by: Andrey Pronin <apronin@chromium.org>
Reviewed-by: Maksim Ivanov <emaxx@chromium.org>
1 file changed