Skip to content

Commit 926344a

Browse files
committed
Add a comment about how OwnedHandle should not be used with registry handles.
1 parent 31f7bf8 commit 926344a

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

library/std/src/os/windows/io/handle.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ pub struct BorrowedHandle<'handle> {
4747
/// `INVALID_HANDLE_VALUE` instead of null, use [`OptionFileHandle`] instead
4848
/// of `Option<OwnedHandle>`.
4949
///
50+
/// `OwnedHandle` uses [`CloseHandle`] to close its handle on drop. As such,
51+
/// it must not be used with handles to open registry keys which need to be
52+
/// closed with [`RegCloseKey`] instead.
53+
///
54+
/// [`CloseHandle`]: https://docs.microsoft.com/en-us/windows/win32/api/handleapi/nf-handleapi-closehandle
55+
/// [`RegCloseKey`]: https://docs.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regclosekey
56+
///
5057
/// [here]: https://devblogs.microsoft.com/oldnewthing/20040302-00/?p=40443
5158
#[repr(transparent)]
5259
#[unstable(feature = "io_safety", issue = "87074")]
@@ -178,8 +185,14 @@ impl FromRawHandle for OwnedHandle {
178185
///
179186
/// # Safety
180187
///
181-
/// The resource pointed to by `raw` must be open and suitable for assuming
182-
/// ownership. The resource must not require any cleanup other than `CloseHandle`.
188+
/// The resource pointed to by `raw` must be open and suitable for
189+
/// assuming ownership. The resource must not require any cleanup other
190+
/// than `CloseHandle`.
191+
///
192+
/// In particular, it must not be used with handles to open registry
193+
/// keys which need to be closed with [`RegCloseKey`] instead.
194+
///
195+
/// [`RegCloseKey`]: https://docs.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regclosekey
183196
#[inline]
184197
unsafe fn from_raw_handle(raw: RawHandle) -> Self {
185198
assert!(!raw.is_null());

0 commit comments

Comments
 (0)