I have a weird problem. Each time I run my program, sometimes it runs successfully, but sometimes it crashes, with the error message:
"cppProject(4255,0x7fff730ef300) malloc: *** error for object 0x1003008c8: incorrect checksum for freed object - object was probably modified after being freed."
I think each time I run (re-compile and re-run) the program, it should yield the same results, either correct or incorrect, but it should be consistent. Why different run returns different results? (I run the program 10 times for example, then maybe 2 times it will return the error).
Some more details:
I am using Eigen library for some matrix manipulation. Since I am trying to write code as generic as possible, I use dynamic matrix allocation, something like MatrixXd matA(A.cols(), A.rows());. If I use static allocation, like Matrix3d matA(3,3);, then there's problem.
Somewhere in your program you are handling dynamic memory incorrectly. Sometimes your program is lucky and acquires a portion of memory that allows it to be successful, but other times it acquires a portion of memory that leads to failure. Is your code small enough to share?
I am not handling any of dynamic allocation, I am simply using Eigen library, which involves some dynamic matrix manipulation. It's a rather complex library so I really have no idea to debug the library.
Below are some snippet of my code, but as I said, the main algorithm is implemented by Eigen, not myself.
x[k+1] on line 23 goes out of bounds when k is x.size()-1
You should add a restraint checking that k<u.size() on line 21, unless you always know that u and x are always the same length.