From d13480dc9cba1f1fb2ba5bfd33675eb97bfd3a48 Mon Sep 17 00:00:00 2001 From: Eric Fu Date: Fri, 29 Sep 2023 09:53:52 +0000 Subject: [PATCH] remove unsafe code --- src/compute/src/memory_management/policy.rs | 5 ++--- src/compute/src/rpc/service/monitor_service.rs | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/compute/src/memory_management/policy.rs b/src/compute/src/memory_management/policy.rs index 9d450a4f38fc4..1ad08eb46c1d6 100644 --- a/src/compute/src/memory_management/policy.rs +++ b/src/compute/src/memory_management/policy.rs @@ -122,9 +122,9 @@ impl JemallocMemoryControl { .unwrap() .to_string(); + // FIXME: file_path_str is leaked let file_path_str = Box::leak(file_path.into_boxed_str()); - let file_path_bytes = unsafe { file_path_str.as_bytes_mut() }; - let file_path_ptr = file_path_bytes.as_mut_ptr(); + let file_path_bytes = file_path_str.as_bytes(); if let Err(e) = self .jemalloc_dump_mib .write(CStr::from_bytes_with_nul(file_path_bytes).unwrap()) @@ -133,7 +133,6 @@ impl JemallocMemoryControl { } else { tracing::info!("Successfully dumped heap profile to {}", file_name); } - let _ = unsafe { Box::from_raw(file_path_ptr) }; } } } diff --git a/src/compute/src/rpc/service/monitor_service.rs b/src/compute/src/rpc/service/monitor_service.rs index 02b89f5bdf4bf..f450bd5fb1d86 100644 --- a/src/compute/src/rpc/service/monitor_service.rs +++ b/src/compute/src/rpc/service/monitor_service.rs @@ -154,9 +154,9 @@ impl MonitorService for MonitorServiceImpl { .to_str() .ok_or_else(|| Status::internal("The file dir is not a UTF-8 String"))?; + // FIXME: file_path_str is leaked let file_path_str = Box::leak(file_path.to_string().into_boxed_str()); - let file_path_bytes = unsafe { file_path_str.as_bytes_mut() }; - let file_path_ptr = file_path_bytes.as_mut_ptr(); + let file_path_bytes = file_path_str.as_bytes(); let response = if let Err(e) = tikv_jemalloc_ctl::prof::dump::write( CStr::from_bytes_with_nul(file_path_bytes).unwrap(), ) { @@ -165,7 +165,6 @@ impl MonitorService for MonitorServiceImpl { } else { Ok(Response::new(HeapProfilingResponse {})) }; - let _ = unsafe { Box::from_raw(file_path_ptr) }; response }