LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   malloc_consolidate (http://www.linuxquestions.org/questions/linux-general-1/malloc_consolidate-757663/)

mannoj 09-25-2009 03:12 AM

malloc_consolidate
 
Hi,
I am using Slackware 12.0.
I am facing the problem at the time of deallocating the memory.
When I am using the free/delete as per calloc/new. I am using the same function more than once.
I did the debug process. I watched all variables, every thing is allright but why it crashes in malloc_consolidate()after perticular numbers of iterations?

Please,if any one faced same problem and that was sovled successfully, then suggest me way to come out of this problem.

Thank you,

lutusp 09-25-2009 04:35 AM

Quote:

Originally Posted by mannoj (Post 3696472)
Hi,
I am using Slackware 12.0.
I am facing the problem at the time of deallocating the memory.
When I am using the free/delete as per calloc/new. I am using the same function more than once.
I did the debug process. I watched all variables, every thing is allright but why it crashes in malloc_consolidate()after perticular numbers of iterations?

Please,if any one faced same problem and that was sovled successfully, then suggest me way to come out of this problem.

Thank you,

Chances are there is something wrong with your code. I would be more specific, but you weren't more specific.

mannoj 09-29-2009 12:51 AM

Specification
 
Quote:

Originally Posted by lutusp (Post 3696537)
Chances are there is something wrong with your code. I would be more specific, but you weren't more specific.

Hi,
First of all thank you for the reply.
Please, you specify which type of more information you want.
I will post it.
Thanking you.

lutusp 09-29-2009 03:54 AM

Quote:

Originally Posted by mannoj (Post 3700138)
Hi,
First of all thank you for the reply.
Please, you specify which type of more information you want.
I will post it.
Thanking you.

I would specify what information I need, but I can't, because you haven't posted your code.

johnsfine 09-29-2009 08:52 AM

Quote:

Originally Posted by mannoj (Post 3696472)
I did the debug process. I watched all variables, every thing is allright but why it crashes in malloc_consolidate()after perticular numbers of iterations?

There are lots of possibilities. The most common one is that some part of your program wrote to memory that didn't belong to it and that memory happened to be part of the structures malloc uses to keep track of which memory is free vs. allocated. When malloc later tries to consolidate newly freed memory with previously freed memory, it runs into those corrupted data structures and crashes.

If your program is small enough to post the entire source code, I expect it is simple enough for any experienced programmer to spot the error, so post it and someone will tell you what the error is.

If it isn't small enough to post and you need to find the problem by debugging, that can be quite a challenge for a beginner. An expert would debug a build that includes debug info for malloc itself as well as debug info for the program. Then you can see which memory location in malloc's internal structures was clobbered to cause the crash. Then you can restart and make the debugger stop on every modification to that address and you can see which modification is not legitimate.

There are also tools you can use to instrument your program and/or run it under a cpu simulator rather than directly in the CPU, so it can watch for and report many cases of routines writing to memory they don't own. We (where I work) mainly investigate such issues in Windows with Purify, so I forget the names of similar tools available free in Linux.

If you just want to study your own source code looking for the bug, look for places it keeps/uses a pointer to an object that could have been deleted and for places it might write beyond the end of an array.

mjones490 09-29-2009 09:04 AM

Also, take care that that you use only free on memory that's mallocated, and delete on objects that are newed. They are not the same. If you can't escape using both types of allocators in one program, at least try to keep them in separate modules.

mannoj 09-30-2009 12:51 AM

Thank you all to giving me your precious time.

As per the suggestions, I observed the code.
I found that I was using all the allocated memory.
So, it create problem at free.
I did one thing i.e. size is increased by one.
Now, every thing is fine, working properly.


Thank you all.


All times are GMT -5. The time now is 03:14 AM.