-
February 2nd, 2004, 11:12 PM
#1
Problem with HeapFree
Hi,
I am allocating memory in the Heap.
pV = HeapAlloc(Mem, 0, ulSize);
I am freeing the memory using HeapFree function.
HeapFree(SesMem, 0, pV);
But the problem is when i tried to the free of the same memory again
HeapFree(SesMem, 0, pV);,
i am getting a Memory Leak. Is there a way to find that this heap has been freed already.
i.e when i try to free the heap memory that is freed already, i shold be in a able to find that this heap memory has been freed already and free should not be done now.
Thanks in Advance,
Varadha
-
February 2nd, 2004, 11:27 PM
#2
Your question is unclear. When you HeapAlloc(...) you HeapFree(...) when you are done manipulating the Heap. To call HeapFree(...) twice on a pointer allocated by HeapAlloc(...) is undefined behavior, as your freeing memory that may be allocated for other reasons. When you call HeapFree, set the pointer to null. If you double free in a debug build you will breakpoint out of RtlpValidateHeapEntry(...)
-
February 2nd, 2004, 11:29 PM
#3
also show the code your using..
-
February 3rd, 2004, 04:35 AM
#4
HI,
I have problem with the allocation of memory in heap using HeapAlloc function.
HeapAlloc function not allocating the memory.
These are the list of events that i do.
1. Pv1 = HeapAlloc(Mem, HEAP_ZERO_MEMORY , ulSize)
2. HeapFree(Mem,0,Pv1)
3. Pv2 = HeapAlloc(Mem, HEAP_ZERO_MEMORY , ulSize1)
4. HeapFree(Mem,0,Pv2)
If i follow the above steps i am not getting Pv2 allocated..i.e for Pv2 is assigned a value of 0x00000000
But if i follow the following steps
1. Pv1 = HeapAlloc(Mem, HEAP_ZERO_MEMORY , ulSize)
2. Pv2 = HeapAlloc(Mem, HEAP_ZERO_MEMORY , ulSize1)
3. HeapFree(Mem,0,Pv2)
by skipping HeapFree for Pv1, then the Pv2 is properly allocated memory in the Heap.
What may the reason behind this.
Thanks in Advance,
Varadha
-
February 3rd, 2004, 04:50 AM
#5
Mem I assume is a handle in a CreateHeap call, we need to see that and the ulsize and ulsize1 values. Break down your code into a simple console application and you will most likely find very quick your error. There is no problem with calling HeapCreate(...) and HeapAlloc(...)/HeapFree(...) etc, unless you set dwMaximumSize to be less than you are allocating, but that makes no sense in the context your describing, that one succedes when you don't Free....which brings me to memory corruption, but I can assume again your running under a debug build and if you have corruptied the heap it should raise a breakpoint...
-
February 3rd, 2004, 05:35 AM
#6
Thanks Mick,
can you suggest me the way i can find that why this error occures..
Can you suggest some tutorial to understand the heap allocation better.. is there any tool that i can you to oversome this problem
-
February 4th, 2004, 06:47 AM
#7
Hi,
When i use HeapAlloc to allocate the memory in the heap i am getting the following error.
Code:
pV = HeapAlloc(SesMem, HEAP_ZERO_MEMORY , ulSize);
Error:
First-chance exception in App.exe (NTDLL.DLL): 0xC0000005: Access Violation.
What may be the reason behind this error.
Thanks in Advance,
Varadha
-
February 4th, 2004, 06:54 AM
#8
Originally posted by Varadha
Hi,
When i use HeapAlloc to allocate the memory in the heap i am getting the following error.
Code:
pV = HeapAlloc(SesMem, HEAP_ZERO_MEMORY , ulSize);
Error:
First-chance exception in App.exe (NTDLL.DLL): 0xC0000005: Access Violation.
What may be the reason behind this error.
Thanks in Advance,
Varadha
in whatever debugger of your choice, I'll assume the VC debugger, break early on in your app, if it's a MFC app then in the initinstance for example, then hit the debug->exceptions and turn on the stop always for acess violation, run your code, and post the stack.
-
February 4th, 2004, 07:08 AM
#9
HI,
do i get the access violation error if there is no enough space in the heap for allocation.
can i know what do you mean in the words "run your code, and post the stack." in the previous post
Regards,
Varadha
-
February 4th, 2004, 08:49 AM
#10
When the following statement is executed
pV = HeapAlloc(SesMem, HEAP_ZERO_MEMORY , 81000);
I had pV as 0x00000000..i.e no memory allocated in the Heap
But when i have this as very next statement,
pV = HeapAlloc(SesMem, HEAP_ZERO_MEMORY , 1000);
i have memory allocated in the above statement.
What may be the reason behind this error
-
March 22nd, 2005, 02:46 AM
#11
Re: Problem with HeapFree
when application exit in Debug mode.
displaying error by opening free.c file
in the following line
.
.
#endif /* _WIN64 */
{
HeapFree(_crtheap, 0, pBlock);
}
}
.
.
anyone can Explain how to solve this problem
Thanks
-Renugopal
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|