Fix keyfile bug with read() updating `location` incorrectly

I'm not sure how to test this change yet, but this patch works in practice for my use cases.