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

types: avoid accessing BoundMutex::inner in derived Debug #225

Merged
merged 1 commit into from
Jun 29, 2024
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
19 changes: 17 additions & 2 deletions src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,21 @@ impl std::error::Error for Error {}

mod bound_mutex {
use super::{Bound, CompleteBound, Error, Final};
use std::fmt;
use std::sync::{Arc, Mutex};

/// Source or target type of a Simplicity expression
#[derive(Debug)]
pub struct BoundMutex {
/// The type's status according to the union-bound algorithm.
inner: Mutex<Arc<Bound>>,
}

impl fmt::Debug for BoundMutex {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.get().fmt(f)
}
}

impl BoundMutex {
pub fn new(bound: Bound) -> Self {
BoundMutex {
Expand Down Expand Up @@ -591,7 +597,7 @@ mod tests {
use super::*;

use crate::jet::Core;
use crate::node::{ConstructNode, CoreConstructible};
use crate::node::{ConstructNode, CoreConstructible, WitnessNode};

#[test]
fn inference_failure() {
Expand All @@ -609,4 +615,13 @@ mod tests {
// Trying to do it again should not work.
Arc::<ConstructNode<Core>>::pair(&unit, &take_unit).unwrap_err();
}

#[test]
fn memory_leak() {
let iden = Arc::<WitnessNode<Core>>::iden();
let drop = Arc::<WitnessNode<Core>>::drop_(&iden);
let case = Arc::<WitnessNode<Core>>::case(&iden, &drop).unwrap();

format!("{:?}", case.arrow().source);
}
}
Loading