Huw Davies : winealsa: Use NtAllocateVirtualMemory() to alloc the buffers returned to the user.
Alexandre Julliard
julliard at winehq.org
Tue Feb 22 16:06:52 CST 2022
Module: wine
Branch: master
Commit: 7262da2afcb18682da76d9787ead8cbdfe5ab20a
URL: https://source.winehq.org/git/wine.git/?a=commit;h=7262da2afcb18682da76d9787ead8cbdfe5ab20a
Author: Huw Davies <huw at codeweavers.com>
Date: Tue Feb 22 08:14:17 2022 +0000
winealsa: Use NtAllocateVirtualMemory() to alloc the buffers returned to the user.
Signed-off-by: Huw Davies <huw at codeweavers.com>
Signed-off-by: Andrew Eikum <aeikum at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/winealsa.drv/mmdevdrv.c | 52 +++++++++++++++++++++++++++++++-------------
1 file changed, 37 insertions(+), 15 deletions(-)
diff --git a/dlls/winealsa.drv/mmdevdrv.c b/dlls/winealsa.drv/mmdevdrv.c
index 23a420c8ac7..d89ae4ee9ec 100644
--- a/dlls/winealsa.drv/mmdevdrv.c
+++ b/dlls/winealsa.drv/mmdevdrv.c
@@ -597,12 +597,19 @@ static ULONG WINAPI AudioClient_Release(IAudioClient3 *iface)
}
HeapFree(GetProcessHeap(), 0, This->vols);
if (stream){
+ SIZE_T size;
snd_pcm_drop(stream->pcm_handle);
snd_pcm_close(stream->pcm_handle);
- HeapFree(GetProcessHeap(), 0, stream->local_buffer);
+ if(stream->local_buffer){
+ size = 0;
+ NtFreeVirtualMemory(GetCurrentProcess(), (void **)&stream->local_buffer, &size, MEM_RELEASE);
+ }
+ if(stream->tmp_buffer){
+ size = 0;
+ NtFreeVirtualMemory(GetCurrentProcess(), (void **)&stream->tmp_buffer, &size, MEM_RELEASE);
+ }
HeapFree(GetProcessHeap(), 0, stream->remapping_buf);
HeapFree(GetProcessHeap(), 0, stream->silence_buf);
- HeapFree(GetProcessHeap(), 0, stream->tmp_buffer);
HeapFree(GetProcessHeap(), 0, stream->hw_params);
CoTaskMemFree(stream->fmt);
HeapFree(GetProcessHeap(), 0, stream->vols);
@@ -928,6 +935,7 @@ static HRESULT WINAPI AudioClient_Initialize(IAudioClient3 *iface,
unsigned int rate, alsa_period_us;
int err, i;
HRESULT hr = S_OK;
+ SIZE_T size;
TRACE("(%p)->(%x, %x, %s, %s, %p, %s)\n", This, mode, flags,
wine_dbgstr_longlong(duration), wine_dbgstr_longlong(period), fmt, debugstr_guid(sessionguid));
@@ -1158,9 +1166,9 @@ static HRESULT WINAPI AudioClient_Initialize(IAudioClient3 *iface,
goto exit;
}
- stream->local_buffer = HeapAlloc(GetProcessHeap(), 0,
- stream->bufsize_frames * fmt->nBlockAlign);
- if(!stream->local_buffer){
+ size = stream->bufsize_frames * fmt->nBlockAlign;
+ if(NtAllocateVirtualMemory(GetCurrentProcess(), (void **)&stream->local_buffer, 0, &size,
+ MEM_COMMIT, PAGE_READWRITE)){
hr = E_OUTOFMEMORY;
goto exit;
}
@@ -1212,8 +1220,10 @@ exit:
HeapFree(GetProcessHeap(), 0, sw_params);
if(FAILED(hr)){
snd_pcm_close(stream->pcm_handle);
- HeapFree(GetProcessHeap(), 0, stream->local_buffer);
- stream->local_buffer = NULL;
+ if(stream->local_buffer){
+ size = 0;
+ NtFreeVirtualMemory(GetCurrentProcess(), (void **)&stream->local_buffer, &size, MEM_RELEASE);
+ }
CoTaskMemFree(stream->fmt);
stream->fmt = NULL;
HeapFree(GetProcessHeap(), 0, stream->vols);
@@ -2297,6 +2307,7 @@ static HRESULT WINAPI AudioRenderClient_GetBuffer(IAudioRenderClient *iface,
ACImpl *This = impl_from_IAudioRenderClient(iface);
struct alsa_stream *stream = This->stream;
UINT32 write_pos;
+ SIZE_T size;
TRACE("(%p)->(%u, %p)\n", This, frames, data);
@@ -2325,10 +2336,15 @@ static HRESULT WINAPI AudioRenderClient_GetBuffer(IAudioRenderClient *iface,
write_pos = stream->wri_offs_frames;
if(write_pos + frames > stream->bufsize_frames){
if(stream->tmp_buffer_frames < frames){
- HeapFree(GetProcessHeap(), 0, stream->tmp_buffer);
- stream->tmp_buffer = HeapAlloc(GetProcessHeap(), 0,
- frames * stream->fmt->nBlockAlign);
- if(!stream->tmp_buffer){
+ if(stream->tmp_buffer){
+ size = 0;
+ NtFreeVirtualMemory(GetCurrentProcess(), (void **)&stream->tmp_buffer, &size, MEM_RELEASE);
+ stream->tmp_buffer = NULL;
+ }
+ size = frames * stream->fmt->nBlockAlign;
+ if(NtAllocateVirtualMemory(GetCurrentProcess(), (void **)&stream->tmp_buffer, 0, &size,
+ MEM_COMMIT, PAGE_READWRITE)){
+ stream->tmp_buffer_frames = 0;
alsa_unlock(stream);
return E_OUTOFMEMORY;
}
@@ -2465,6 +2481,7 @@ static HRESULT WINAPI AudioCaptureClient_GetBuffer(IAudioCaptureClient *iface,
{
ACImpl *This = impl_from_IAudioCaptureClient(iface);
struct alsa_stream *stream = This->stream;
+ SIZE_T size;
TRACE("(%p)->(%p, %p, %p, %p, %p)\n", This, data, frames, flags,
devpos, qpcpos);
@@ -2495,10 +2512,15 @@ static HRESULT WINAPI AudioCaptureClient_GetBuffer(IAudioCaptureClient *iface,
if(stream->lcl_offs_frames + *frames > stream->bufsize_frames){
UINT32 chunk_bytes, offs_bytes, frames_bytes;
if(stream->tmp_buffer_frames < *frames){
- HeapFree(GetProcessHeap(), 0, stream->tmp_buffer);
- stream->tmp_buffer = HeapAlloc(GetProcessHeap(), 0,
- *frames * stream->fmt->nBlockAlign);
- if(!stream->tmp_buffer){
+ if(stream->tmp_buffer){
+ size = 0;
+ NtFreeVirtualMemory(GetCurrentProcess(), (void **)&stream->tmp_buffer, &size, MEM_RELEASE);
+ stream->tmp_buffer = NULL;
+ }
+ size = *frames * stream->fmt->nBlockAlign;
+ if(NtAllocateVirtualMemory(GetCurrentProcess(), (void **)&stream->tmp_buffer, 0, &size,
+ MEM_COMMIT, PAGE_READWRITE)){
+ stream->tmp_buffer_frames = 0;
alsa_unlock(stream);
return E_OUTOFMEMORY;
}
More information about the wine-cvs
mailing list