diff --git a/src/base.rs b/src/base.rs index 4728cb42e6f..7a6a96ab5ac 100644 --- a/src/base.rs +++ b/src/base.rs @@ -496,35 +496,37 @@ pub struct DisplayInfo { /// assert!(parse_display("0").is_none()); /// ``` pub fn parse_display(name: &str) -> Option { - unsafe { - let name = CString::new(name).unwrap(); - let mut hostp: *mut c_char = ptr::null_mut(); - let mut display = 0i32; - let mut screen = 0i32; + let name = CString::new(name).unwrap(); + let mut hostp: *mut c_char = ptr::null_mut(); + let mut display = 0i32; + let mut screen = 0i32; - let success = xcb_parse_display( + let success = unsafe { + xcb_parse_display( name.as_ptr(), &mut hostp as *mut _, &mut display as *mut _, &mut screen as *mut _, - ); + ) + }; - if success != 0 { - let host = CStr::from_ptr(hostp as *const _) - .to_str() - .unwrap() - .to_string(); + if success != 0 { + let host = unsafe { CStr::from_ptr(hostp as *const _) } + .to_str() + .unwrap() + .to_string(); + unsafe { libc::free(hostp as *mut _); - - Some(DisplayInfo { - host, - display, - screen, - }) - } else { - None } + + Some(DisplayInfo { + host, + display, + screen, + }) + } else { + None } }