Skip to content
Snippets Groups Projects
Commit 18857b89 authored by yta's avatar yta Committed by TAMUKI Shoichi
Browse files

Fix NULL pointer access issue (Windows audio driver output)


Add DriverClosing and OutputWorking flags.  If TiMidity++ called
close_output during a stop at output_data, app cause a NULL pointer
access.  After changing, WaitForBuffer(1) to stop until return from
output_data.

Signed-off-by: default avataryta <yta@inter7.jp>
parent cc029545
No related branches found
No related tags found
No related merge requests found
...@@ -181,11 +181,14 @@ static volatile int NumBuffersInUse; ...@@ -181,11 +181,14 @@ static volatile int NumBuffersInUse;
static HWAVEOUT hDevice; static HWAVEOUT hDevice;
static int BufferDelay; // in milliseconds static int BufferDelay; // in milliseconds
static volatile BOOL DriverClosing = FALSE;
static volatile BOOL OutputWorking = FALSE;
static const int AllowSynchronousWaveforms = 1; static const int AllowSynchronousWaveforms = 1;
/*****************************************************************************************************************************/ /*****************************************************************************************************************************/
static void CALLBACK OnPlaybackEvent (HWAVE hWave, UINT Msg, DWORD UserData, DWORD Param1, DWORD Param2); static void CALLBACK OnPlaybackEvent (HWAVE hWave, UINT Msg, DWORD_PTR UserData, DWORD_PTR Param1, DWORD_PTR Param2);
static void BufferPoolReset (void); static void BufferPoolReset (void);
static struct MMBuffer * GetBuffer (); static struct MMBuffer * GetBuffer ();
static void PutBuffer (struct MMBuffer *); static void PutBuffer (struct MMBuffer *);
...@@ -290,6 +293,7 @@ static int open_output(void) ...@@ -290,6 +293,7 @@ static int open_output(void)
DebugPrint("Opening device...\n"); DebugPrint("Opening device...\n");
hDevice = 0; hDevice = 0;
DriverClosing = FALSE;
if (opt_wmme_device_id == -2){ if (opt_wmme_device_id == -2){
uDeviceID = WAVE_MAPPER; uDeviceID = WAVE_MAPPER;
...@@ -366,6 +370,8 @@ static void close_output(void) ...@@ -366,6 +370,8 @@ static void close_output(void)
{ {
int i; int i;
DriverClosing = TRUE;
if (dpm.fd != -1) if (dpm.fd != -1)
{ {
WaitForBuffer(1); WaitForBuffer(1);
...@@ -374,6 +380,7 @@ static void close_output(void) ...@@ -374,6 +380,7 @@ static void close_output(void)
waveOutReset(hDevice); waveOutReset(hDevice);
waveOutClose(hDevice); waveOutClose(hDevice);
hDevice = NULL;
DebugPrint("Device closed.\n"); DebugPrint("Device closed.\n");
...@@ -393,6 +400,7 @@ static void close_output(void) ...@@ -393,6 +400,7 @@ static void close_output(void)
} }
free(Buffers); free(Buffers);
Buffers = NULL;
/** Reset the file descriptor. **/ /** Reset the file descriptor. **/
...@@ -414,10 +422,11 @@ static int output_data(char * Data, int32 Size) ...@@ -414,10 +422,11 @@ static int output_data(char * Data, int32 Size)
char * d; char * d;
int32 s; int32 s;
OutputWorking = TRUE;
d = Data; d = Data;
s = Size; s = Size;
while (s > 0) while (NOT DriverClosing && s > 0)
{ {
int32 n; int32 n;
struct MMBuffer * b; struct MMBuffer * b;
...@@ -482,6 +491,7 @@ static int output_data(char * Data, int32 Size) ...@@ -482,6 +491,7 @@ static int output_data(char * Data, int32 Size)
s -= n; s -= n;
} }
OutputWorking = FALSE;
return 0; return 0;
} }
...@@ -529,7 +539,7 @@ static int acntl(int request, void *arg) ...@@ -529,7 +539,7 @@ static int acntl(int request, void *arg)
/*****************************************************************************************************************************/ /*****************************************************************************************************************************/
static void CALLBACK OnPlaybackEvent(HWAVE hWave, UINT Msg, DWORD UserData, DWORD Param1, DWORD Param2) static void CALLBACK OnPlaybackEvent(HWAVE hWave, UINT Msg, DWORD_PTR UserData, DWORD_PTR Param1, DWORD_PTR Param2)
{ {
ctl->cmsg(CMSG_INFO, VERB_DEBUG, "Msg: 0x%08X, Num. buffers in use: %d", Msg, NumBuffersInUse); ctl->cmsg(CMSG_INFO, VERB_DEBUG, "Msg: 0x%08X, Num. buffers in use: %d", Msg, NumBuffersInUse);
...@@ -724,7 +734,7 @@ static void WaitForBuffer(int WaitForAllBuffers) ...@@ -724,7 +734,7 @@ static void WaitForBuffer(int WaitForAllBuffers)
while (1) { while (1) {
EnterCriticalSection(&critSect); EnterCriticalSection(&critSect);
numbuf = NumBuffersInUse; numbuf = NumBuffersInUse;
if (numbuf) { if (numbuf || OutputWorking) {
LeaveCriticalSection(&critSect); LeaveCriticalSection(&critSect);
Sleep(BufferDelay); Sleep(BufferDelay);
continue; continue;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment