Fixed memory leak (#919)
Fixed memory leak for parameter ppClosestMatch in call to IAudioClient::IsFormatSupported
This commit is contained in:
parent
fb9a53982a
commit
d7dee9af10
1 changed files with 19 additions and 37 deletions
|
|
@ -152,43 +152,25 @@ pub unsafe fn is_format_supported(
|
||||||
waveformatex_ptr: *const Audio::WAVEFORMATEX,
|
waveformatex_ptr: *const Audio::WAVEFORMATEX,
|
||||||
) -> Result<bool, SupportedStreamConfigsError> {
|
) -> Result<bool, SupportedStreamConfigsError> {
|
||||||
// Check if the given format is supported.
|
// Check if the given format is supported.
|
||||||
let is_supported = |waveformatex_ptr, closest_waveformatex_ptr| {
|
let mut closest_waveformatex_ptr: *mut Audio::WAVEFORMATEX = ptr::null_mut();
|
||||||
let result = client.IsFormatSupported(
|
|
||||||
Audio::AUDCLNT_SHAREMODE_SHARED,
|
|
||||||
waveformatex_ptr,
|
|
||||||
Some(closest_waveformatex_ptr),
|
|
||||||
);
|
|
||||||
// `IsFormatSupported` can return `S_FALSE` (which means that a compatible format
|
|
||||||
// has been found, but not an exact match) so we also treat this as unsupported.
|
|
||||||
match result {
|
|
||||||
Audio::AUDCLNT_E_DEVICE_INVALIDATED => {
|
|
||||||
Err(SupportedStreamConfigsError::DeviceNotAvailable)
|
|
||||||
}
|
|
||||||
r if r.is_err() => Ok(false),
|
|
||||||
Foundation::S_FALSE => Ok(false),
|
|
||||||
_ => Ok(true),
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// First we want to retrieve a pointer to the `WAVEFORMATEX`.
|
let result = client.IsFormatSupported(
|
||||||
// Although `GetMixFormat` writes the format to a given `WAVEFORMATEX` pointer,
|
Audio::AUDCLNT_SHAREMODE_SHARED,
|
||||||
// the pointer itself may actually point to a `WAVEFORMATEXTENSIBLE` structure.
|
waveformatex_ptr,
|
||||||
// We check the wFormatTag to determine this and get a pointer to the correct type.
|
Some(&mut closest_waveformatex_ptr as *mut _),
|
||||||
match (*waveformatex_ptr).wFormatTag as u32 {
|
);
|
||||||
Audio::WAVE_FORMAT_PCM | Multimedia::WAVE_FORMAT_IEEE_FLOAT => {
|
|
||||||
let mut closest_waveformatex = *waveformatex_ptr;
|
if !closest_waveformatex_ptr.is_null() {
|
||||||
let mut closest_waveformatex_ptr = &mut closest_waveformatex as *mut _;
|
Com::CoTaskMemFree(Some(closest_waveformatex_ptr as *mut std::ffi::c_void));
|
||||||
is_supported(waveformatex_ptr, &mut closest_waveformatex_ptr as *mut _)
|
}
|
||||||
}
|
|
||||||
KernelStreaming::WAVE_FORMAT_EXTENSIBLE => {
|
// `IsFormatSupported` can return `S_FALSE` (which means that a compatible format
|
||||||
let waveformatextensible_ptr = waveformatex_ptr as *const Audio::WAVEFORMATEXTENSIBLE;
|
// has been found, but not an exact match) so we also treat this as unsupported.
|
||||||
let mut closest_waveformatextensible = *waveformatextensible_ptr;
|
match result {
|
||||||
let closest_waveformatextensible_ptr = &mut closest_waveformatextensible as *mut _;
|
Audio::AUDCLNT_E_DEVICE_INVALIDATED => Err(SupportedStreamConfigsError::DeviceNotAvailable),
|
||||||
let mut closest_waveformatex_ptr =
|
r if r.is_err() => Ok(false),
|
||||||
closest_waveformatextensible_ptr as *mut Audio::WAVEFORMATEX;
|
Foundation::S_FALSE => Ok(false),
|
||||||
is_supported(waveformatex_ptr, &mut closest_waveformatex_ptr as *mut _)
|
_ => Ok(true),
|
||||||
}
|
|
||||||
_ => Ok(false),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -262,7 +244,7 @@ unsafe fn format_from_waveformatex_ptr(
|
||||||
} else {
|
} else {
|
||||||
SupportedBufferSize::Range {
|
SupportedBufferSize::Range {
|
||||||
min: 0,
|
min: 0,
|
||||||
max: u32::max_value(),
|
max: u32::MAX,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue