Module: wine Branch: master Commit: 62bf20783cf760fd09a0c9a2562819aacb7c9a53 URL: http://source.winehq.org/git/wine.git/?a=commit;h=62bf20783cf760fd09a0c9a256...
Author: Michael Stefaniuc mstefani@winehq.org Date: Fri May 12 16:11:22 2017 +0200
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
---
dlls/dmusic/dmusic.c | 39 +++++++++++++++++++++++++++++++++++++-- dlls/dmusic/dmusic_private.h | 2 ++ dlls/dmusic/port.c | 1 + dlls/dmusic/tests/dmusic.c | 6 ++++++ 4 files changed, 46 insertions(+), 2 deletions(-)
diff --git a/dlls/dmusic/dmusic.c b/dlls/dmusic/dmusic.c index 105e6f7..4199da4 100644 --- a/dlls/dmusic/dmusic.c +++ b/dlls/dmusic/dmusic.c @@ -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); diff --git a/dlls/dmusic/dmusic_private.h b/dlls/dmusic/dmusic_private.h index 8c77715..f9839ed 100644 --- a/dlls/dmusic/dmusic_private.h +++ b/dlls/dmusic/dmusic_private.h @@ -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 */ diff --git a/dlls/dmusic/port.c b/dlls/dmusic/port.c index f2f7599..5064615 100644 --- a/dlls/dmusic/port.c +++ b/dlls/dmusic/port.c @@ -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); diff --git a/dlls/dmusic/tests/dmusic.c b/dlls/dmusic/tests/dmusic.c index f65dc7e..288a741 100644 --- a/dlls/dmusic/tests/dmusic.c +++ b/dlls/dmusic/tests/dmusic.c @@ -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);