News for hackers. Stuff that matters.
Re:Comparative unsafety by mqus on Friday April 09, 2021 @11:04AM (#26751421)
to be clear, not path is freed, but what path points to, meaning the result of CString::new(...).unwrap()

Because it is not bound to a variable, it will get dropped before the next line, even if we create a pointer to it. if you would have borrowed instead of creating a pointer this would have been a compiler error because the borrow would have outlived the original object. But a pointer exists outside of the borrow semantics and lifetimes, that is also why it can only be used inside the unsafe block.

There are no comments on this comment yet.