This function:
free_list(struct List_db_void *elm, enum db_type type) {
switch(type) {
case db_type_int:
free((struct List_db_int*) elm);
break;
case db_type_string:
free((struct List_db_string*) elm);
break;
default:
/*Should not reach*/
return ;
break;
}
}
is exactly the same as (considering that we never go through the default
branch, as your comment suggests)
free_list(struct List_db_void *elm, enum db_type type) {
free(elm);
}
Pointer casts are for the type system and have no dynamic semantics. They disappear after compiling, so to speak.
This being said I'm taking a look to see what causes the segfault.
EDIT: Probably this!
for (j = 0; j < HOW_MANY_ELEMENTS_REMOVE; j++) {
free_list(last, t->cols[i]/*type of column*/);
last = last->next;
}
You're using last
after freeing it. Do something like
for (j = 0; j < HOW_MANY_ELEMENTS_REMOVE; j++) {
struct List_db_void *temp = last->next;
free_list(last, t->cols[i]/*type of column*/);
last = temp;
}