Skip to content

Commit

Permalink
dmband: Avoid leaking collection on band release.
Browse files Browse the repository at this point in the history
  • Loading branch information
rbernon authored and julliard committed Sep 19, 2023
1 parent 7fb9afe commit 9d390da
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 deletions.
40 changes: 32 additions & 8 deletions dlls/dmband/band.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,25 @@
WINE_DEFAULT_DEBUG_CHANNEL(dmband);
WINE_DECLARE_DEBUG_CHANNEL(dmfile);

struct instrument_entry
{
struct list entry;
DMUS_IO_INSTRUMENT instrument;
IDirectMusicCollection *collection;
};

static void instrument_entry_destroy(struct instrument_entry *entry)
{
if (entry->collection) IDirectMusicCollection_Release(entry->collection);
free(entry);
}

struct band
{
IDirectMusicBand IDirectMusicBand_iface;
struct dmobject dmobj;
LONG ref;
struct list Instruments;
struct list instruments;
};

static inline struct band *impl_from_IDirectMusicBand(IDirectMusicBand *iface)
Expand Down Expand Up @@ -77,7 +90,18 @@ static ULONG WINAPI band_Release(IDirectMusicBand *iface)

TRACE("(%p) ref=%ld\n", This, ref);

if (!ref) free(This);
if (!ref)
{
struct instrument_entry *entry, *next;

LIST_FOR_EACH_ENTRY_SAFE(entry, next, &This->instruments, struct instrument_entry, entry)
{
list_remove(&entry->entry);
instrument_entry_destroy(entry);
}

free(This);
}

return ref;
}
Expand Down Expand Up @@ -192,7 +216,7 @@ static HRESULT parse_instrument(struct band *This, DMUS_PRIVATE_CHUNK *pChunk,
HRESULT hr;

DMUS_IO_INSTRUMENT inst;
LPDMUS_PRIVATE_INSTRUMENT pNewInstrument;
struct instrument_entry *pNewInstrument;
IDirectMusicObject* pObject = NULL;

if (pChunk->fccID != DMUS_FOURCC_INSTRUMENT_LIST) {
Expand Down Expand Up @@ -272,8 +296,8 @@ static HRESULT parse_instrument(struct band *This, DMUS_PRIVATE_CHUNK *pChunk,
* @TODO insert pNewInstrument into This
*/
if (!(pNewInstrument = calloc(1, sizeof(*pNewInstrument)))) return E_OUTOFMEMORY;
memcpy(&pNewInstrument->pInstrument, &inst, sizeof(DMUS_IO_INSTRUMENT));
pNewInstrument->ppReferenceCollection = NULL;
memcpy(&pNewInstrument->instrument, &inst, sizeof(DMUS_IO_INSTRUMENT));
pNewInstrument->collection = NULL;
if (NULL != pObject) {
IDirectMusicCollection* pCol = NULL;
hr = IDirectMusicObject_QueryInterface (pObject, &IID_IDirectMusicCollection, (void**) &pCol);
Expand All @@ -282,10 +306,10 @@ static HRESULT parse_instrument(struct band *This, DMUS_PRIVATE_CHUNK *pChunk,
free(pNewInstrument);
return hr;
}
pNewInstrument->ppReferenceCollection = pCol;
pNewInstrument->collection = pCol;
IDirectMusicObject_Release(pObject);
}
list_add_tail (&This->Instruments, &pNewInstrument->entry);
list_add_tail(&This->instruments, &pNewInstrument->entry);

return S_OK;
}
Expand Down Expand Up @@ -510,7 +534,7 @@ HRESULT create_dmband(REFIID lpcGUID, void **ppobj)
dmobject_init(&obj->dmobj, &CLSID_DirectMusicBand, (IUnknown *)&obj->IDirectMusicBand_iface);
obj->dmobj.IDirectMusicObject_iface.lpVtbl = &band_object_vtbl;
obj->dmobj.IPersistStream_iface.lpVtbl = &band_persist_stream_vtbl;
list_init (&obj->Instruments);
list_init(&obj->instruments);

hr = IDirectMusicBand_QueryInterface(&obj->IDirectMusicBand_iface, lpcGUID, ppobj);
IDirectMusicBand_Release(&obj->IDirectMusicBand_iface);
Expand Down
6 changes: 0 additions & 6 deletions dlls/dmband/dmband_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,6 @@ typedef struct _DMUS_PRIVATE_BAND_ITEM_HEADER {
MUSIC_TIME lBandTimePhysical;
} DMUS_PRIVATE_BAND_ITEM_HEADER;

typedef struct _DMUS_PRIVATE_INSTRUMENT {
struct list entry; /* for listing elements */
DMUS_IO_INSTRUMENT pInstrument;
IDirectMusicCollection* ppReferenceCollection;
} DMUS_PRIVATE_INSTRUMENT, *LPDMUS_PRIVATE_INSTRUMENT;

/*****************************************************************************
* Misc.
*/
Expand Down

0 comments on commit 9d390da

Please sign in to comment.