Michael Stefaniuc : dsound: Simplify error handling when creating a sound buffer.
Module: wine Branch: master Commit: d51d55bab8995f94dcc78ce8418a4149836c27b0 URL: http://source.winehq.org/git/wine.git/?a=commit;h=d51d55bab8995f94dcc78ce841... Author: Michael Stefaniuc <mstefani(a)redhat.de> Date: Tue Dec 22 10:49:10 2015 +0100 dsound: Simplify error handling when creating a sound buffer. Signed-off-by: Michael Stefaniuc <mstefani(a)redhat.de> Signed-off-by: Alexandre Julliard <julliard(a)winehq.org> --- dlls/dsound/buffer.c | 46 ++++++++++++++++------------------------------ 1 file changed, 16 insertions(+), 30 deletions(-) diff --git a/dlls/dsound/buffer.c b/dlls/dsound/buffer.c index 5aa2834..d7717fd 100644 --- a/dlls/dsound/buffer.c +++ b/dlls/dsound/buffer.c @@ -992,29 +992,28 @@ HRESULT IDirectSoundBufferImpl_Create( LPWAVEFORMATEX wfex = dsbd->lpwfxFormat; HRESULT err = DS_OK; DWORD capf = 0; + TRACE("(%p,%p,%p)\n",device,pdsb,dsbd); + *pdsb = NULL; + if (dsbd->dwBufferBytes < DSBSIZE_MIN || dsbd->dwBufferBytes > DSBSIZE_MAX) { WARN("invalid parameter: dsbd->dwBufferBytes = %d\n", dsbd->dwBufferBytes); - *pdsb = NULL; return DSERR_INVALIDPARAM; /* FIXME: which error? */ } dsb = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*dsb)); - if (dsb == 0) { - WARN("out of memory\n"); - *pdsb = NULL; + if (!dsb) return DSERR_OUTOFMEMORY; - } TRACE("Created buffer at %p\n", dsb); - dsb->ref = 0; + dsb->ref = 1; dsb->refn = 0; dsb->ref3D = 0; dsb->refiks = 0; - dsb->numIfaces = 0; + dsb->numIfaces = 1; dsb->device = device; dsb->IDirectSoundBuffer8_iface.lpVtbl = &dsbvt; dsb->IDirectSoundNotify_iface.lpVtbl = &dsnvt; @@ -1025,9 +1024,8 @@ HRESULT IDirectSoundBufferImpl_Create( CopyMemory(&dsb->dsbd, dsbd, dsbd->dwSize); dsb->pwfx = DSOUND_CopyFormat(wfex); - if (dsb->pwfx == NULL) { - HeapFree(GetProcessHeap(),0,dsb); - *pdsb = NULL; + if (!dsb->pwfx) { + IDirectSoundBuffer8_Release(&dsb->IDirectSoundBuffer8_iface); return DSERR_OUTOFMEMORY; } @@ -1052,22 +1050,16 @@ HRESULT IDirectSoundBufferImpl_Create( /* Allocate an empty buffer */ dsb->buffer = HeapAlloc(GetProcessHeap(),0,sizeof(*(dsb->buffer))); - if (dsb->buffer == NULL) { - WARN("out of memory\n"); - HeapFree(GetProcessHeap(),0,dsb->pwfx); - HeapFree(GetProcessHeap(),0,dsb); - *pdsb = NULL; + if (!dsb->buffer) { + IDirectSoundBuffer8_Release(&dsb->IDirectSoundBuffer8_iface); return DSERR_OUTOFMEMORY; } /* Allocate system memory for buffer */ dsb->buffer->memory = HeapAlloc(GetProcessHeap(),0,dsb->buflen); - if (dsb->buffer->memory == NULL) { + if (!dsb->buffer->memory) { WARN("out of memory\n"); - HeapFree(GetProcessHeap(),0,dsb->pwfx); - HeapFree(GetProcessHeap(),0,dsb->buffer); - HeapFree(GetProcessHeap(),0,dsb); - *pdsb = NULL; + IDirectSoundBuffer8_Release(&dsb->IDirectSoundBuffer8_iface); return DSERR_OUTOFMEMORY; } @@ -1118,18 +1110,12 @@ HRESULT IDirectSoundBufferImpl_Create( /* register buffer if not primary */ if (!(dsbd->dwFlags & DSBCAPS_PRIMARYBUFFER)) { err = DirectSoundDevice_AddBuffer(device, dsb); - if (err != DS_OK) { - HeapFree(GetProcessHeap(),0,dsb->buffer->memory); - HeapFree(GetProcessHeap(),0,dsb->buffer); - RtlDeleteResource(&dsb->lock); - HeapFree(GetProcessHeap(),0,dsb->pwfx); - HeapFree(GetProcessHeap(),0,dsb); - dsb = NULL; - } + if (err == DS_OK) + *pdsb = dsb; + else + IDirectSoundBuffer8_Release(&dsb->IDirectSoundBuffer8_iface); } - IDirectSoundBuffer8_AddRef(&dsb->IDirectSoundBuffer8_iface); - *pdsb = dsb; return err; }
participants (1)
-
Alexandre Julliard