Memory management for matrices built with dynamic arrays
At first, you should give your program some structure.

Start by indenting all the lines consistently. Ideally, let a program do this automatically. Search for indenter or beautifier.

Then, define a class called Matrix, give it a proper constructor and destructor. This could already help with the memory leak.

Or if you don't like classes, at least define an allocation and a deallocation function for a matrix. But then, it's almost a class anyway.

Finally, fix the syntax errors in your code so that it compiles at least.

Make the code in main so simple to read that you can explain it to a layman. That is, no explicit memory allocation, no details, just the high level view. All the rest of the code needs to go to separate functions.