I am just starting to learn about malloc'd and realloc'd arrays. Can anyone help explain to me how to properly free my following array? I have tried looking at other posts, but I have a hard time understanding memory allocation in C.
char ** result = NULL;
int numSpaces = 0;
char * p = strtok(command, " ");
/* split string and append tokens to 'result' */
while (p)
{
result = realloc (result, sizeof (char*) * ++numSpaces);
if (result == NULL)
exit (-1); /* memory allocation failed */
result[numSpaces-1] = p;
p = strtok(NULL, " ");
}