mirror of
https://github.com/encounter/rust-sdl2.git
synced 2026-07-10 21:18:41 -07:00
Drop Chunk::from_wav_buffer(), it's unsound
Mix_QuickLoad_WAV performs buffer traversal assuming we passed it enough data. This is not necessarily true and protecting against it would duplicate some of the Mix_QuickLoad_WAV logic here. As this is less useful than from_raw_buffer() let's drop it for now.
This commit is contained in:
+3
-11
@@ -232,10 +232,9 @@ impl Drop for Chunk {
|
||||
fn drop(&mut self) {
|
||||
if self.owned {
|
||||
unsafe {
|
||||
// Mix_QuickLoad_* functions don't set the allocated flag, but
|
||||
// from_wav_buffer and from_raw_buffer *do* take ownership of the data,
|
||||
// so we need to deallocate the buffers here, because Mix_FreeChunk won't
|
||||
// and we'd be leaking memory otherwise.
|
||||
// Mix_QuickLoad_* functions don't set the allocated flag, but from_raw_buffer
|
||||
// *does* take ownership of the data, so we need to deallocate the buffers here,
|
||||
// because Mix_FreeChunk won't and we'd be leaking memory otherwise.
|
||||
if (*self.raw).allocated == 0 {
|
||||
drop(Box::from_raw((*self.raw).abuf));
|
||||
}
|
||||
@@ -252,13 +251,6 @@ impl Chunk {
|
||||
Self::from_owned_raw(raw)
|
||||
}
|
||||
|
||||
/// Get chunk based on a buffer containing WAV data in the mixer format. The chunk takes
|
||||
/// ownership of the buffer.
|
||||
pub fn from_wav_buffer(buffer: Box<[u8]>) -> Result<Chunk, String> {
|
||||
let raw = unsafe { mixer::Mix_QuickLoad_WAV(Box::into_raw(buffer) as *mut u8) };
|
||||
Self::from_owned_raw(raw)
|
||||
}
|
||||
|
||||
/// Load chunk from a buffer containing raw audio data in the mixer format. The length of the
|
||||
/// buffer has to fit in 32-bit unsigned integer. The chunk takes ownership of the buffer.
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user