diff --git a/src/compute/src/memory_management/policy.rs b/src/compute/src/memory_management/policy.rs index 9d450a4f38fc..a735797c88e2 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(); + // `file_path_str` is leaked because `jemalloc_dump_mib.write` requires static lifetime 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 02b89f5bdf4b..82cf5c217dbc 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"))?; + // `file_path_str` is leaked because `prof::dump::write` requires static lifetime 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 }