1

I have a function that uses two copies of a 2D array and does some mathematical operations on them, but I can free before overwriting. The code is something like this:

int **function(int **A)
{
    int **B = (int **)malloc(N*sizeof(int *));
    for(i = 0; i < N; i++)
         B[i] = (int *)malloc(M*sizeof(int));
    //the operations i need to do

   return B;
}

And in main the call is like this(A in int **):

A = function(A);

Is there a way to get rid of leaks without changing the code too much ?

smci
  • 32,567
  • 20
  • 113
  • 146

0 Answers0