How to Free Memory in C Programming
It’s not as much of an issue as it was back in the microcomputer era, but wasting memory should still be a concern for any C programmer. Though you can brace yourself for 1,024 characters of input, odds are good that your program’s users may not all be Stephen King.
In that case, you can pare down your memory requests after you make them. The extra memory can then be returned to the operating system in what’s considered common courtesy.
GIVING BACK A FEW BYTES
input = (char *)malloc(sizeof(char)*1024);
puts("Unable to allocate buffer! Oh no!");
puts("Type something long and boring:");
len = strlen(input);
puts("Unable to reallocate buffer!");