CString::new("/tmp/noted").unwrap().as_ptr() line creates a temporary CString, gets the pointer to it, and then deallocates it. Because this is a common issue, the behaviour on drop was changed to zero the first byte of all CStrings when they are dropped, so at the end of the first line,
filename points to memory which is technically freed, but which probably contains
\0. Unfortunately, raw pointers do not contain lifetimes so there is no error. For example, if you change
to_bytes() you'll get an error.
To fix it, you need to change it so that the
CString outlives the call to
let filename = CString::new("/tmp/noted").unwrap(); // No as ptr
libc::mkfifo(filename.as_ptr(), 0o644); // as_ptr moved here