Skip to content

Commit e2db0ea

Browse files
committed
Fix a graph invariant violation on cycle detection
1 parent 158e535 commit e2db0ea

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
1111
type aliases function the same as the ones they belong to, resolving to either the tracing
1212
versions when debug assertions are enabled or the standard one when they're not.
1313

14+
### Fixed
15+
- Fixed a corruption error where deallocating a previously cyclic mutex could result in a panic.
16+
1417
## [0.1.1] - 2021-05-24
1518

1619
### Changed

src/graph.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ where
127127
// We use map instead of unwrap to avoid an `unwrap()` but we know that these
128128
// entries are present as we just added them above.
129129
self.nodes.get_mut(&y).map(|node| node.in_edges.remove(&x));
130-
self.nodes.get_mut(&x).map(|node| node.out_edges.remove(&x));
130+
self.nodes.get_mut(&x).map(|node| node.out_edges.remove(&y));
131131

132132
// No edge was added
133133
return false;

src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,18 @@ mod tests {
304304
assert!(get_dependency_graph().add_edge(c.value(), a.value()));
305305
}
306306

307+
/// Test creating a cycle, then panicking.
308+
#[test]
309+
#[should_panic]
310+
fn test_mutex_id_conflict() {
311+
let ids = [MutexId::new(), MutexId::new(), MutexId::new()];
312+
313+
for i in 0..3 {
314+
let _first_lock = ids[i].get_borrowed();
315+
let _second_lock = ids[(i + 1) % 3].get_borrowed();
316+
}
317+
}
318+
307319
/// Fuzz the global dependency graph by fake-acquiring lots of mutexes in a valid order.
308320
///
309321
/// This test generates all possible forward edges in a 100-node graph consisting of natural

0 commit comments

Comments
 (0)