LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 09-25-2009, 03:12 AM   #1
mannoj
LQ Newbie
 
Registered: Sep 2009
Location: India
Posts: 20

Rep: Reputation: 1
Post 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,
 
Old 09-25-2009, 04:35 AM   #2
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 101Reputation: 101
Quote:
Originally Posted by mannoj View Post
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.
 
Old 09-29-2009, 12:51 AM   #3
mannoj
LQ Newbie
 
Registered: Sep 2009
Location: India
Posts: 20

Original Poster
Rep: Reputation: 1
Smile Specification

Quote:
Originally Posted by lutusp View Post
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.
 
Old 09-29-2009, 03:54 AM   #4
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 101Reputation: 101
Quote:
Originally Posted by mannoj View Post
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.
 
Old 09-29-2009, 08:52 AM   #5
johnsfine
Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,139

Rep: Reputation: 1127Reputation: 1127Reputation: 1127Reputation: 1127Reputation: 1127Reputation: 1127Reputation: 1127Reputation: 1127Reputation: 1127
Quote:
Originally Posted by mannoj View Post
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.

Last edited by johnsfine; 09-29-2009 at 08:55 AM.
 
Old 09-29-2009, 09:04 AM   #6
mjones490
Member
 
Registered: Sep 2005
Distribution: LFS
Posts: 60

Rep: Reputation: 22
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.
 
Old 09-30-2009, 12:51 AM   #7
mannoj
LQ Newbie
 
Registered: Sep 2009
Location: India
Posts: 20

Original Poster
Rep: Reputation: 1
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.
 
  


Reply

Tags
delete, free


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
segfault in malloc_consolidate ?? zaichik Programming 3 09-13-2005 05:00 PM


All times are GMT -5. The time now is 02:41 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration