Skip to content

Commit 7e67c91

Browse files
committed
chore: Fix macos::get_memory_info may access to uninitialized memory
1 parent 903b531 commit 7e67c91

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

crates/slacc-system-metrics/src/macos.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ pub(crate) unsafe fn get_disk_io() -> Result<DiskInformation, SlaccStatsError> {
231231

232232
IOObjectRelease(parent);
233233
IOObjectRelease(item);
234-
CFRelease(props_dictionary as *const _ as *const ::libc::c_void);
234+
CFRelease(props_dictionary as *const _);
235235
item = IOIteratorNext(iterator);
236236
}
237237

@@ -247,13 +247,13 @@ pub(crate) unsafe fn get_memory_info() -> Result<MemoryInformation, SlaccStatsEr
247247
let mut memory_size: u64 = 0;
248248
let mut command = [libc::CTL_HW, libc::HW_PAGESIZE];
249249
let host_port = libc::mach_host_self();
250-
let mut statistic = MaybeUninit::<::libc::vm_statistics64>::uninit();
250+
let mut statistic = std::mem::zeroed::<::libc::vm_statistics64>();
251251
let mut statistic_count = libc::HOST_VM_INFO64_COUNT;
252252

253253
libc::host_statistics64(
254254
host_port,
255255
libc::HOST_VM_INFO64,
256-
statistic.as_mut_ptr() as *mut i32,
256+
&raw mut statistic as *mut i32,
257257
&mut statistic_count,
258258
)
259259
.into_errno()?;
@@ -269,7 +269,6 @@ pub(crate) unsafe fn get_memory_info() -> Result<MemoryInformation, SlaccStatsEr
269269
.into_errno()?;
270270

271271
command = [libc::CTL_HW, libc::HW_MEMSIZE];
272-
let statistic = statistic.assume_init();
273272

274273
libc::sysctl(
275274
command.as_mut_ptr(),

0 commit comments

Comments
 (0)