5 ms·
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 dr
by mqus 6y ago
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.