Looks like you're changing line
inside the loop, so you're not free'ing the same pointer you got from malloc()
You should make a copy of the pointer for modifying in the loop and leave the original alone.
You might also want to consider doing something less horrid than allocating a potentially enormous amount of memory up front, just in case, and then using it without error checks.
(you don't check the memory was ever allocated, and your fgets always assumes you have INT_MAX bytes available even after you increment the pointer into the buffer).