This change resolves following static analysis issues:
1. Using uint32_t and enumeration as operands to logical AND
operator (&&) is not allowed by the static analyzer tool.
Convert them to bool and use.
2. Overwriting the variable previous value before using it.
3. sizeof(key_alloc_buf[k]) returns 4/8 bytes as key_alloc_buf[k]
contains pointer. Use sizeof(*key_alloc_buf[k]) to get right
size of the object and use it to mem_zero the buffer.
Change-Id: I6faa5b3ff6847786a7f6ac525ccb0e5f60dbd020
CRs-Fixed: 3646512