Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Field host in struct OfxHost and String in enum PropertyValue can be leaked. #3

Open
labyrinth-ssr opened this issue Jul 27, 2023 · 0 comments

Comments

@labyrinth-ssr
Copy link

labyrinth-ssr commented Jul 27, 2023

#[derive(Debug, Clone)]
pub enum PropertyValue {
Pointer(*const c_void),
Integer(c_int),
Double(c_double),
String(*const c_char), // TODO : differenciate between host and plugin allocated strings
Undefined,
}

impl<'a> From<&'a str> for PropertyValue {
fn from(value: &'a str) -> Self {
let cstr = CString::new(value).unwrap();
PropertyValue::String(cstr.into_raw())
}
}

The destructor won't release PropertyValue.String (on the heap since PropertyValue::String(c_str.to_owned().into_raw()) ), causing memory leak.

To free the field, probable fix is to implement drop for PropertyValue.

rustfx/src/suites/core.rs

Lines 116 to 121 in 8209089

#[repr(C)]
#[allow(non_snake_case)]
pub struct OfxHost {
pub host: OfxPropertySetHandle,
pub fetchSuite: extern "C" fn(OfxPropertySetHandle, *const c_char, c_int) -> *mut c_void,
}

rustfx/src/suites/core.rs

Lines 160 to 170 in 8209089

impl OfxHost {
pub fn new(properties: Box<OfxPropertySet>) -> Box<OfxHost> {
let host_props = Box::into_raw(properties);
trace!("properties for host set ptr is {:?}",
host_props as *const _);
Box::new(OfxHost {
host: host_props as *mut libc::c_void,
fetchSuite: fetch_suite,
})
}
}

The destructor won't release OfxHost.host (on the heap since host_props = Box::into_raw(properties); ), causing memory leak.

Probable fix is to add release for host in drop for OfxHost.

rustfx/src/suites/core.rs

Lines 123 to 129 in 8209089

#[cfg(debug)]
impl Drop for OfxHost {
fn drop( & mut self ) {
println!("Dropping host");
}
}

@labyrinth-ssr labyrinth-ssr changed the title Proxy field host in struct OfxHost and String in enum PropertyValue. Field host in struct OfxHost and String in enum PropertyValue can be leaked. Jul 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant