When I run my program it will occasionally crash and give me this error: "glibc detected /pathtoexecutable: free(): invalid next size (fast)"
The backtrace leads to a member function that just calls a vector's push_back function -
void Path::add(Position p) {path.push_back(p);}
I have tried googling the error and the very large majority of the problems are people allocating too little memory. But how could that be happening on an std::vector<>.push_back? What can I check for? Any help is appreciated.
You're probably doing an invalid write somewhere and trashing the control information kept by glibc for bookkeeping. Thus, when it tries to free things it detects abnormal conditions (unreasonable sizes to free).
What's worst about this kind of thing is that the problem doesn't manifest itself at the point where you made the real mistake so it can be quite hard to catch (it's quite common to be an off-by-one error).
Your best bet is to use a memory debugger. valgrind
could be a start (since you mentioned glibc). Look for "invalid write of size..." before the glibc message.
As @cniculat sayed, try valgrind.
Another tools you can try are:
assert()
, so you'll receive error message on console.malloc()
/free()
. Just link your appl with tcmalloc link version, and it can detect mist memory usage problems.STL debug support and tcmalloc can be used in regular in debug builds. This way you can work as regular, while these tools will in "background" assert you if there's an error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With