I'm using this two MACROS

;----------------------------------------------
;INITGROWABLHEAP
INITGROWABLEHEAP MACRO hHEAP,pHEAPMEM
invoke HeapCreate,HEAP_NO_SERIALIZE or HEAP_GENERATE_EXCEPTIONS,0,0
mov hHEAP,eax
invoke HeapAlloc,hHEAP,HEAP_NO_SERIALIZE or HEAP_ZERO_MEMORY or HEAP_GENERATE_EXCEPTIONS,0
mov pHEAPMEM,eax
ENDM
;----------------------------------------------
;DEINITGROWABLEHEAP
DEINITGROWABLEHEAP MACRO hHEAP,pHEAPMEM
invoke HeapFree,hHEAP,HEAP_NO_SERIALIZE,pHEAPMEM
invoke HeapDestroy,hHEAP
ENDM
;----------------------------------------------



Here is my code.

INITGROWABLEHEAP hHeapTest,pHeapTest
mov edx,pHeapTest
mov byte ptr ,'t'
DEINITGROWABLEHEAP hHeapTest,pHeapTest

When i'm checking my prog using MemProof
Invalid Address specified to RtlFreeHeap is appearing in "Debug Window"
Posted on 2003-10-03 15:33:30 by AceEmbler
Perhaps you could do something like this... please try it and tell me if it works. :)


;----------------------------------------------
;INITGROWABLEHEAP
INITGROWABLEHEAP MACRO hHEAP,pHEAPMEM
invoke HeapCreate,HEAP_NO_SERIALIZE or HEAP_GENERATE_EXCEPTIONS,0,0
mov &hHEAP&,eax
invoke HeapAlloc,eax,HEAP_NO_SERIALIZE or HEAP_ZERO_MEMORY or HEAP_GENERATE_EXCEPTIONS,0
mov &pHEAPMEM&,eax
ENDM
;----------------------------------------------
;DEINITGROWABLEHEAP
DEINITGROWABLEHEAP MACRO hHEAP,pHEAPMEM
mov eax,&hHEAP&
push eax
invoke HeapFree,eax,HEAP_NO_SERIALIZE,&pHEAPMEM&
call HeapDestroy
ENDM
;----------------------------------------------
Posted on 2003-10-03 15:38:49 by QvasiModo
i would zero int that heap..

i did test it and it did work... so im not sure whats wronge with your program..

HeapFree

Return Values

If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. An application can call GetLastError for extended error information.

my program returned a 1 meaning it worked right..
Posted on 2003-10-03 15:41:09 by devilsclaw

Perhaps you could do something like this... please try it and tell me if it works. :)


;----------------------------------------------
;INITGROWABLEHEAP
INITGROWABLEHEAP MACRO hHEAP,pHEAPMEM
invoke HeapCreate,HEAP_NO_SERIALIZE or HEAP_GENERATE_EXCEPTIONS,0,0
mov &hHEAP&,eax
invoke HeapAlloc,eax,HEAP_NO_SERIALIZE or HEAP_ZERO_MEMORY or HEAP_GENERATE_EXCEPTIONS,0
mov &pHEAPMEM&,eax
ENDM
;----------------------------------------------
;DEINITGROWABLEHEAP
DEINITGROWABLEHEAP MACRO hHEAP,pHEAPMEM
mov eax,&hHEAP&
push eax
invoke HeapFree,eax,HEAP_NO_SERIALIZE,&pHEAPMEM&
call HeapDestroy
ENDM
;----------------------------------------------



its the same as before.



i know that HeapFree is returning nonzero value, but sometimes my APP just crashs whille HeapFree. And of course the error in MemProof is appearing as allways. :tongue:
Posted on 2003-10-04 12:10:25 by AceEmbler
K here is the app. Try it and tell me if it crashes.
Posted on 2003-10-04 14:13:09 by AceEmbler
It smells like a buffer overflow somewhere... Writing past the end of the allocated space in heap allocated memory does strange things (like an app crashing only when being debugged).
I tried it under ME, and it seems to work fine, even under a debugger. Have you managed to reproduce the crash somehow, or does it just seem to be random?
Posted on 2003-10-06 13:17:07 by QvasiModo
since the \Res\slownie.rc is not included i dont know if this is a valid point but im working on XP Pro and it seems to bomb trying to run

