Ello all

I am currently attempting to write a program that dynamically allocates memeory according to what is in a text file.

The text file contains rows of numbers with the first row describing the size of the matrix
eg
2 3
1 2 3
2 1 3
4 5 5


after much hair pulling and fustration I am sure that it is in the memory allocation/deallocation that I am having difficulties with.

I have attached my code for these two functions which are part of a larger program. The first function opens the file and calls the memory allocation function
the next function then populates the 2d array
the next function then calcculates the required calculations on the array
the next function the displays the results
the next functuion then frees the memory

Code:
/*--------------------------------------------------------*
 * Function to free the memory*/

int FreeArray2d(int rowSize, int colSize)

{
    int **array2d;

    /*free the memory row space */
    for (int index=0; index <rowSize; index++)
        {
            free (array2d[index]);
            array2d[index] = NULL;
	}

    /*free the memory column space */
    for (int index=0; index <colSize; index++)
	{
	    free (array2d[index]);
	    array2d[index] = NULL;
	}

    /*free allocated memory*/
    free (array2d);
    array2d = NULL;

    return 0;
}
/*--------------------------------------------------------*/
/*Function to allocte memory*/

int AllocateMemory(int **array2d, int rowSize, int colSize)
{ 

    {    /*Allocate the memory for the rows of the array*/
	 /*Used malloc, as calloc wouldn't work in the same way*/
         array2d = malloc (rowSize *  sizeof(int *));
	
        /*Check that memory was allocated*/
        if (rowSize !=0 && array2d != NULL)
            {
                for (int index = 0; index < rowSize; index++)
	            {
		        array2d[index] = malloc (colSize *  sizeof(int));
		    }
	    }

        else
            {
	        fprintf(stderr, "Cannot allocate memory of size %d by %d.\n", rowSize, colSize);
            }

        return  **array2d;
	 
    }
}
Can someone have a look at the two functions above. I know that i should be using calloc instead of malloc cause it zeros the memory first.