dmusic: Remove the port from the ports list on the port destruction.

Signed-off-by: Michael Stefaniuc <mstefani@winehq.org>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
oldstable
Michael Stefaniuc 2017-05-12 16:11:22 +02:00 committed by Alexandre Julliard
parent bf10c558ed
commit 62bf20783c
4 changed files with 46 additions and 2 deletions

View File

@ -160,9 +160,11 @@ static HRESULT WINAPI IDirectMusic8Impl_CreatePort(LPDIRECTMUSIC8 iface, REFCLSI
}
This->num_ports++;
if (!This->ports)
This->ports = HeapAlloc(GetProcessHeap(), 0, sizeof(IDirectMusicPort *) * This->num_ports);
This->ports = HeapAlloc(GetProcessHeap(), 0,
sizeof(*This->ports) * This->num_ports);
else
This->ports = HeapReAlloc(GetProcessHeap(), 0, This->ports, sizeof(IDirectMusicPort *) * This->num_ports);
This->ports = HeapReAlloc(GetProcessHeap(), 0, This->ports,
sizeof(*This->ports) * This->num_ports);
This->ports[This->num_ports - 1] = new_port;
*port = new_port;
return S_OK;
@ -172,6 +174,39 @@ static HRESULT WINAPI IDirectMusic8Impl_CreatePort(LPDIRECTMUSIC8 iface, REFCLSI
return E_NOINTERFACE;
}
void dmusic_remove_port(IDirectMusic8Impl *dmusic, IDirectMusicPort *port)
{
BOOL found = FALSE;
int i;
TRACE("Removing port %p.\n", port);
for (i = 0; i < dmusic->num_ports; i++)
{
if (dmusic->ports[i] == port) {
found = TRUE;
break;
}
}
if (!found)
{
ERR("Port %p not found in ports array.\n", port);
return;
}
if (!--dmusic->num_ports) {
HeapFree(GetProcessHeap(), 0, dmusic->ports);
dmusic->ports = NULL;
return;
}
memmove(&dmusic->ports[i], &dmusic->ports[i + 1],
(dmusic->num_ports - i) * sizeof(*dmusic->ports));
dmusic->ports = HeapReAlloc(GetProcessHeap(), 0, dmusic->ports,
sizeof(*dmusic->ports) * dmusic->num_ports);
}
static HRESULT WINAPI IDirectMusic8Impl_EnumMasterClock(LPDIRECTMUSIC8 iface, DWORD index, LPDMUS_CLOCKINFO clock_info)
{
TRACE("(%p)->(%d, %p)\n", iface, index, clock_info);

View File

@ -229,6 +229,8 @@ static inline void DMUSIC_UnlockModule(void) { InterlockedDecrement( &DMUSIC_ref
/*****************************************************************************
* Misc.
*/
void dmusic_remove_port(IDirectMusic8Impl *dmusic, IDirectMusicPort *port) DECLSPEC_HIDDEN;
/* for simpler reading */
typedef struct _DMUS_PRIVATE_CHUNK {
FOURCC fccID; /* FOURCC ID of the chunk */

View File

@ -194,6 +194,7 @@ static ULONG WINAPI SynthPortImpl_IDirectMusicPort_Release(LPDIRECTMUSICPORT ifa
if (!ref)
{
dmusic_remove_port(This->parent, iface);
IDirectMusicSynth_Activate(This->synth, FALSE);
IDirectMusicSynth_Close(This->synth);
IDirectMusicSynth_Release(This->synth);

View File

@ -176,10 +176,16 @@ static void test_setdsound(void)
ok(hr == S_OK, "CreatePort returned: %x\n", hr);
ref = get_refcount(dsound);
ok(ref == 2, "dsound ref count got %d expected 2\n", ref);
IDirectMusicPort_AddRef(port);
ref = IDirectMusicPort_Release(port);
ok(ref == 1, "port ref count got %d expected 1\n", ref);
hr = IDirectMusicPort_Activate(port, TRUE);
ok(hr == S_OK, "Port Activate returned: %x\n", hr);
ref = get_refcount(dsound);
ok(ref == 4, "dsound ref count got %d expected 4\n", ref);
IDirectMusicPort_AddRef(port);
ref = IDirectMusicPort_Release(port);
ok(ref == 1, "port ref count got %d expected 1\n", ref);
/* Releasing dsound from dmusic */
hr = IDirectMusic_SetDirectSound(dmusic, NULL, NULL);