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

View File

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

View File

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