In my C program, I've allocated memory using this:
C Code:
  1. printf("Sorting.\nSort how many numbers? ");
  2. scanf("%ld", &n); //get input for number of numbers
  3. int *pIntArray; //declare pointer, which will point to first element
  4. pIntArray = (int *) malloc (sizeof(int) * n); //allocate enough memory for 'n' ints, and point pIntArray at the first one
I know I'm meant to free the memory once I'm done with it, but when I call free(), do I only need to call it once, using pIntArray as the argument? Or do I need to loop through pIntArray to pIntArray + n - 1 and free every one of my 'elements'? Oh and after free()ing, should I set pIntArray to NULL?
On a side note, if I don't free() the memory, creating a memory leak, when is the memory eventually returned to the pool? When the program ends? When the computer is shut down? Some other time?

cheers,
metal