Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doubly-linked-list: improve leak check #2043

Merged
merged 1 commit into from
Feb 26, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ fn drop_no_leaks() {
drop(list);

let allocated_after = ALLOCATED.load(SeqCst);
let leaked_bytes = allocated_before - allocated_after;
assert!(leaked_bytes == 0);
Comment on lines -22 to -23
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was there any particular reason for choosing subtraction over equality in the past? It seems like a really strange decision.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at it more closely, it just looks like a logic error. Even if there was a reason for the subtraction, the order should have been reversed. There's no conceivable reason for allocated_before to ever be larger than allocated_after.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original PR is here, I can't find any discussion on that.

assert_eq!(allocated_before, allocated_after);
}

// Defines a wrapper around the global allocator that counts allocations
Expand Down