diff --git a/controls/listbox.c b/controls/listbox.c
index b6ddb38a08f82133a09ae0dd2c69535c7bbeedff..bd14a895e9a9ed2f8c0dc076bb79ed82157b2de3 100644
--- a/controls/listbox.c
+++ b/controls/listbox.c
@@ -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;
diff --git a/dlls/dsound/buffer.c b/dlls/dsound/buffer.c
index f248228ffd420c23bd40ad2e91f19c02eb1c7f1f..b68054b50764ecc524d4945e0f30582fbd1ddfdb 100644
--- a/dlls/dsound/buffer.c
+++ b/dlls/dsound/buffer.c
@@ -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. */
-	    This->dsb->notifies = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 
-	        This->dsb->notifies, howmuch * sizeof(DSBPOSITIONNOTIFY));
+	    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;
diff --git a/dlls/dsound/capture.c b/dlls/dsound/capture.c
index 3948882a9127d6fa50cd749ca9ccfc8c1d018a7b..a7a46dab6e28988a123181ea1c050d5a171dbc0c 100644
--- a/dlls/dsound/capture.c
+++ b/dlls/dsound/capture.c
@@ -757,8 +757,10 @@ DSOUND_CreateDirectSoundCaptureBuffer(
 
 	    buflen = lpcDSCBufferDesc->dwBufferBytes;
             TRACE("desired buflen=%ld, old buffer=%p\n", buflen, ipDSC->buffer);
-            newbuf = (LPBYTE)HeapReAlloc(GetProcessHeap(),0,ipDSC->buffer,buflen);
-
+	    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. */
-	This->dscb->notifies = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 
-	    This->dscb->notifies, howmuch * sizeof(DSBPOSITIONNOTIFY));
+	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 */
-                ipDSC->pwave = HeapReAlloc(GetProcessHeap(),0,ipDSC->pwave,
-                    ipDSC->nrofpwaves*sizeof(WAVEHDR));
+		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;
-                ipDSC->pwave = HeapReAlloc(GetProcessHeap(),0,ipDSC->pwave,sizeof(WAVEHDR));
+		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;
diff --git a/dlls/dsound/dsound_main.c b/dlls/dsound/dsound_main.c
index 1470a735636e7c51abced90fc3598766fc494453..67caa89be89fb0be6d899bab5d200713155b8222 100644
--- a/dlls/dsound/dsound_main.c
+++ b/dlls/dsound/dsound_main.c
@@ -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;
diff --git a/dlls/dsound/primary.c b/dlls/dsound/primary.c
index 7589f8c06ee30a0f5e50611c11d98ea332c30b5c..f6a3368fac6d4840328f675a3ee0bf9da6a4eae2 100644
--- a/dlls/dsound/primary.c
+++ b/dlls/dsound/primary.c
@@ -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 */
-		newbuf = (LPBYTE)HeapReAlloc(GetProcessHeap(),0,This->buffer,buflen);
+
+		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;
diff --git a/dlls/kernel/editline.c b/dlls/kernel/editline.c
index 0dada92e06e4aef400720bf8cf7a51ed68e1471e..88ee70bf1d6bd82cb7a6ff9965e30ee88ed809ec 100644
--- a/dlls/kernel/editline.c
+++ b/dlls/kernel/editline.c
@@ -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;
-	newline = HeapReAlloc(GetProcessHeap(), 0, ctx->line, sizeof(WCHAR) * newsize);
+
+	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;
diff --git a/dlls/kernel/global16.c b/dlls/kernel/global16.c
index a21c7c2f061b298b820244a69cb8e6d42697b783..76641e5ff7fa3ebd0fcca1233fa45932c0470fda 100644
--- a/dlls/kernel/global16.c
+++ b/dlls/kernel/global16.c
@@ -352,10 +352,16 @@ HGLOBAL16 WINAPI GlobalReAlloc16(
          * given out by GetVDMPointer32W16),
          * only try to realloc in place
          */