invoke DialogBoxParam,hInstance,IDD_DIALOG1,NULL,addr DlgProc,NULL

i even tryed to int 3 right before it checks the windows massages and still nothing..
Posted on 2003-10-06 13:35:34 by devilsclaw
it seems if i switch the program you compiled to windows 98 compatible mode it works.. but i still cant compile working program with out the rc file
Posted on 2003-10-06 13:47:27 by devilsclaw
Slownie.rc contains

#include <Res\SlownieDlg.rc> ;<===== this line :tongue:


I have changed macros a litle and now there are looking like this.



;----------------------------------------------
;INITGROWABLHEAP
INITGROWABLEHEAP MACRO hHEAP,pHEAPMEM
invoke HeapCreate,0,0,0
mov hHEAP,eax
invoke HeapAlloc,hHEAP,HEAP_ZERO_MEMORY,0
mov pHEAPMEM,eax
ENDM
;----------------------------------------------
;DEINITGROWABLEHEAP
DEINITGROWABLEHEAP MACRO hHEAP,pHEAPMEM
invoke HeapFree,hHEAP,0,pHEAPMEM
invoke HeapDestroy,hHEAP
ENDM
;----------------------------------------------



Probably there were some problems with HEAP_NO_SERIALIZE flag so now the HeapFree return nonzero value. But MemProof shows me unfreed resources and HeapFree Unknown Win32 error. I'm attaching the source + *.rc file :tongue: (you have to push button to make heap)
Posted on 2003-10-06 15:14:03 by AceEmbler
Hi AceEmbler !
I found the bug. No problem in your calls Heap API. Bug occurred not in two macro but in the LiczbaStr function
invoke LiczbaStr,pHeapTest,0,1,1,5 ; Write exceed 46 bytes, so Heap will be corrupted
I used Rational Purify to test
Posted on 2003-10-06 23:34:20 by TQN

Hi AceEmbler !
I found the bug. No problem in your calls Heap API. Bug occurred not in two macro but in the LiczbaStr function
invoke LiczbaStr,pHeapTest,0,1,1,5 ; Write exceed 46 bytes, so Heap will be corrupted
I used Rational Purify to test



Why it will be corrupted I dont get it since it's growable heap?? dont tell me im able to write 46 bytes only.
Posted on 2003-10-07 03:56:56 by AceEmbler
Well after reading the HeapCreate api ref..
it says that if you set max size to 0 it means the heap can grow as you have done...

but thats not the problem im guessing that when it allocates the memory it places it near a memory space that does not have much room to grow since you told its projected size / initial size is 0.. if you told it a larger number you might get placed into a new location that allows you to grow more..
Posted on 2003-10-07 04:57:32 by devilsclaw
As i see growable heap is useless since i have to specify how much memory i will use.

BTW. I called HeapSize and it returned 0. But heap was used and filled with data so WTF.
Posted on 2003-10-07 06:02:58 by AceEmbler
I think "growable heap" only means that you can keep allocating blocks with HeapAlloc... NOT that you can simply write bytes to a heap. (It's not like the stack, it will grow but not automatically). Thus writing past the end of the allocated memory block corrupts the heap, that's the cause of this strange behavior.
Posted on 2003-10-07 17:18:27 by QvasiModo
That's right.

A "growable" heap grows only when you Allocate from that heap. This is possible because the growable heap is not a contiguous area of memory. Each allocated block is contiguous, but not the whole heap.

To make it grow like the stack, hardware must be provided to detect when you are storing "out of bounds". The x86 provides this via segment/selector registers. However, the OS does not give you control of this mechanism at Ring3 (the normal application privilege level). One reason why is - it would break the flat memory model completely.
Posted on 2003-10-07 20:36:47 by tenkey
AceEmbler, have you tried using Guard Pages?
Creating Guard Pages
Posted on 2003-10-07 20:51:50 by bitRAKE
thx all

I will look at the GuardPages bitRake thanks for the advice.
Posted on 2003-10-08 03:37:07 by AceEmbler