Behavior of realloc vs. HeapReAlloc

Michael Stefaniuc mstefani at redhat.com
Mon Aug 24 03:50:03 CDT 2009


Hello!

Paul Chitescu wrote:
> While trying to debug a crash in msi.dll I noticed that the local 
> msi_realloc() is implemented as a (too) thin wrapper around HeapReAlloc() and 
> differs from the expected behavior of realloc() when the old pointer or the 
> new size are zero.
> 
> The runtime realloc() works like free() if the new size is zero and it works 
> like alloc() if the old pointer is null. HeapReAlloc never allocates or 
> completely frees memory.
> 
> realloc:
> http://msdn.microsoft.com/en-us/library/xbebcx7d(VS.80).aspx
> 
> HeapReAlloc:
> http://msdn.microsoft.com/en-us/library/aa366704(VS.85).aspx
> 
> So I suggest all implementations of heap_realloc to be modified like:
> 
> if (!size) {
>     HeapFree(...)
>     return 0;
> }
> else if (!mem)
>     return HeapAlloc(...)
> else
>     return HeapReAlloc(...)
> 
> Any comments?
Well, the heap_alloc wrappers are really supposed to be "thin" wrappers.
Those are there to basically save typing and not to simulate the
behavior of malloc/realloc/free. But I don't feel too strong about the
realloc case; you'd need to convince Alexandre to accept such a patch.

bye
	michael



More information about the wine-devel mailing list