From 482a039f92cf713792fd11e123dbd6622dd4a921 Mon Sep 17 00:00:00 2001 From: Gautier Minster Date: Tue, 23 Jun 2020 17:01:11 -0700 Subject: [PATCH] FIXUP: also fix AudioQueue::open_queue --- src/sdl2/audio.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/sdl2/audio.rs b/src/sdl2/audio.rs index 0551e186..6e77b4f1 100644 --- a/src/sdl2/audio.rs +++ b/src/sdl2/audio.rs @@ -559,7 +559,10 @@ impl<'a, Channel: AudioFormatNum> AudioQueue { Some(device) => Some(CString::new(device).unwrap()), None => None }; - let device_ptr = device.map_or(ptr::null(), |s| s.as_ptr()); + // Warning: map_or consumes its argument; `device.map_or()` would therefore consume the + // CString and drop it, making device_ptr a dangling pointer! To avoid that we downgrade + // device to an Option<&_> first. + let device_ptr = device.as_ref().map_or(ptr::null(), |s| s.as_ptr()); let iscapture_flag = 0; let device_id = sys::SDL_OpenAudioDevice(