Commit 2251fbc3 authored by Eric Pouech's avatar Eric Pouech Committed by Alexandre Julliard

Simplified memory allocation for asynchronous MCI message handling.

parent 15a3d774
...@@ -81,7 +81,6 @@ struct SCA { ...@@ -81,7 +81,6 @@ struct SCA {
UINT wMsg; UINT wMsg;
DWORD dwParam1; DWORD dwParam1;
DWORD dwParam2; DWORD dwParam2;
BOOL allocatedCopy;
}; };
/* EPP DWORD WINAPI mciSendCommandA(UINT wDevID, UINT wMsg, DWORD dwParam1, DWORD dwParam2); */ /* EPP DWORD WINAPI mciSendCommandA(UINT wDevID, UINT wMsg, DWORD dwParam1, DWORD dwParam2); */
...@@ -99,8 +98,6 @@ static DWORD CALLBACK MCI_SCAStarter(LPVOID arg) ...@@ -99,8 +98,6 @@ static DWORD CALLBACK MCI_SCAStarter(LPVOID arg)
ret = mciSendCommandA(sca->wDevID, sca->wMsg, sca->dwParam1 | MCI_WAIT, sca->dwParam2); ret = mciSendCommandA(sca->wDevID, sca->wMsg, sca->dwParam1 | MCI_WAIT, sca->dwParam2);
TRACE("In thread after async command (%08x,%u,%08lx,%08lx)\n", TRACE("In thread after async command (%08x,%u,%08lx,%08lx)\n",
sca->wDevID, sca->wMsg, sca->dwParam1, sca->dwParam2); sca->wDevID, sca->wMsg, sca->dwParam1, sca->dwParam2);
if (sca->allocatedCopy)
HeapFree(GetProcessHeap(), 0, (LPVOID)sca->dwParam2);
HeapFree(GetProcessHeap(), 0, sca); HeapFree(GetProcessHeap(), 0, sca);
ExitThread(ret); ExitThread(ret);
WARN("Should not happen ? what's wrong \n"); WARN("Should not happen ? what's wrong \n");
...@@ -114,7 +111,7 @@ static DWORD CALLBACK MCI_SCAStarter(LPVOID arg) ...@@ -114,7 +111,7 @@ static DWORD CALLBACK MCI_SCAStarter(LPVOID arg)
static DWORD MCI_SendCommandAsync(UINT wDevID, UINT wMsg, DWORD dwParam1, static DWORD MCI_SendCommandAsync(UINT wDevID, UINT wMsg, DWORD dwParam1,
DWORD dwParam2, UINT size) DWORD dwParam2, UINT size)
{ {
struct SCA* sca = HeapAlloc(GetProcessHeap(), 0, sizeof(struct SCA)); struct SCA* sca = HeapAlloc(GetProcessHeap(), 0, sizeof(struct SCA) + size);
if (sca == 0) if (sca == 0)
return MCIERR_OUT_OF_MEMORY; return MCIERR_OUT_OF_MEMORY;
...@@ -123,20 +120,14 @@ static DWORD MCI_SendCommandAsync(UINT wDevID, UINT wMsg, DWORD dwParam1, ...@@ -123,20 +120,14 @@ static DWORD MCI_SendCommandAsync(UINT wDevID, UINT wMsg, DWORD dwParam1,
sca->wMsg = wMsg; sca->wMsg = wMsg;
sca->dwParam1 = dwParam1; sca->dwParam1 = dwParam1;
if (size) { if (size && dwParam2) {
sca->dwParam2 = (DWORD)HeapAlloc(GetProcessHeap(), 0, size); sca->dwParam2 = (DWORD)sca + sizeof(struct SCA);
if (sca->dwParam2 == 0) {
HeapFree(GetProcessHeap(), 0, sca);
return MCIERR_OUT_OF_MEMORY;
}
sca->allocatedCopy = TRUE;
/* copy structure passed by program in dwParam2 to be sure /* copy structure passed by program in dwParam2 to be sure
* we can still use it whatever the program does * we can still use it whatever the program does
*/ */
memcpy((LPVOID)sca->dwParam2, (LPVOID)dwParam2, size); memcpy((LPVOID)sca->dwParam2, (LPVOID)dwParam2, size);
} else { } else {
sca->dwParam2 = dwParam2; sca->dwParam2 = dwParam2;
sca->allocatedCopy = FALSE;
} }
if (CreateThread(NULL, 0, MCI_SCAStarter, sca, 0, NULL) == 0) { if (CreateThread(NULL, 0, MCI_SCAStarter, sca, 0, NULL) == 0) {
...@@ -403,7 +394,7 @@ static DWORD MIDI_mciReadMTrk(WINE_MCIMIDI* wmm, MCI_MIDITRACK* mmt) ...@@ -403,7 +394,7 @@ static DWORD MIDI_mciReadMTrk(WINE_MCIMIDI* wmm, MCI_MIDITRACK* mmt)
} }
break; break;
case 0x03: case 0x03:
if (wmm->lpstrCopyright) { if (wmm->lpstrName) {
WARN("Two names (%s|%s)\n", wmm->lpstrName, buf); WARN("Two names (%s|%s)\n", wmm->lpstrName, buf);
} else { } else {
wmm->lpstrName = HeapAlloc( GetProcessHeap(), 0, strlen(buf)+1 ); wmm->lpstrName = HeapAlloc( GetProcessHeap(), 0, strlen(buf)+1 );
......
...@@ -53,7 +53,6 @@ struct SCA { ...@@ -53,7 +53,6 @@ struct SCA {
UINT wMsg; UINT wMsg;
DWORD dwParam1; DWORD dwParam1;
DWORD dwParam2; DWORD dwParam2;
BOOL allocatedCopy;
}; };
/************************************************************************** /**************************************************************************
...@@ -69,8 +68,6 @@ static DWORD CALLBACK MCI_SCAStarter(LPVOID arg) ...@@ -69,8 +68,6 @@ static DWORD CALLBACK MCI_SCAStarter(LPVOID arg)
ret = mciSendCommandA(sca->wDevID, sca->wMsg, sca->dwParam1 | MCI_WAIT, sca->dwParam2); ret = mciSendCommandA(sca->wDevID, sca->wMsg, sca->dwParam1 | MCI_WAIT, sca->dwParam2);
TRACE("In thread after async command (%08x,%u,%08lx,%08lx)\n", TRACE("In thread after async command (%08x,%u,%08lx,%08lx)\n",
sca->wDevID, sca->wMsg, sca->dwParam1, sca->dwParam2); sca->wDevID, sca->wMsg, sca->dwParam1, sca->dwParam2);
if (sca->allocatedCopy)
HeapFree(GetProcessHeap(), 0, (LPVOID)sca->dwParam2);
HeapFree(GetProcessHeap(), 0, sca); HeapFree(GetProcessHeap(), 0, sca);
ExitThread(ret); ExitThread(ret);
WARN("Should not happen ? what's wrong \n"); WARN("Should not happen ? what's wrong \n");
...@@ -84,7 +81,7 @@ static DWORD CALLBACK MCI_SCAStarter(LPVOID arg) ...@@ -84,7 +81,7 @@ static DWORD CALLBACK MCI_SCAStarter(LPVOID arg)
static DWORD MCI_SendCommandAsync(UINT wDevID, UINT wMsg, DWORD dwParam1, static DWORD MCI_SendCommandAsync(UINT wDevID, UINT wMsg, DWORD dwParam1,
DWORD dwParam2, UINT size) DWORD dwParam2, UINT size)
{ {
struct SCA* sca = HeapAlloc(GetProcessHeap(), 0, sizeof(struct SCA)); struct SCA* sca = HeapAlloc(GetProcessHeap(), 0, sizeof(struct SCA) + size);
if (sca == 0) if (sca == 0)
return MCIERR_OUT_OF_MEMORY; return MCIERR_OUT_OF_MEMORY;
...@@ -93,20 +90,14 @@ static DWORD MCI_SendCommandAsync(UINT wDevID, UINT wMsg, DWORD dwParam1, ...@@ -93,20 +90,14 @@ static DWORD MCI_SendCommandAsync(UINT wDevID, UINT wMsg, DWORD dwParam1,
sca->wMsg = wMsg; sca->wMsg = wMsg;
sca->dwParam1 = dwParam1; sca->dwParam1 = dwParam1;
if (size) { if (size && dwParam2) {
sca->dwParam2 = (DWORD)HeapAlloc(GetProcessHeap(), 0, size); sca->dwParam2 = (DWORD)sca + sizeof(struct SCA);
if (sca->dwParam2 == 0) {
HeapFree(GetProcessHeap(), 0, sca);
return MCIERR_OUT_OF_MEMORY;
}
sca->allocatedCopy = TRUE;
/* copy structure passed by program in dwParam2 to be sure /* copy structure passed by program in dwParam2 to be sure
* we can still use it whatever the program does * we can still use it whatever the program does
*/ */
memcpy((LPVOID)sca->dwParam2, (LPVOID)dwParam2, size); memcpy((LPVOID)sca->dwParam2, (LPVOID)dwParam2, size);
} else { } else {
sca->dwParam2 = dwParam2; sca->dwParam2 = dwParam2;
sca->allocatedCopy = FALSE;
} }
if (CreateThread(NULL, 0, MCI_SCAStarter, sca, 0, NULL) == 0) { if (CreateThread(NULL, 0, MCI_SCAStarter, sca, 0, NULL) == 0) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment