-
Notifications
You must be signed in to change notification settings - Fork 21
Open
Description
This example segfaults:
let output_port = {
let context = PortMidi::new().unwrap();
let device = context.device(device_number).unwrap();
context.output_port(device, 1024).unwrap()
};
output_port.write_message(message); // SEGFAULTThe problem is that output_port outlives context. To be more precise, context calls Pm_Terminate in its destructor rendering output_port invalid. But, unfortunately, outport_port is still accessible after the scope braces. The problem can be solved by adding an artificial lifetime to the DeviceInfo struct, s.t. Rust knows that output_port depends on a DeviceInfo instance which depends on context. Also, DeviceInfo::new should be unsafe and PortMidi::device should validate the device number.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels