Fixed memory leak in mixer code.

This commit is contained in:
Robert Reif 2005-01-24 11:27:05 +00:00 committed by Alexandre Julliard
parent 9f625c5e2c
commit b0d74e6bf3
3 changed files with 19 additions and 17 deletions

View File

@ -301,6 +301,7 @@ static ULONG WINAPI IDirectSoundImpl_Release(
if (This->driver)
IDsDriver_Release(This->driver);
HeapFree(GetProcessHeap(),0,This->tmp_buffer);
RtlDeleteResource(&This->buffer_list_lock);
This->mixlock.DebugInfo->Spare[1] = 0;
DeleteCriticalSection(&This->mixlock);
@ -809,6 +810,8 @@ HRESULT WINAPI IDirectSoundImpl_Create(
pDS->primary = NULL;
pDS->speaker_config = DSSPEAKER_STEREO | (DSSPEAKER_GEOMETRY_NARROW << 16);
pDS->initialized = FALSE;
pDS->tmp_buffer = NULL;
pDS->tmp_buffer_len = 0;
/* 3D listener initial parameters */
pDS->listener = NULL;

View File

@ -95,6 +95,8 @@ struct IDirectSoundImpl
DSBUFFERDESC dsbd;
DWORD speaker_config;
BOOL initialized;
LPBYTE tmp_buffer;
DWORD tmp_buffer_len;
/* DirectSound3DListener fields */
IDirectSound3DListenerImpl* listener;

View File

@ -368,20 +368,20 @@ static void DSOUND_MixerVol(IDirectSoundBufferImpl *dsb, BYTE *buf, INT len)
}
}
static void *tmp_buffer;
static size_t tmp_buffer_len = 0;
static void *DSOUND_tmpbuffer(size_t len)
static LPBYTE DSOUND_tmpbuffer(IDirectSoundImpl *dsound, DWORD len)
{
if (len>tmp_buffer_len) {
void *new_buffer = realloc(tmp_buffer, len);
if (new_buffer) {
tmp_buffer = new_buffer;
tmp_buffer_len = len;
TRACE("(%p,%ld)\n",dsound,len);
if (len > dsound->tmp_buffer_len) {
if (dsound->tmp_buffer)
dsound->tmp_buffer = HeapReAlloc(GetProcessHeap(), 0, dsound->tmp_buffer, len);
else
dsound->tmp_buffer = HeapAlloc(GetProcessHeap(), 0, len);
dsound->tmp_buffer_len = len;
}
return new_buffer;
}
return tmp_buffer;
return dsound->tmp_buffer;
}
static DWORD DSOUND_MixInBuffer(IDirectSoundBufferImpl *dsb, DWORD writepos, DWORD fraglen)
@ -407,9 +407,7 @@ static DWORD DSOUND_MixInBuffer(IDirectSoundBufferImpl *dsb, DWORD writepos, DWO
return 0;
}
/* Been seeing segfaults in malloc() for some reason... */
TRACE("allocating buffer (size = %d)\n", len);
if ((buf = ibuf = (BYTE *) DSOUND_tmpbuffer(len)) == NULL)
if ((buf = ibuf = DSOUND_tmpbuffer(dsb->dsound, len)) == NULL)
return 0;
TRACE("MixInBuffer (%p) len = %d, dest = %ld\n", dsb, len, writepos);
@ -518,8 +516,7 @@ static void DSOUND_PhaseCancel(IDirectSoundBufferImpl *dsb, DWORD writepos, DWOR
nBlockAlign = dsb->dsound->pwfx->nBlockAlign;
len = len / nBlockAlign * nBlockAlign; /* data alignment */
TRACE("allocating buffer (size = %ld)\n", len);
if ((buf = ibuf = (BYTE *) DSOUND_tmpbuffer(len)) == NULL)
if ((buf = ibuf = DSOUND_tmpbuffer(dsb->dsound, len)) == NULL)
return;
TRACE("PhaseCancel (%p) len = %ld, dest = %ld\n", dsb, len, writepos);