LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   C++ **glibc detected** ./a.out: munmap_chunk:invalid pointer (https://www.linuxquestions.org/questions/programming-9/c-%2A%2Aglibc-detected%2A%2A-a-out-munmap_chunk-invalid-pointer-852155/)

akhand_jyoti 12-24-2010 12:29 AM

C++ **glibc detected** ./a.out: munmap_chunk:invalid pointer
 
after giving the desired output ,above mentioned error comes with backtrace and memory map.
I use fedora 12.

business_kid 12-24-2010 04:19 AM

I just copied your subject line into google and got about 3,070 hits. It seems others have had that particular crash before . . .

Snark1994 12-26-2010 07:24 AM

And we might be able to spot the problem slightly more easily if you gave us a (preferably small) sample of code which shows the problem :) and from the google hits, it seems likely that something is writing to memory it shouldn't be...

johnsfine 12-26-2010 07:49 AM

Quote:

Originally Posted by akhand_jyoti (Post 4201789)
after giving the desired output ,above mentioned error comes with backtrace and memory map.
I use fedora 12.

You should understand that this represents a bug in your program, not a bug in Fedora 12, nor in glibc, etc.

It appears that the bug is detected while the program is releasing resources after it has already produced its desired output. That doesn't mean the bug occurred at that point. Most likely the bug occurred significantly before the point at which it was detected.

Quote:

Originally Posted by business_kid (Post 4201945)
It seems others have had that particular crash before . . .

That may be misleading help, especially as it may be misinterpreted to imply a Linux or glibc bug affecting many different people. That is not the case. Instead a lot of different beginning programmers have made many different mistakes, each of which was detected by glibc during release of some resource.

Unfortunately, the OP is not likely to find his bug by searching and reading other posts about other programmers whose different bugs produced the same error message.

Quote:

Originally Posted by Snark1994 (Post 4203334)
And we might be able to spot the problem slightly more easily if you gave us a (preferably small) sample of code which shows the problem

If the code is small and the OP posts the whole thing, I'm sure the bug will be obvious to whatever experienced programmer looks at it first.

If the code is too large for the OP to post the whole thing, it is unlikely that the OP would guess the right portion to post to let us deduce the bug.

A very skilled programmer working on a much more difficult problem often can experimentally cut sections out of a program until a much smaller program shows the same symptom. That would be a good strategy if you actually thought a glibc or Linux bug was behind the symptom.

That isn't a great strategy for a beginner looking for an easy bug, because it would be far more work than finding the bug ought to be.

Quote:

it seems likely that something is writing to memory it shouldn't be...
I don't think there is any doubt of that. But that also doesn't narrow the possibilities much.

The most common and simplest bug with this symptom is writing past the end of an array allocated with malloc (or with new in C++). But after that common one, there are countless less common ones that taken together are more likely. So we can't really guess the bug without seeing it.

Snark1994 12-27-2010 06:57 AM

Quote:

If the code is small and the OP posts the whole thing, I'm sure the bug will be obvious to whatever experienced programmer looks at it first.

If the code is too large for the OP to post the whole thing, it is unlikely that the OP would guess the right portion to post to let us deduce the bug.

A very skilled programmer working on a much more difficult problem often can experimentally cut sections out of a program until a much smaller program shows the same symptom. That would be a good strategy if you actually thought a glibc or Linux bug was behind the symptom.

That isn't a great strategy for a beginner looking for an easy bug, because it would be far more work than finding the bug ought to be.
Sorry, I obviously have lost sight of what people can do when starting out... I tend to do this to find problems in my own C code, then if I can't spot what I'm doing wrong in the smallest possible code sample then I post it here. We will just have to wait on the whole code, then ;)


All times are GMT -5. The time now is 03:17 PM.