Save the locked handle in obtainWriteLock

Prevents the handle from going out of scope and the lock automatically being freed

cc @th3fallen @DeepDiver1975