[#2212] CID49417:

Added unlock before return from function acquiring a lock
[#2212] CID60655:

Avoid negative-indexing an array for hopefully obvious reasons.
[#2212] CID60654:

don't negative index into arrays