Clean-up of finding the lowest lock instance

The code had a number of issues: it used slist_append, which is O(n),
making the list construction O(n**2). Finding the lowest lock was also
done in a rather non-elegant way.

Anyways, the whole list construction was needless anyway, because one
could just save the lowest lock instance integer while iterating over
the locks.

I'm not *entirely* sure of that patch, because I have no idea of the rest of
the code, and this just caught my attention as soon as I opened a random
source file in vim, but I'm sure there's a better solution than the existing
one along the lines of this patch.