I got a problem with the HeapFree api..

I want to alloc memory using HeapAlloc

Invoke GetProcessHeap
Invoke HeapAlloc, eax, HEAP_ZERO_MEMORY, 1000h
mov dword ptr , eax

then I free, normally with:
Invoke GetProcessHeap
Invoke HeapFree, eax, 0, dword ptr

The problem is: this works fine under Win9x, but on Win2k it will crash when doing HeapFree...I've noticed that I can free the memory allocated with HeapAlloc with VirtualFree, but still I want to use HeapFree.
While looking at the HeapFree api in win2k I've noticed it looks quite different from the Win9x versions and it contains useless code lines like: inc esp/ dec esp. Maybe I have a corrupted Kernel?
Posted on 2002-12-18 17:07:51 by DZA
Its got me... our destroy function in our OOP framework has:
DESTROY MACRO pName

mov eax, pName
push eax
call dword ptr [eax]

push eax
invoke GetProcessHeap
invoke HeapFree, eax, NULL, pName
pop eax
ENDM


And no one ever complained about it. And its been tested on all platforms... at least i believe it has (been a while now ;)

Does this work on your machine.. ( a little example program i wote a while ago, with heap objects (alloc, and free's) ).

:nAn:
Posted on 2002-12-18 17:23:38 by NaN
Make sure the address in base is the address that was allocated. Also make sure you aren't trying to free up the same memory twice.

Also make sure you are saving and restoring the registers properly. If you haven't done so, add USE EBX,ESI,EDI in your PROC line. And don't expect ECX or EDX to stay unchanged over an API call. NT subsystems use more registers in 32-bit mode than 9x subsystems, so proper register saving is important.
Posted on 2002-12-18 21:55:59 by tenkey
Nan: test.exe on my Win2k : The instruction at "0x004016ca" referenced memory at "0x00000000". The memory could not be "read".
Again, I think something is wrong with my Win2k..maybe I should must reinstall
tenkey: thanks, but I was already aware of all that you said
Posted on 2002-12-19 05:22:38 by DZA
Nan:it worx now..I didnt extracted openme.txt the first time:)
Posted on 2002-12-19 05:26:43 by DZA