Skip to content

Commit

Permalink
fix(alloc): potentially dangling temporary (#772)
Browse files Browse the repository at this point in the history
* fix: potentially dangling temporary

I was trying out the Rust 2024 edition which required a new nightly.
There's now a warning for dangling_pointers_from_temporaries. This
could be a false positive but I am not certain.

* test: skip problematic miri tests on MacOS

These are all due to kqueue, example:

```
error: unsupported operation: can't call foreign function `kqueue` on OS `macos`
   --> /levi.morrison/.cargo/registry/src/index.crates.io-6f17d22bba15001f/mio-1.0.2/src/sys/unix/selector/kqueue.rs:76:48
    |
76  |         let kq = unsafe { OwnedFd::from_raw_fd(syscall!(kqueue())?) };
    |                                                ^^^^^^^^^^^^^^^^^^ can't call foreign function `kqueue` on OS `macos`
```

* test: fix env test when running locally

If the local env has this set, it fails.
  • Loading branch information
morrisonlevi authored Dec 2, 2024
1 parent 17f36e9 commit 1c1fc18
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 4 deletions.
7 changes: 3 additions & 4 deletions alloc/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,9 @@ impl<A: Allocator + Clone> Drop for ChainAllocator<A> {
// moved to the stack before the chunk is dropped, so it's
// alive and valid after the chunk is dropped below.
chain_node_ptr = unsafe {
core::ptr::addr_of!((*non_null.as_ptr()).prev)
.read()
.get()
.read()
// Save to variable to avoid a dangling temporary.
let unsafe_cell = core::ptr::addr_of!((*non_null.as_ptr()).prev).read();
unsafe_cell.get().read()
};

// SAFETY: the chunk hasn't been dropped yet, and the
Expand Down
2 changes: 2 additions & 0 deletions data-pipeline/src/trace_exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,7 @@ mod tests {
use tinybytes::BytesString;
use tokio::time::sleep;

#[cfg_attr(all(miri, target_os = "macos"), ignore)]
#[test]
fn new() {
let builder = TraceExporterBuilder::default();
Expand Down Expand Up @@ -951,6 +952,7 @@ mod tests {
assert!(!exporter.metadata.client_computed_stats);
}

#[cfg_attr(all(miri, target_os = "macos"), ignore)]
#[test]
fn new_defaults() {
let builder = TraceExporterBuilder::default();
Expand Down
1 change: 1 addition & 0 deletions sidecar/src/service/debugger_diagnostics_bookkeeper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ mod tests {
}
}

#[cfg_attr(all(miri, target_os = "macos"), ignore)]
#[tokio::test]
async fn test_bookkeeper() {
let bookkeeper = DebuggerDiagnosticsBookkeeper::start();
Expand Down
1 change: 1 addition & 0 deletions sidecar/src/service/session_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ mod tests {
use super::*;

#[tokio::test]
#[cfg_attr(all(miri, target_os = "macos"), ignore)]
async fn test_get_runtime() {
let session_info = SessionInfo::default();
let runtime_id = "runtime1".to_string();
Expand Down
1 change: 1 addition & 0 deletions trace-mini-agent/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ mod tests {
#[test]
#[serial]
fn test_error_if_no_api_key_env_var() {
env::remove_var("DD_API_KEY");
let config = config::Config::new();
assert!(config.is_err());
assert_eq!(
Expand Down
1 change: 1 addition & 0 deletions trace-protobuf/src/pb_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ mod tests {

use crate::pb::{ClientGroupedStats, ClientStatsBucket, ClientStatsPayload, Trilean::NotSet};

#[cfg_attr(all(miri, target_os = "macos"), ignore)]
#[tokio::test]
async fn test_deserialize_client_stats_payload() {
let stats_json = r#"{
Expand Down
3 changes: 3 additions & 0 deletions trace-utils/src/stats_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ mod tests {
use serde_json::Value;

#[tokio::test]
#[cfg_attr(all(miri, target_os = "macos"), ignore)]
async fn test_get_stats_from_request_body() {
let stats_json = r#"{
"Hostname": "TestHost",
Expand Down Expand Up @@ -188,6 +189,7 @@ mod tests {
}

#[tokio::test]
#[cfg_attr(all(miri, target_os = "macos"), ignore)]
async fn test_get_stats_from_request_body_without_stats() {
let stats_json = r#"{
"Hostname": "TestHost",
Expand Down Expand Up @@ -239,6 +241,7 @@ mod tests {
}

#[tokio::test]
#[cfg_attr(all(miri, target_os = "macos"), ignore)]
async fn test_serialize_client_stats_payload_without_stats() {
let client_stats_payload_without_stats = ClientStatsPayload {
hostname: "TestHost".to_string(),
Expand Down
1 change: 1 addition & 0 deletions trace-utils/src/trace_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,7 @@ mod tests {

#[tokio::test]
#[allow(clippy::type_complexity)]
#[cfg_attr(all(miri, target_os = "macos"), ignore)]
async fn get_v05_traces_from_request_body() {
let data: (
Vec<String>,
Expand Down

0 comments on commit 1c1fc18

Please sign in to comment.