Comments (2)
The
unsafe
markings on thenew
(introduced in commit 06fc8d3) andleak
(introduced in commit 38a8884) methods for the ...Guard
structs (e.g. in gdi/guard.rs and macros/handles.rs) are backwards from what they should be, as far as I can tell.For example, doing this requires no
unsafe
block but causes a double-free:let handle: GdiObject = …; drop(GdiObjectGuard::new(handle)); drop(GdiObjectGuard::new(handle));
As far as I remember, the handles that can be wrapped in guards cannot be created at will (at least not safely), as shown in the first line. They are returned from functions already in guards. Can you show me a concrete example where this double free will happen?
In contrast, resource leaks are not considered
unsafe
: https://github.com/rust-lang/rfcs/blob/master/text/1066-safe-mem-forget.md, https://stackoverflow.com/questions/56107324/why-does-rust-consider-it-safe-to-leak-memory, https://stackoverflow.com/questions/55553048/is-it-possible-to-cause-a-memory-leak-in-rust, https://brson.github.io/rust-anthology/1/memory-leaks-are-memory-safe.html, https://doc.rust-lang.org/nomicon/leaking.html, https://www.reddit.com/r/rust/comments/xd1ial/im_i_the_only_one_who_doesnt_like_boxleak_being/, https://cglab.ca/%7Eabeinges/blah/everyone-poops/
Now this is very unsettling:source
Memory leaks do not trigger Undefined Behavior, and therefore are safe.
I must say I'm baffled, but I must abide. I will remove all the unsafe
notations from the leak methods (it will hurt).
from winsafe.
As far as I remember, the handles that can be wrapped in guards cannot be created at will (at least not safely), as shown in the first line. They are returned from functions already in guards.
Yeah, it looks like every function that returns a handle either wraps it in a guard or is marked unsafe
, so I guess that should be fine then. I didn't think to check for that.
Now this is very unsettling:source
Memory leaks do not trigger Undefined Behavior, and therefore are safe.
I must say I'm baffled, but I must abide. I will remove all the unsafe notations from the leak methods (it will hurt).
Yeah, sorry to break the bad news.
from winsafe.
Related Issues (20)
- validate_retrieved_reg_val always fails
- [Question] - Calling windows APIs twice best practice HOT 3
- RegQueryValueEx returning TRANSACTION_REQUEST_NOT_VALID for valid data HOT 6
- nm_custom_draw should provide a mutable reference? HOT 6
- How do you envision WM_USER being used? HOT 1
- `WC::NoValue`? HOT 1
- I don't think `MultiByteToWideChar` and `WideCharToMultiByte` need to add 1 to `num_bytes` HOT 4
- resizable_layout not work as expect HOT 8
- When the new_dlg function is used to create a window, the wm_create event does not work HOT 6
- Async IO should be marked as "unsafe" HOT 1
- CreateToolhelp32Snapshot error when compiling for x86
- Panic in wstring/ QueryFullProcessImageName HOT 3
- How to set up a transparent window? HOT 1
- please font settings HOT 7
- Add missing API to open app in foreground? HOT 3
- Possible ShellExecuteEx implementation HOT 8
- Linker errors in Windows 7
- Add support for raw-window-handle HOT 3
- Can't run library tests on 0.0.21 HOT 8
- winsvc.h HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from winsafe.