[PATCH] dmusic: Use the new global HeapReAlloc wrappers in CreatePort()
Michael Stefaniuc
mstefani at winehq.org
Sun Jan 21 15:38:35 CST 2018
Signed-off-by: Michael Stefaniuc <mstefani at winehq.org>
---
Actually I remembered one of my dmusic patches where the new
heap_realloc() semantics (alloc for NULL ptr and free for 0 size) could
have come in handy.
Also I used there the "nofail" approach aka did not check for memory
failure as the alloc size it at most a handful of (void*) sizes.
That are also tests that exercise those code paths.
Of course I could have added a heap_reallocarray() too, but don't want
to start with the scope creep already...
dlls/dmusic/dmusic.c | 21 +++++----------------
dlls/dmusic/dmusic_private.h | 1 +
2 files changed, 6 insertions(+), 16 deletions(-)
diff --git a/dlls/dmusic/dmusic.c b/dlls/dmusic/dmusic.c
index 58dcd9d952..eb3bc71af2 100644
--- a/dlls/dmusic/dmusic.c
+++ b/dlls/dmusic/dmusic.c
@@ -159,12 +159,7 @@ static HRESULT WINAPI IDirectMusic8Impl_CreatePort(LPDIRECTMUSIC8 iface, REFCLSI
return hr;
}
This->num_ports++;
- if (!This->ports)
- This->ports = HeapAlloc(GetProcessHeap(), 0,
- sizeof(*This->ports) * This->num_ports);
- else
- This->ports = HeapReAlloc(GetProcessHeap(), 0, This->ports,
- sizeof(*This->ports) * This->num_ports);
+ This->ports = heap_realloc_nofail(This->ports, sizeof(*This->ports) * This->num_ports);
This->ports[This->num_ports - 1] = new_port;
*port = new_port;
return S_OK;
@@ -195,16 +190,10 @@ void dmusic_remove_port(IDirectMusic8Impl *dmusic, IDirectMusicPort *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);
+ if (--dmusic->num_ports)
+ memmove(&dmusic->ports[i], &dmusic->ports[i + 1],
+ (dmusic->num_ports - i) * sizeof(*dmusic->ports));
+ dmusic->ports = heap_realloc_nofail(dmusic->ports, sizeof(*dmusic->ports) * dmusic->num_ports);
}
static HRESULT WINAPI IDirectMusic8Impl_EnumMasterClock(LPDIRECTMUSIC8 iface, DWORD index, LPDMUS_CLOCKINFO clock_info)
diff --git a/dlls/dmusic/dmusic_private.h b/dlls/dmusic/dmusic_private.h
index f9839edfda..f948099bbd 100644
--- a/dlls/dmusic/dmusic_private.h
+++ b/dlls/dmusic/dmusic_private.h
@@ -35,6 +35,7 @@
#include "winuser.h"
#include "wine/debug.h"
+#include "wine/heap.h"
#include "wine/list.h"
#include "wine/unicode.h"
#include "winreg.h"
--
2.14.3
More information about the wine-devel
mailing list