From 84e7b08a631bac0f209259fb74ee463593ef6e8c Mon Sep 17 00:00:00 2001 From: Benjamin Peinhardt Date: Wed, 5 Jan 2022 11:23:06 -0600 Subject: [PATCH] Oops two lines of unsafe code and I do a double free --- src/xpath.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/xpath.rs b/src/xpath.rs index b3f51ce6e0..0b1356f7a4 100644 --- a/src/xpath.rs +++ b/src/xpath.rs @@ -257,6 +257,8 @@ pub fn xml_xpath_compiles(xpath: &str) -> bool { let c_xpath = CString::new(xpath).unwrap(); let xml_xpath_comp_expr_ptr = unsafe { xmlXPathCompile(c_xpath.as_bytes().as_ptr()) }; let result = !xml_xpath_comp_expr_ptr.is_null(); - unsafe { libc::free(xml_xpath_comp_expr_ptr as *mut c_void); } + if result { + unsafe { libc::free(xml_xpath_comp_expr_ptr as *mut c_void); } + } result }