Skip to content

Commit

Permalink
dmband: Avoid leaking bands on band track 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 696e8c1 commit 7fb9afe
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 16 deletions.
45 changes: 35 additions & 10 deletions dlls/dmband/bandtrack.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,26 @@
WINE_DEFAULT_DEBUG_CHANNEL(dmband);
WINE_DECLARE_DEBUG_CHANNEL(dmfile);

struct band_entry
{
struct list entry;
DMUS_PRIVATE_BAND_ITEM_HEADER head;
IDirectMusicBand *band;
};

static void band_entry_destroy(struct band_entry *entry)
{
IDirectMusicTrack_Release(entry->band);
free(entry);
}

struct band_track
{
IDirectMusicTrack8 IDirectMusicTrack8_iface;
struct dmobject dmobj; /* IPersistStream only */
LONG ref;
DMUS_IO_BAND_TRACK_HEADER header;
struct list Bands;
struct list bands;
};

static inline struct band_track *impl_from_IDirectMusicTrack8(IDirectMusicTrack8 *iface)
Expand Down Expand Up @@ -76,7 +89,18 @@ static ULONG WINAPI band_track_Release(IDirectMusicTrack8 *iface)

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

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

LIST_FOR_EACH_ENTRY_SAFE(entry, next, &This->bands, struct band_entry, entry)
{
list_remove(&entry->entry);
band_entry_destroy(entry);
}

free(This);
}

return ref;
}
Expand Down Expand Up @@ -337,13 +361,14 @@ static HRESULT load_band(struct band_track *This, IStream *pClonedStream,
/*
* @TODO insert pBand into This
*/
if (SUCCEEDED(hr)) {
LPDMUS_PRIVATE_BAND pNewBand;
if (!(pNewBand = calloc(1, sizeof(*pNewBand)))) return E_OUTOFMEMORY;
pNewBand->BandHeader = *pHeader;
pNewBand->band = *ppBand;
IDirectMusicBand_AddRef(*ppBand);
list_add_tail (&This->Bands, &pNewBand->entry);
if (SUCCEEDED(hr))
{
struct band_entry *entry;
if (!(entry = calloc(1, sizeof(*entry)))) return E_OUTOFMEMORY;
entry->head = *pHeader;
entry->band = *ppBand;
IDirectMusicBand_AddRef(*ppBand);
list_add_tail(&This->bands, &entry->entry);
}

return S_OK;
Expand Down Expand Up @@ -635,7 +660,7 @@ HRESULT create_dmbandtrack(REFIID lpcGUID, void **ppobj)
track->ref = 1;
dmobject_init(&track->dmobj, &CLSID_DirectMusicBandTrack, (IUnknown *)&track->IDirectMusicTrack8_iface);
track->dmobj.IPersistStream_iface.lpVtbl = &band_track_persist_stream_vtbl;
list_init (&track->Bands);
list_init(&track->bands);

hr = IDirectMusicTrack8_QueryInterface(&track->IDirectMusicTrack8_iface, lpcGUID, ppobj);
IDirectMusicTrack8_Release(&track->IDirectMusicTrack8_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 @@ -67,12 +67,6 @@ typedef struct _DMUS_PRIVATE_INSTRUMENT {
IDirectMusicCollection* ppReferenceCollection;
} DMUS_PRIVATE_INSTRUMENT, *LPDMUS_PRIVATE_INSTRUMENT;

typedef struct _DMUS_PRIVATE_BAND {
struct list entry; /* for listing elements */
DMUS_PRIVATE_BAND_ITEM_HEADER BandHeader;
IDirectMusicBand *band;
} DMUS_PRIVATE_BAND, *LPDMUS_PRIVATE_BAND;

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

0 comments on commit 7fb9afe

Please sign in to comment.