By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,079 Members | 843 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,079 IT Pros & Developers. It's quick & easy.

Debug assertion failed

P: 1
Hi

I have an application which creates a queue, a thread is putting data in the queue using malloc and another thread is getting data from the queue and delete the memory allocated in the first thread.
When free() is called to delete the allocated memory, it crashes with:

Debug assertion failed
dbgheap.c line 1044

expression _CrtIsValidHeapPointer(pUserData)

It looks like the second thread can not free the memory allocated in the first thread. Is there any easy way to fix the problem?

Thanks

Long
Aug 27 '07 #1
Share this Question
Share on Google+
2 Replies


RRick
Expert 100+
P: 463
Threads use the same global space so I don't see any reason why the heap resource can't be released by another thread.

Have you made sure that there isn't some bug happening here? Is the address being corrupted? Do you release the resource more than once? Are you mixing malloc/new with free/delete?

Sometimes a second opinion is really helpful. Valgrind is one of the best memory checkers for linux boxes.
Aug 27 '07 #2

weaknessforcats
Expert Mod 5K+
P: 9,197
This is clearly a memory corruption bug caused by these threads manipulating the same memory.

Are the threads operating on the memory while in a critical section?? If not, there's your answer.
Aug 28 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.