Behavior of realloc vs. HeapReAlloc

Paul Chitescu paulc at voip.null.ro
Sun Aug 23 07:51:22 CDT 2009


Hi!

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?

Paul Chitescu



More information about the wine-devel mailing list