Linux - GeneralThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.