Commit d51d55ba authored by Michael Stefaniuc's avatar Michael Stefaniuc Committed by Alexandre Julliard

dsound: Simplify error handling when creating a sound buffer.

parent 7eec8cb4
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment