Adding releaseLock(handle) for error handling and cleanup