Skip to content

Commit

Permalink
Fix build lifetime issue on freebsd, netbsd,
Browse files Browse the repository at this point in the history
illumos and solaris, too

warning: getting the inner pointer of a temporary `CString`
  --> src/bpf.rs:82:57
   |
82 |                 CString::new(&b"/dev/bpf"[..]).unwrap().as_ptr(),
   |                 --------------------------------------- ^^^^^^ this pointer will be invalid
   |                 |
   |                 this `CString` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
   |
   = note: `#[warn(temporary_cstring_as_ptr)]` on by default
   = note: pointers do not have a lifetime; when calling `as_ptr` the `CString` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
   = help: for more information, see https://doc.rust-lang.org/reference/destructors.html
  • Loading branch information
teutat3s committed Apr 10, 2022
1 parent f1f38b8 commit cbb6eb9
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pnet_datalink/src/bpf.rs
Expand Up @@ -82,9 +82,10 @@ pub fn channel(network_interface: &NetworkInterface, config: Config) -> io::Resu
target_os = "solaris"
))]
fn get_fd(_attempts: usize) -> libc::c_int {
let c_file_name = CString::new(&b"/dev/bpf"[..]).unwrap();
unsafe {
libc::open(
CString::new(&b"/dev/bpf"[..]).unwrap().as_ptr(),
c_file_name.as_ptr(),
libc::O_RDWR,
0,
)
Expand Down

0 comments on commit cbb6eb9

Please sign in to comment.