diff --git a/src/configure/auto_mozilla.rs b/src/configure/auto_mozilla.rs index 005cc5fcb..1a9a2eeea 100644 --- a/src/configure/auto_mozilla.rs +++ b/src/configure/auto_mozilla.rs @@ -1,10 +1,8 @@ -use libc::free; use quick_xml; use quick_xml::events::{BytesEnd, BytesStart, BytesText}; use crate::constants::*; use crate::context::Context; -use crate::dc_tools::*; use crate::login_param::LoginParam; use super::read_autoconf_file; @@ -29,21 +27,17 @@ pub unsafe fn moz_autoconfigure( url: &str, param_in: &LoginParam, ) -> Option { - let xml_raw = read_autoconf_file(context, url); - if xml_raw.is_null() { - return None; - } + let xml_raw = read_autoconf_file(context, url)?; // Split address into local part and domain part. let p = param_in.addr.find("@"); if p.is_none() { - free(xml_raw as *mut libc::c_void); return None; } let (in_emaillocalpart, in_emaildomain) = param_in.addr.split_at(p.unwrap()); let in_emaildomain = &in_emaildomain[1..]; - let mut reader = quick_xml::Reader::from_str(as_str(xml_raw)); + let mut reader = quick_xml::Reader::from_str(&xml_raw); reader.trim_text(true); let mut buf = Vec::new(); @@ -88,11 +82,9 @@ pub unsafe fn moz_autoconfigure( { let r = moz_ac.out.to_string(); warn!(context, "Bad or incomplete autoconfig: {}", r,); - free(xml_raw as *mut libc::c_void); return None; } - free(xml_raw as *mut libc::c_void); Some(moz_ac.out) } diff --git a/src/configure/auto_outlook.rs b/src/configure/auto_outlook.rs index 654809194..9e0edad75 100644 --- a/src/configure/auto_outlook.rs +++ b/src/configure/auto_outlook.rs @@ -28,7 +28,6 @@ pub unsafe fn outlk_autodiscover( url__: &str, param_in: &LoginParam, ) -> Option { - let mut xml_raw: *mut libc::c_char = ptr::null_mut(); let mut url = url__.to_string(); let mut outlk_ad = outlk_autodiscover_t { in_0: param_in, @@ -54,13 +53,8 @@ pub unsafe fn outlk_autodiscover( ::std::mem::size_of::(), ); - xml_raw = read_autoconf_file(context, &url); - if xml_raw.is_null() { - ok_to_continue = false; - break; - } - - let mut reader = quick_xml::Reader::from_str(as_str(xml_raw)); + if let Some(xml_raw) = read_autoconf_file(context, &url) { + let mut reader = quick_xml::Reader::from_str(&xml_raw); reader.trim_text(true); let mut buf = Vec::new(); @@ -101,9 +95,11 @@ pub unsafe fn outlk_autodiscover( url = as_str(outlk_ad.config[5usize]).to_string(); outlk_clean_config(&mut outlk_ad); - free(xml_raw as *mut libc::c_void); - xml_raw = ptr::null_mut(); i += 1; + } else { + ok_to_continue = false; + break; + } } if ok_to_continue { @@ -114,13 +110,11 @@ pub unsafe fn outlk_autodiscover( { let r = outlk_ad.out.to_string(); warn!(context, "Bad or incomplete autoconfig: {}", r,); - free(xml_raw as *mut libc::c_void); outlk_clean_config(&mut outlk_ad); return None; } } - free(xml_raw as *mut libc::c_void); outlk_clean_config(&mut outlk_ad); if out_null { None diff --git a/src/configure/mod.rs b/src/configure/mod.rs index 8a0fba1d4..6116babdc 100644 --- a/src/configure/mod.rs +++ b/src/configure/mod.rs @@ -633,7 +633,7 @@ pub fn dc_stop_ongoing_process(context: &Context) { }; } -pub fn read_autoconf_file(context: &Context, url: &str) -> *mut libc::c_char { +pub fn read_autoconf_file(context: &Context, url: &str) -> Option { info!(context, "Testing {} ...", url); match reqwest::Client::new() @@ -641,11 +641,11 @@ pub fn read_autoconf_file(context: &Context, url: &str) -> *mut libc::c_char { .send() .and_then(|mut res| res.text()) { - Ok(res) => unsafe { res.strdup() }, + Ok(res) => Some(res), Err(_err) => { info!(context, "Can\'t read file.",); - std::ptr::null_mut() + None } } }