(22878) Scope the call to CloseHandle

Without this patch the ensure block calls a private method (throwing an error). By continuing the scope used in the main block the correct method is called.