Hey,
I am new to C and I am writing a small program similar to grep. I am using some linked list structures so I don't have to have a staticly defined array. I use malloc to create each new structure. What I am wondering is, do I have to call free on each pointer when the program ends? I read that you have to call free or you will have a memory leak. But in the examples I read in some books K&R Programming C and pratical C, they don't usually call free. When my program ends will the memory be freed up? Or will more and more memory get eaten up each time I run my program? Do give you an idea of the code:
Hope this made sense.
Thanks for any help.
Later
I am new to C and I am writing a small program similar to grep. I am using some linked list structures so I don't have to have a staticly defined array. I use malloc to create each new structure. What I am wondering is, do I have to call free on each pointer when the program ends? I read that you have to call free or you will have a memory leak. But in the examples I read in some books K&R Programming C and pratical C, they don't usually call free. When my program ends will the memory be freed up? Or will more and more memory get eaten up each time I run my program? Do give you an idea of the code:
Code:
//this is a structure for our file information
struct file_info
{
char *filename;//name of the file
unsigned long matches;
// struct line_info *
struct file_info *next; //the next file
} files;
/* So I will start off with one file and with each
new file use malloc to create a pointer to a new
file_info structure and make next point to it.
*/
Hope this made sense.
Thanks for any help.
Later