3

I wrote a code that simulates a matrix. this matrix has a pointer to pointer and actually its an array of linked list. i have two of those - one for the rows and the second for the column. each array index its the matrix row/col first place, and the list is the rest number in the rox/col.

I can send the code, but its not short.

My problem is that after im doing some actions, and im trying to delete the matrix at the end - it pop me this Failed problem. I have tryed to change my code and I found that the problem is here:

delete this->rowsArray;
this->rowsArray = newRowArray; ->here


delete this->colsArray;
this->colsArray = newColArray; ->here

rowsArray ad colsArray initilized like that:

rowsArray = new matrixNode*[lastRowPlace+1]; colsArray = new matrixNode*[lastColPlace+1];

same about newColsArray and row... I hope you would be able to give me an advice cause I really dont know what to do :(

**Just forgot to say that the problem pop just at the destructor...

Ben
  • 201
  • 1
  • 4
  • 13
  • 2
    The problem is somewhere else. Although `rowsArray` was correctly allocated, you changed your pointer somewhere in your code after creating `rowsArray`. At that point, it was no longer a valid Heap Pointer. – abelenky Dec 29 '15 at 18:54
  • Does this answer your question? [Why do I get \_CrtIsValidHeapPointer(block) and/or is\_block\_type\_valid(header->\_block\_use) assertions?](https://stackoverflow.com/questions/64418624/why-do-i-get-crtisvalidheappointerblock-and-or-is-block-type-validheader-b) – ead Oct 28 '20 at 21:36

1 Answers1

6

If you defined a pointer such as new T* [size]

you should delete it with delete[] instead of delete

永东何
  • 86
  • 1
  • 3