Git Product home page Git Product logo

Comments (2)

rodrigocfd avatar rodrigocfd commented on September 23, 2024

The unsafe markings on the new (introduced in commit 06fc8d3) and leak (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.

sollyucko avatar sollyucko commented on September 23, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.