anyone know whi memproof is telling me that GlobalFree Fail ? I've checked, when i call GlobalFree i use the same handle returned from GlobalAlloc, but GlobalFree fail...
Posted on 2003-09-19 12:29:25 by Bit7
Using only the info you provided, it is hard to figure out where the bug is... :grin:
Try explaining a little more, or posting some code.
A few general suggestions:
- Check that the handle is stored in a global variable (NOT in a LOCAL), and it is not overwritten somehow.
- Run your app with a debugger, and see what error code GetLastError returns.
- If the object is moveable, you should try unlocking it before freeing.
Posted on 2003-09-19 17:02:47 by QvasiModo
thx quasimodo,

ok, i've now additional information:
i do

call GlobalAlloc, GMEM_FIXED,
where size is still 139DA8h

after the execution of this line the debugger say:

int3 Command at ntdll Dbg breakpoint
Posted on 2003-09-19 17:32:08 by Bit7
You do not pass the size to global free you pass the return value of the globalalloc function.

call GlobalAlloc, GMEM_FIXED, Posted on 2003-09-19 17:43:01 by donkey
sorry donkey, what i've reported before is wrong, i know, as always i pass the handle, not the size.


but always i fall in int3
Posted on 2003-09-20 01:11:24 by Bit7
found it!!!

as alway, the error is frome the coder !
After allocating space, i wase readin a file into that space, than i was decripting and display, an than do the GlobalFree. Skipping the decription function the problem disappeared. In my decription function i was reading a byte more than the maximun size allocated. Changed the jle with jl solved my trouble ! thanks all.
Posted on 2003-09-20 01:40:10 by Bit7
invoke GlobalAlloc ,GMEM_MOVEABLE or GMEM_ZEROINIT,bytes2write
mov hbuff2,eax
or eax,eax
jnz $+07h
call GetlastError
invoke GlobalLock,eax
mov lock2,eax ; pointer to new buffer

invoke GlobalUnlock,addr lock2
invoke GlobalFree,addr hbuff2
Posted on 2003-09-20 05:55:57 by mrgone
Use Virtual or Heap memory APIs instead of Global and Local because they are faster
Posted on 2003-09-21 01:36:20 by greenant
yes, i can use VirtualAlloc, but i need to allocate some hundred of bytes... VirtualAlloc allocate 64k memory pages, initialized to 0, probaly it is anyway faster... but it seems a waste of space..
Posted on 2003-09-21 04:17:37 by Bit7
VirtualAlloc is slower for small allocations, iirc. And it definitely wastes memory. You should use Heap* anyway, since Local/Global are deprecated, and on NT end up calling Heap* anyway.
Posted on 2003-09-21 05:35:02 by f0dder