Free the outer slice in C++ usbmuxd::get_devices

This commit is contained in:
Jackson Coxson
2025-12-13 12:34:41 -07:00
parent 080fea02eb
commit 9776516544
2 changed files with 17 additions and 1 deletions

View File

@@ -50,7 +50,7 @@ use idevice::{Idevice, IdeviceSocket, ReadWrite};
use once_cell::sync::Lazy;
use plist_ffi::PlistWrapper;
use std::{
ffi::{CStr, CString, c_char},
ffi::{CStr, CString, c_char, c_void},
ptr::null_mut,
};
use tokio::runtime::{self, Runtime};
@@ -432,3 +432,18 @@ pub unsafe extern "C" fn idevice_plist_array_free(plists: *mut plist_t, len: usi
}
}
}
/// Frees a slice of pointers allocated by this library that had an underlying
/// vec creation.
///
/// The following functions use an underlying vec and are safe to use:
/// - idevice_usbmuxd_get_devices
///
/// # Safety
/// Pass a valid pointer passed by the Vec creating functions
#[unsafe(no_mangle)]
pub unsafe extern "C" fn idevice_outer_slice_free(slice: *mut c_void, len: usize) {
if !slice.is_null() {
let _ = unsafe { Vec::from_raw_parts(slice, len, len) };
}
}