Skip to content

Commit

Permalink
remove unsafe code
Browse files Browse the repository at this point in the history
  • Loading branch information
fuyufjh committed Sep 29, 2023
1 parent 8f220de commit d13480d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
5 changes: 2 additions & 3 deletions src/compute/src/memory_management/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -133,7 +133,6 @@ impl JemallocMemoryControl {
} else {
tracing::info!("Successfully dumped heap profile to {}", file_name);
}
let _ = unsafe { Box::from_raw(file_path_ptr) };
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/compute/src/rpc/service/monitor_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
) {
Expand All @@ -165,7 +165,6 @@ impl MonitorService for MonitorServiceImpl {
} else {
Ok(Response::new(HeapProfilingResponse {}))
};
let _ = unsafe { Box::from_raw(file_path_ptr) };
response
}

Expand Down

0 comments on commit d13480d

Please sign in to comment.