|
MASKS_ALL = Box::into_raw(v_a); |
|
MASKS_BIT = Box::into_raw(v_b); |
with Box::into_raw(), the pointee is on the heap. Multiple assignments will cause leak of the old value.
Probable fix is like:
If init_masks() should only be called once, adding an Atomic to guarantee assigning only once.
const UNINITIALIZED: usize = 0;
const INITIALIZING: usize = 1;
const INITIALIZED: usize = 2;
static GLOBAL_INIT: AtomicUsize = AtomicUsize::new(UNINITIALIZED);
pub struct SetGlobalDefaultError {
_no_construct: (),
}
// in `init_masks()`
if GLOBAL_INIT
.compare_exchange(
UNINITIALIZED,
INITIALIZING,
Ordering::SeqCst,
Ordering::SeqCst,
)
.is_ok()
{
MASKS_ALL = Box::into_raw(v_a);
MASKS_BIT = Box::into_raw(v_b);
}
}
}
Otherwise add the else branch:
else {
drop(Box::from_raw(MASKS_ALL));
drop(Box::from_raw(MASKS_BIT));
MASKS_ALL = Box::into_raw(v_a);
MASKS_BIT = Box::into_raw(v_b);
}
synthir/src/emulator.rs
Lines 29 to 30 in 98047d1
with
Box::into_raw(), the pointee is on the heap. Multiple assignments will cause leak of the old value.Probable fix is like:
If
init_masks()should only be called once, adding an Atomic to guarantee assigning only once.Otherwise add the else branch: