Support/Windows: Add ScopedHandle and move some clients over to it.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120987 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Support/Windows/PathV2.inc b/lib/Support/Windows/PathV2.inc
index f6f5371..6bd541e 100644
--- a/lib/Support/Windows/PathV2.inc
+++ b/lib/Support/Windows/PathV2.inc
@@ -113,15 +113,14 @@
return success;
}
- struct AutoCryptoProvider {
- HCRYPTPROV CryptoProvider;
+ // Forwarder for ScopedHandle.
+ BOOL WINAPI CryptReleaseContext(HCRYPTPROV Provider) {
+ return ::CryptReleaseContext(Provider, 0);
+ }
- ~AutoCryptoProvider() {
- ::CryptReleaseContext(CryptoProvider, 0);
- }
-
- operator HCRYPTPROV() const {return CryptoProvider;}
- };
+ typedef ScopedHandle<HCRYPTPROV, HCRYPTPROV(INVALID_HANDLE_VALUE),
+ BOOL (WINAPI*)(HCRYPTPROV), CryptReleaseContext>
+ ScopedCryptContext;
}
namespace llvm {
@@ -503,13 +502,14 @@
SmallVector<wchar_t, 128> random_path_utf16;
// Get a Crypto Provider for CryptGenRandom.
- AutoCryptoProvider CryptoProvider;
- if (!::CryptAcquireContextW(&CryptoProvider.CryptoProvider,
+ HCRYPTPROV HCPC;
+ if (!::CryptAcquireContextW(&HCPC,
NULL,
NULL,
PROV_RSA_FULL,
0))
return windows_error(::GetLastError());
+ ScopedCryptContext CryptoProvider(HCPC);
retry_random_path:
random_path_utf16.set_size(0);