We got a 2D allocation as follows:
char** arr;
short i = 0;
arr = malloc(sizeof(char*)*10);
for( ; i<10; i++)
{
arr[i] = malloc(sizeof(char)*100);
}
which allocates arr[10][100];
Then we need to free it like so:
for(i=0; i<sizeof(arr); i++) free(arr[i]);
free(arr);
So i was thinking to make a function that saves time, space and confusion and i have this:
void pfree(void** data)
{
int i;
for(i=0; i<sizeof(data); i++)
{
free(data[i]);
}
}
Is the function relevant, if not is there another way?