ServoMedia::get is unsound
Closed this issue · 3 comments
The initialization of ServoMedia
is very much unsound and should just be using lazy_static
.
This is INSTANCE
, note how it is initialized as a raw null pointer (that should be using std::ptr::null_mut()
btw):
Line 25 in a70f024
Those are the three methods handling initialization:
Lines 68 to 90 in a70f024
Note how calling ServoMedia::get()
before ServoMedia::init()
or ServoMedia::init_with_backend(backend)
will dereference a null pointer.
Please use lazy_static
instead of manually using Once
and a raw pointer in a static.
The raw pointer and Once
value was previously soundly used but it was broken when the method init
was introduced.
How does one pass Box<dyn Backend>
into lazy_static
block?