-        newptr = HeapReAlloc( GetProcessHeap(),
-                              (pArena->pageLockCount > 0) ? 
-                              HEAP_REALLOC_IN_PLACE_ONLY : 0, 
+
+	if (ptr)
+            newptr = HeapReAlloc( GetProcessHeap(),
+		(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)
diff --git a/dlls/kernel/resource16.c b/dlls/kernel/resource16.c
index a00a89aa87bd42e69ee8dea5f35f8b59c0c009cb..85455881ef9ca565eff99dd50accc63690d0d853 100644
--- a/dlls/kernel/resource16.c
+++ b/dlls/kernel/resource16.c
@@ -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;
diff --git a/dlls/kernel/snoop16.c b/dlls/kernel/snoop16.c
index ab27640548384785aa1c64d998797d4461117826..a15570363af2f242123258a063a7e3e84a4640dd 100644
--- a/dlls/kernel/snoop16.c
+++ b/dlls/kernel/snoop16.c
@@ -145,7 +145,12 @@ SNOOP16_RegisterDLL(NE_MODULE *pModule,LPCSTR name) {
                 }
 		dll = &((*dll)->next);
 	}
-	*dll = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, *dll, sizeof(SNOOP16_DLL)+strlen(name));
+
+	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,'\\')))
diff --git a/dlls/ole32/oleproxy.c b/dlls/ole32/oleproxy.c
index bcce77cc7090b5a272842524d6c816dad97d62e4..0739592d9a5fccabb2a4bc584333fc81572d6bcb 100644
--- a/dlls/ole32/oleproxy.c
+++ b/dlls/ole32/oleproxy.c
@@ -185,7 +185,12 @@ CFStub_Invoke(
 	}
 
 	msg->cbBuffer = ststg.cbSize.s.LowPart;
-	msg->Buffer = HeapReAlloc(GetProcessHeap(),0,msg->Buffer,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) {
diff --git a/dlls/ole32/rpc.c b/dlls/ole32/rpc.c
index fed58aabcf9e0e294b238d64e9a5cf211b8156d5..43e823a412eaee98505e9d230070f8374e43bec9 100644
--- a/dlls/ole32/rpc.c
+++ b/dlls/ole32/rpc.c
@@ -606,7 +606,12 @@ _read_one(wine_pipe *xpipe) {
 		continue;
 	    if (xreq->reqh.reqid == resph.reqid) {
 		memcpy(&(xreq->resph),&resph,sizeof(resph));
-		xreq->Buffer = HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,xreq->Buffer,xreq->resph.cbBuffer);
+
+		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;
diff --git a/dlls/rpcrt4/rpc_server.c b/dlls/rpcrt4/rpc_server.c
index e9ed5931815109317f7679162d908bdf395127e4..e9fe90225bc0a10530b384c2d8cb022e8e914c80 100644
--- a/dlls/rpcrt4/rpc_server.c
+++ b/dlls/rpcrt4/rpc_server.c
@@ -390,7 +390,11 @@ static DWORD CALLBACK RPCRT4_server_thread(LPVOID the_arg)
       cps = cps->Next;
     }
     /* make array of connections */
-    objs = HeapReAlloc(GetProcessHeap(), 0, objs, count*sizeof(HANDLE));
+    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;
diff --git a/dlls/setupapi/dirid.c b/dlls/setupapi/dirid.c
index 7728f898b07029400033eda36d9bfaa99b3722e1..63f2e86377bce2aff676d4c1c2fb657f475dd3fe 100644
--- a/dlls/setupapi/dirid.c
+++ b/dlls/setupapi/dirid.c
@@ -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;
diff --git a/dlls/setupapi/setupx_main.c b/dlls/setupapi/setupx_main.c
index fdbf6669afa7c38e99b4e26eec506df2231a8d9d..4f5b9525c3b74c9bf849d97cc2e415bf28536f8b 100644
--- a/dlls/setupapi/setupx_main.c
+++ b/dlls/setupapi/setupx_main.c
@@ -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 */
-	    res = HeapReAlloc(GetProcessHeap(), 0, res, (1+count+32)*sizeof(LPSTR));
+	    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);
diff --git a/dlls/user/message.c b/dlls/user/message.c
index 01abe4ebcf577e624cfd5b99631dae8fde6dd411..31ee8b9efc20a8072921248575175cdef14d1652 100644
--- a/dlls/user/message.c
+++ b/dlls/user/message.c
@@ -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);