Another portion of HeapReAlloc fixes.

This commit is contained in:
Oleg Prokhorov 2003-10-14 05:24:20 +00:00 committed by Alexandre Julliard
parent 46f29944c3
commit de12a97041
15 changed files with 133 additions and 33 deletions

View File

@ -714,10 +714,17 @@ static LRESULT LISTBOX_InitStorage( HWND hwnd, LB_DESCR *descr, INT nb_items )
nb_items += LB_ARRAY_GRANULARITY - 1;
nb_items -= (nb_items % LB_ARRAY_GRANULARITY);
if (descr->items)
if (descr->items) {
nb_items += HeapSize( GetProcessHeap(), 0, descr->items ) / sizeof(*item);
if (!(item = HeapReAlloc( GetProcessHeap(), 0, descr->items,
nb_items * sizeof(LB_ITEMDATA) )))
item = HeapReAlloc( GetProcessHeap(), 0, descr->items,
nb_items * sizeof(LB_ITEMDATA));
}
else {
item = HeapAlloc( GetProcessHeap(), 0,
nb_items * sizeof(LB_ITEMDATA));
}
if (!item)
{
SEND_NOTIFICATION( hwnd, descr, LBN_ERRSPACE );
return LB_ERRSPACE;
@ -1477,8 +1484,13 @@ static LRESULT LISTBOX_InsertItem( HWND hwnd, LB_DESCR *descr, INT index,
{
/* We need to grow the array */
max_items += LB_ARRAY_GRANULARITY;
if (!(item = HeapReAlloc( GetProcessHeap(), 0, descr->items,
max_items * sizeof(LB_ITEMDATA) )))
if (descr->items)
item = HeapReAlloc( GetProcessHeap(), 0, descr->items,
max_items * sizeof(LB_ITEMDATA) );
else
item = HeapAlloc( GetProcessHeap(), 0,
max_items * sizeof(LB_ITEMDATA) );
if (!item)
{
SEND_NOTIFICATION( hwnd, descr, LBN_ERRSPACE );
return LB_ERRSPACE;

View File

@ -121,8 +121,13 @@ static HRESULT WINAPI IDirectSoundNotifyImpl_SetNotificationPositions(
} else {
/* Make an internal copy of the caller-supplied array.
* Replace the existing copy if one is already present. */
if (This->dsb->notifies)
This->dsb->notifies = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
This->dsb->notifies, howmuch * sizeof(DSBPOSITIONNOTIFY));
else
This->dsb->notifies = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
howmuch * sizeof(DSBPOSITIONNOTIFY));
if (This->dsb->notifies == NULL) {
WARN("out of memory\n");
return DSERR_OUTOFMEMORY;
@ -1163,7 +1168,12 @@ HRESULT WINAPI IDirectSoundBufferImpl_Create(
/* register buffer */
RtlAcquireResourceExclusive(&(ds->lock), TRUE);
if (!(dsbd->dwFlags & DSBCAPS_PRIMARYBUFFER)) {
IDirectSoundBufferImpl **newbuffers = (IDirectSoundBufferImpl**)HeapReAlloc(GetProcessHeap(),0,ds->buffers,sizeof(IDirectSoundBufferImpl*)*(ds->nrofbuffers+1));
IDirectSoundBufferImpl **newbuffers;
if (ds->buffers)
newbuffers = (IDirectSoundBufferImpl**)HeapReAlloc(GetProcessHeap(),0,ds->buffers,sizeof(IDirectSoundBufferImpl*)*(ds->nrofbuffers+1));
else
newbuffers = (IDirectSoundBufferImpl**)HeapAlloc(GetProcessHeap(),0,sizeof(IDirectSoundBufferImpl*)*(ds->nrofbuffers+1));
if (newbuffers) {
ds->buffers = newbuffers;
ds->buffers[ds->nrofbuffers] = dsb;

View File

@ -757,8 +757,10 @@ DSOUND_CreateDirectSoundCaptureBuffer(
buflen = lpcDSCBufferDesc->dwBufferBytes;
TRACE("desired buflen=%ld, old buffer=%p\n", buflen, ipDSC->buffer);
if (ipDSC->buffer)
newbuf = (LPBYTE)HeapReAlloc(GetProcessHeap(),0,ipDSC->buffer,buflen);
else
newbuf = (LPBYTE)HeapAlloc(GetProcessHeap(),0,buflen);
if (newbuf == NULL) {
WARN("failed to allocate capture buffer\n");
err = DSERR_OUTOFMEMORY;
@ -850,8 +852,13 @@ static HRESULT WINAPI IDirectSoundCaptureNotifyImpl_SetNotificationPositions(
} else {
/* Make an internal copy of the caller-supplied array.
* Replace the existing copy if one is already present. */
if (This->dscb->notifies)
This->dscb->notifies = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
This->dscb->notifies, howmuch * sizeof(DSBPOSITIONNOTIFY));
else
This->dscb->notifies = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
howmuch * sizeof(DSBPOSITIONNOTIFY));
if (This->dscb->notifies == NULL) {
WARN("out of memory\n");
return DSERR_OUTOFMEMORY;
@ -1336,8 +1343,12 @@ IDirectSoundCaptureBufferImpl_Start(
TRACE("nrofnotifies=%d\n", This->nrofnotifies);
/* prepare headers */
if (ipDSC->pwave)
ipDSC->pwave = HeapReAlloc(GetProcessHeap(),0,ipDSC->pwave,
ipDSC->nrofpwaves*sizeof(WAVEHDR));
else
ipDSC->pwave = HeapAlloc(GetProcessHeap(),0,
ipDSC->nrofpwaves*sizeof(WAVEHDR));
for (c = 0; c < ipDSC->nrofpwaves; c++) {
if (c == 0) {
@ -1379,7 +1390,11 @@ IDirectSoundCaptureBufferImpl_Start(
TRACE("no notifiers specified\n");
/* no notifiers specified so just create a single default header */
ipDSC->nrofpwaves = 1;
if (ipDSC->pwave)
ipDSC->pwave = HeapReAlloc(GetProcessHeap(),0,ipDSC->pwave,sizeof(WAVEHDR));
else
ipDSC->pwave = HeapAlloc(GetProcessHeap(),0,sizeof(WAVEHDR));
ipDSC->pwave[0].lpData = ipDSC->buffer;
ipDSC->pwave[0].dwBufferLength = ipDSC->buflen;
ipDSC->pwave[0].dwUser = (DWORD)ipDSC;

View File

@ -623,7 +623,12 @@ static HRESULT WINAPI IDirectSoundImpl_DuplicateSoundBuffer(
/* register buffer */
RtlAcquireResourceExclusive(&(This->lock), TRUE);
{
IDirectSoundBufferImpl **newbuffers = (IDirectSoundBufferImpl**)HeapReAlloc(GetProcessHeap(),0,This->buffers,sizeof(IDirectSoundBufferImpl**)*(This->nrofbuffers+1));
IDirectSoundBufferImpl **newbuffers;
if (This->buffers)
newbuffers = (IDirectSoundBufferImpl**)HeapReAlloc(GetProcessHeap(),0,This->buffers,sizeof(IDirectSoundBufferImpl**)*(This->nrofbuffers+1));
else
newbuffers = (IDirectSoundBufferImpl**)HeapAlloc(GetProcessHeap(),0,sizeof(IDirectSoundBufferImpl**)*(This->nrofbuffers+1));
if (newbuffers) {
This->buffers = newbuffers;
This->buffers[This->nrofbuffers] = dsb;

View File

@ -90,7 +90,12 @@ static HRESULT DSOUND_PrimaryOpen(IDirectSoundImpl *This)
buflen = ((This->wfx.nAvgBytesPerSec / 100) & ~3) * DS_HEL_FRAGS;
TRACE("desired buflen=%ld, old buffer=%p\n", buflen, This->buffer);
/* reallocate emulated primary buffer */
if (This->buffer)
newbuf = (LPBYTE)HeapReAlloc(GetProcessHeap(),0,This->buffer,buflen);
else
newbuf = (LPBYTE)HeapAlloc(GetProcessHeap(),0,buflen);
if (newbuf == NULL) {
ERR("failed to allocate primary buffer\n");
merr = DSERR_OUTOFMEMORY;

View File

@ -150,7 +150,12 @@ static BOOL WCEL_Grow(WCEL_Context* ctx, size_t len)
/* round up size to 32 byte-WCHAR boundary */
newsize = (ctx->len + len + 1 + 31) & ~31;
if (ctx->line)
newline = HeapReAlloc(GetProcessHeap(), 0, ctx->line, sizeof(WCHAR) * newsize);
else
newline = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR) * newsize);
if (!newline) return FALSE;
ctx->line = newline;
ctx->alloc = newsize;
@ -237,7 +242,8 @@ static void WCEL_SaveYank(WCEL_Context* ctx, int beg, int end)
if (len <= 0) return;
WCEL_FreeYank(ctx);
ctx->yanked = HeapReAlloc(GetProcessHeap(), 0, ctx->yanked, (len + 1) * sizeof(WCHAR));
/* After WCEL_FreeYank ctx->yanked is empty */
ctx->yanked = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR));
if (!ctx->yanked) return;
memcpy(ctx->yanked, &ctx->line[beg], len * sizeof(WCHAR));
ctx->yanked[len] = 0;

View File

@ -352,10 +352,16 @@ HGLOBAL16 WINAPI GlobalReAlloc16(
* given out by GetVDMPointer32W16),
* only try to realloc in place
*/
if (ptr)
newptr = HeapReAlloc( GetProcessHeap(),
(pArena->pageLockCount > 0) ?
HEAP_REALLOC_IN_PLACE_ONLY : 0,
(pArena->pageLockCount > 0) ? HEAP_REALLOC_IN_PLACE_ONLY : 0,
ptr, size );
else
newptr = HeapAlloc( GetProcessHeap(),
(pArena->pageLockCount > 0) ? HEAP_REALLOC_IN_PLACE_ONLY : 0,
size );
}
if (!newptr)

View File

@ -95,10 +95,15 @@ static HRSRC16 MapHRsrc32To16( NE_MODULE *pModule, HRSRC hRsrc32, WORD type )
/* If no space left, grow table */
if ( map->nUsed == map->nAlloc )
{
if ( !(newElem = (HRSRC_ELEM *)HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
map->elem,
(map->nAlloc + HRSRC_MAP_BLOCKSIZE)
* sizeof(HRSRC_ELEM) ) ))
if (map->elem)
newElem = (HRSRC_ELEM *)HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
map->elem, (map->nAlloc + HRSRC_MAP_BLOCKSIZE) * sizeof(HRSRC_ELEM) );
else
newElem = (HRSRC_ELEM *)HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
(map->nAlloc + HRSRC_MAP_BLOCKSIZE) * sizeof(HRSRC_ELEM) );
if ( !newElem )
{
ERR("Cannot grow HRSRC map\n" );
return 0;

View File

@ -145,7 +145,12 @@ SNOOP16_RegisterDLL(NE_MODULE *pModule,LPCSTR name) {
}
dll = &((*dll)->next);
}
if (*dll)
*dll = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, *dll, sizeof(SNOOP16_DLL)+strlen(name));
else
*dll = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(SNOOP16_DLL)+strlen(name));
(*dll)->next = NULL;
(*dll)->hmod = pModule->self;
if ((s=strrchr(name,'\\')))

View File

@ -185,7 +185,12 @@ CFStub_Invoke(
}
msg->cbBuffer = ststg.cbSize.s.LowPart;
if (msg->Buffer)
msg->Buffer = HeapReAlloc(GetProcessHeap(),0,msg->Buffer,ststg.cbSize.s.LowPart);
else
msg->Buffer = HeapAlloc(GetProcessHeap(),0,ststg.cbSize.s.LowPart);
seekto.s.LowPart = 0;seekto.s.HighPart = 0;
hres = IStream_Seek(pStm,seekto,SEEK_SET,&newpos);
if (hres) {

View File

@ -606,7 +606,12 @@ _read_one(wine_pipe *xpipe) {
continue;
if (xreq->reqh.reqid == resph.reqid) {
memcpy(&(xreq->resph),&resph,sizeof(resph));
if (xreq->Buffer)
xreq->Buffer = HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,xreq->Buffer,xreq->resph.cbBuffer);
else
xreq->Buffer = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,xreq->resph.cbBuffer);
hres = _xread(xhPipe,xreq->Buffer,xreq->resph.cbBuffer);
if (hres) goto end;
xreq->state = REQSTATE_RESP_GOT;

View File

@ -390,7 +390,11 @@ static DWORD CALLBACK RPCRT4_server_thread(LPVOID the_arg)
cps = cps->Next;
}
/* make array of connections */
if (objs)
objs = HeapReAlloc(GetProcessHeap(), 0, objs, count*sizeof(HANDLE));
else
objs = HeapAlloc(GetProcessHeap(), 0, count*sizeof(HANDLE));
objs[0] = m_event;
count = 1;
cps = protseqs;

View File

@ -176,8 +176,16 @@ static BOOL store_user_dirid( HINF hinf, int id, WCHAR *str )
if (nb_user_dirids >= alloc_user_dirids)
{
int new_size = max( 32, alloc_user_dirids * 2 );
struct user_dirid *new = HeapReAlloc( GetProcessHeap(), 0, user_dirids,
struct user_dirid *new;
if (user_dirids)
new = HeapReAlloc( GetProcessHeap(), 0, user_dirids,
new_size * sizeof(*new) );
else
new = HeapAlloc( GetProcessHeap(), 0,
new_size * sizeof(*new) );
if (!new) return FALSE;
user_dirids = new;
alloc_user_dirids = new_size;

View File

@ -131,7 +131,10 @@ static LPSTR *SETUPX_GetSubStrings(LPSTR start, char delimiter)
/* alloc entry for new substring in steps of 32 units and copy over */
if (count % 32 == 0)
{ /* 1 for count field + current count + 32 */
if (res)
res = HeapReAlloc(GetProcessHeap(), 0, res, (1+count+32)*sizeof(LPSTR));
else
res = HeapAlloc(GetProcessHeap(), 0, (1+count+32)*sizeof(LPSTR));
}
*(res+1+count) = HeapAlloc(GetProcessHeap(), 0, len+1);
strncpy(*(res+1+count), p, len);

View File

@ -1160,8 +1160,14 @@ static BOOL dde_add_pair(HGLOBAL chm, HGLOBAL shm)
/* now remember the pair of hMem on both sides */
if (dde_num_used == dde_num_alloc)
{
struct DDE_pair* tmp = HeapReAlloc( GetProcessHeap(), 0, dde_pairs,
struct DDE_pair* tmp;
if (dde_pairs)
tmp = HeapReAlloc( GetProcessHeap(), 0, dde_pairs,
(dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
else
tmp = HeapAlloc( GetProcessHeap(), 0,
(dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
if (!tmp)
{
LeaveCriticalSection(&dde_crst);