Dmitry Timoshkov : dsound: Fix a memory leak.

Alexandre Julliard julliard at winehq.org
Thu Jun 22 16:50:52 CDT 2017


Module: wine
Branch: master
Commit: c39121fc97a0f8441ef0a9fb8e4103631574c504
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=c39121fc97a0f8441ef0a9fb8e4103631574c504

Author: Dmitry Timoshkov <dmitry at baikal.ru>
Date:   Wed Jun 21 16:23:52 2017 +0800

dsound: Fix a memory leak.

Signed-off-by: Dmitry Timoshkov <dmitry at baikal.ru>
Signed-off-by: Andrew Eikum <aeikum at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 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 796fe1e..8dd86e4 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 b15189e..c045b38 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 b89c45a..9ef4ac9 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;




More information about the wine-cvs mailing list