I get 4 still reachable blocks and I have no idea why. It seems I free everything I have allocated. But, it still shows me 4 reachable blocks when I run valgrind.
I am trying to discover if I have freed allocated stuff in the right way.
Here is my code:
struct builtin *table[CMDNUM];
void freeBuiltinsTable(){
int i = 0;
for(i = 0; i < CMDNUM; i++){
free(table[i]);
}
}
void initializeBuiltins(){
table[0] = calloc(1, sizeof(struct builtin));
table[0]->name = "exit";
table[0]->f = my_exit;
table[1] = calloc(1, sizeof(struct builtin));
table[1]->name = "cd";
table[1]->f = my_cd;
}
And here I am freeing linked list:
struct cmd{
char *command[2+MAXARGS];
struct cmd *next;
};
void freeLL(){
struct cmd *ptr = cmdListFront;
struct cmd *temp;
while(ptr != NULL){
temp = ptr;
ptr = ptr->next;
free(temp);
}
}
And the last one I am allocating and freeing a line that is allocated for user input:
char *line = calloc(MAXLINE+1, 1);
while (fgets(line, MAXLINE+1, stdin)) {
...
free(line);
line = calloc(MAXLINE+1, 1);
}
free(line);
Any mistakes in my frees?