From: Andrew Eikum Subject: Re: dsound: Fix a memory leak. Message-Id: <20170622131421.GL3954@foghorn.codeweavers.com> Date: Thu, 22 Jun 2017 08:14:21 -0500 In-Reply-To: <20170621162352.7f893e6b.dmitry@baikal.ru> References: <20170621162352.7f893e6b.dmitry@baikal.ru> Signed-off-by: Andrew Eikum On Wed, Jun 21, 2017 at 04:23:52PM +0800, Dmitry Timoshkov wrote: > Signed-off-by: Dmitry Timoshkov > --- > dlls/dsound/dsound_main.c | 2 +- > dlls/dsound/dsound_private.h | 15 ++++++++++++++- > dlls/dsound/propset.c | 12 +++++------- > 3 files changed, 20 insertions(+), 9 deletions(-) > > diff --git a/dlls/dsound/dsound_main.c b/dlls/dsound/dsound_main.c > index 796fe1e526..8dd86e40ed 100644 > --- a/dlls/dsound/dsound_main.c > +++ b/dlls/dsound/dsound_main.c > @@ -89,7 +89,7 @@ CRITICAL_SECTION DSOUND_capturers_lock = { &DSOUND_capturers_lock_debug, -1, 0, > GUID DSOUND_renderer_guids[MAXWAVEDRIVERS]; > GUID DSOUND_capture_guids[MAXWAVEDRIVERS]; > > -WCHAR wine_vxd_drv[] = { 'w','i','n','e','m','m','.','v','x','d', 0 }; > +const WCHAR wine_vxd_drv[] = { 'w','i','n','e','m','m','.','v','x','d', 0 }; > > /* All default settings, you most likely don't want to touch these, see wiki on UsefulRegistryKeys */ > int ds_hel_buflen = 32768 * 2; > diff --git a/dlls/dsound/dsound_private.h b/dlls/dsound/dsound_private.h > index b15189ed2d..c045b38f4a 100644 > --- a/dlls/dsound/dsound_private.h > +++ b/dlls/dsound/dsound_private.h > @@ -31,6 +31,7 @@ > #include "uuids.h" > > #include "wine/list.h" > +#include "wine/unicode.h" > > #define DS_MAX_CHANNELS 6 > > @@ -254,7 +255,7 @@ extern struct list DSOUND_renderers DECLSPEC_HIDDEN; > extern GUID DSOUND_renderer_guids[MAXWAVEDRIVERS] DECLSPEC_HIDDEN; > extern GUID DSOUND_capture_guids[MAXWAVEDRIVERS] DECLSPEC_HIDDEN; > > -extern WCHAR wine_vxd_drv[] DECLSPEC_HIDDEN; > +extern const WCHAR wine_vxd_drv[] DECLSPEC_HIDDEN; > > void setup_dsound_options(void) DECLSPEC_HIDDEN; > > @@ -264,3 +265,15 @@ BOOL DSOUND_check_supported(IAudioClient *client, DWORD rate, > DWORD depth, WORD channels) DECLSPEC_HIDDEN; > HRESULT enumerate_mmdevices(EDataFlow flow, GUID *guids, > LPDSENUMCALLBACKW cb, void *user) DECLSPEC_HIDDEN; > + > +static inline WCHAR *strdupW( const WCHAR *str ) > +{ > + size_t size; > + WCHAR *ret; > + > + if (!str) return NULL; > + size = (strlenW( str ) + 1) * sizeof(WCHAR); > + ret = HeapAlloc( GetProcessHeap(), 0, size ); > + if (ret) memcpy( ret, str, size ); > + return ret; > +} > diff --git a/dlls/dsound/propset.c b/dlls/dsound/propset.c > index b89c45ad90..9ef4ac9fbc 100644 > --- a/dlls/dsound/propset.c > +++ b/dlls/dsound/propset.c > @@ -200,7 +200,6 @@ static HRESULT DSPROPERTY_DescriptionW( > IMMDevice *mmdevice; > IPropertyStore *ps; > PROPVARIANT pv; > - DWORD desclen; > HRESULT hr; > > TRACE("pPropData=%p,cbPropData=%d,pcbReturned=%p)\n", > @@ -248,12 +247,9 @@ static HRESULT DSPROPERTY_DescriptionW( > return hr; > } > > - desclen = lstrlenW(pv.u.pwszVal) + 1; > - /* FIXME: Still a memory leak.. */ > - ppd->Description = HeapAlloc(GetProcessHeap(), 0, desclen * sizeof(WCHAR)); > - memcpy(ppd->Description, pv.u.pwszVal, desclen * sizeof(WCHAR)); > - ppd->Module = wine_vxd_drv; > - ppd->Interface = wInterface; > + ppd->Description = strdupW(pv.u.pwszVal); > + ppd->Module = strdupW(wine_vxd_drv); > + ppd->Interface = strdupW(wInterface); > ppd->Type = DIRECTSOUNDDEVICE_TYPE_VXD; > > PropVariantClear(&pv); > @@ -463,6 +459,7 @@ static HRESULT DSPROPERTY_DescriptionA( > return hr; > if (!DSPROPERTY_descWtoA(&data, ppd)) > hr = E_OUTOFMEMORY; > + HeapFree(GetProcessHeap(), 0, data.Description); > HeapFree(GetProcessHeap(), 0, data.Module); > HeapFree(GetProcessHeap(), 0, data.Interface); > return hr; > @@ -488,6 +485,7 @@ static HRESULT DSPROPERTY_Description1( > if (FAILED(hr)) > return hr; > DSPROPERTY_descWto1(&data, ppd); > + HeapFree(GetProcessHeap(), 0, data.Description); > HeapFree(GetProcessHeap(), 0, data.Module); > HeapFree(GetProcessHeap(), 0, data.Interface); > return hr; > -- > 2.13.1 > > >