Jörg Höhle : winmm: PlaySound concurrency cleanup .
Alexandre Julliard
julliard at winehq.org
Wed Mar 30 13:15:38 CDT 2011
Module: wine
Branch: master
Commit: e0dcc2cd7d4495b7056a47ada1af74cc7c318ef2
URL: http://source.winehq.org/git/wine.git/?a=commit;h=e0dcc2cd7d4495b7056a47ada1af74cc7c318ef2
Author: Jörg Höhle <hoehle at users.sourceforge.net>
Date: Mon Mar 28 22:34:02 2011 +0200
winmm: PlaySound concurrency cleanup.
---
dlls/winmm/playsound.c | 22 +++++++++++++---------
1 files changed, 13 insertions(+), 9 deletions(-)
diff --git a/dlls/winmm/playsound.c b/dlls/winmm/playsound.c
index 3624124..02e24e8 100644
--- a/dlls/winmm/playsound.c
+++ b/dlls/winmm/playsound.c
@@ -44,7 +44,6 @@ typedef struct tagWINE_PLAYSOUND
LPCWSTR pszSound;
HMODULE hMod;
DWORD fdwSound;
- HANDLE hThread;
struct tagWINE_PLAYSOUND* lpNext;
} WINE_PLAYSOUND;
@@ -215,7 +214,6 @@ static void PlaySound_Free(WINE_PLAYSOUND* wps)
if (PlaySoundList == NULL) SetEvent(psLastEvent);
LeaveCriticalSection(&WINMM_cs);
if (wps->bAlloc) HeapFree(GetProcessHeap(), 0, (void*)wps->pszSound);
- if (wps->hThread) CloseHandle(wps->hThread);
HeapFree(GetProcessHeap(), 0, wps);
}
@@ -258,7 +256,8 @@ static WINE_PLAYSOUND* PlaySound_Alloc(const void* pszSound, HMODULE hmod,
return wps;
oom_error:
- PlaySound_Free(wps);
+ if (wps->bAlloc) HeapFree(GetProcessHeap(), 0, (void*)wps->pszSound);
+ HeapFree(GetProcessHeap(), 0, wps);
return NULL;
}
@@ -377,6 +376,8 @@ static DWORD WINAPI proc_PlaySound(LPVOID arg)
(LPSTR)&mmckInfo.ckid, mmckInfo.fccType, mmckInfo.cksize);
lpWaveFormat = HeapAlloc(GetProcessHeap(), 0, mmckInfo.cksize);
+ if (!lpWaveFormat)
+ goto errCleanUp;
if (mmioRead(hmmio, (HPSTR)lpWaveFormat, mmckInfo.cksize) < sizeof(PCMWAVEFORMAT))
goto errCleanUp;
@@ -398,6 +399,8 @@ static DWORD WINAPI proc_PlaySound(LPVOID arg)
(LPSTR)&mmckInfo.ckid, mmckInfo.fccType, mmckInfo.cksize);
s.hEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
+ if (!s.hEvent)
+ goto errCleanUp;
if (waveOutOpen(&hWave, WAVE_MAPPER, lpWaveFormat, (DWORD_PTR)PlaySound_Callback,
(DWORD_PTR)&s, CALLBACK_FUNCTION) != MMSYSERR_NOERROR)
@@ -407,6 +410,8 @@ static DWORD WINAPI proc_PlaySound(LPVOID arg)
bufsize = (((lpWaveFormat->nAvgBytesPerSec / 3) - 1) / lpWaveFormat->nBlockAlign + 1) *
lpWaveFormat->nBlockAlign;
waveHdr = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(WAVEHDR) + 2 * bufsize);
+ if (!waveHdr)
+ goto errCleanUp;
waveHdr[0].lpData = (char*)waveHdr + 2 * sizeof(WAVEHDR);
waveHdr[1].lpData = (char*)waveHdr + 2 * sizeof(WAVEHDR) + bufsize;
waveHdr[0].dwUser = waveHdr[1].dwUser = 0L;
@@ -458,10 +463,10 @@ static DWORD WINAPI proc_PlaySound(LPVOID arg)
errCleanUp:
TRACE("Done playing=%s => %s!\n", debugstr_w(wps->pszSound), bRet ? "ok" : "ko");
- CloseHandle(s.hEvent);
- HeapFree(GetProcessHeap(), 0, waveHdr);
HeapFree(GetProcessHeap(), 0, lpWaveFormat);
if (hWave) while (waveOutClose(hWave) == WAVERR_STILLPLAYING) Sleep(100);
+ CloseHandle(s.hEvent);
+ HeapFree(GetProcessHeap(), 0, waveHdr);
if (hmmio) mmioClose(hmmio, 0);
PlaySound_Free(wps);
@@ -509,16 +514,15 @@ static BOOL MULTIMEDIA_PlaySound(const void* pszSound, HMODULE hmod, DWORD fdwSo
PlaySoundList = wps;
LeaveCriticalSection(&WINMM_cs);
- if (!pszSound || (fdwSound & SND_PURGE)) return TRUE;
+ if (!wps) return TRUE;
if (fdwSound & SND_ASYNC)
{
- DWORD id;
HANDLE handle;
wps->bLoop = (fdwSound & SND_LOOP) ? TRUE : FALSE;
- if ((handle = CreateThread(NULL, 0, proc_PlaySound, wps, 0, &id)) != 0) {
- wps->hThread = handle;
+ if ((handle = CreateThread(NULL, 0, proc_PlaySound, wps, 0, NULL)) != 0) {
SetThreadPriority(handle, THREAD_PRIORITY_TIME_CRITICAL);
+ CloseHandle(handle);
return TRUE;
}
}
More information about the wine-cvs
mailing list