i have allocated the following structure,using dataset_creator function, and i want to free this structure(dataset, i maen) with all of its components. would you help me please??
struct dataset{
char *title;
struct linked_data *head;
struct dataset *next;
struct attribute **hash_table;
};
struct dataset* dataset_creator(char *name,struct attribute *expressions,struct query *query){
struct dataset *ds; //"ds" is the abbreviation of word "dataset"
//struct attribute **hash_table;
//struct linked_data *data;
struct attribute *current_attribute;
//int i;
int j;
int index;
ds=(struct dataset*)malloc(sizeof(struct dataset));
if(ds==NULL){
printf("failed memory allocation request\n");
exit(EXIT_FAILURE);
}
ds->next=NULL;
ds->title=(char*)calloc((strlen(name)+1),sizeof(char));
strcpy(ds->title,name);
ds->head=(linked_data*)malloc(sizeof(struct linked_data));
if(ds->head==NULL){
printf("failed memory allocation request\n");
exit(EXIT_FAILURE);
}
ds->head->next=NULL;
ds->hash_table=(attribute**)malloc(MAX_NUM_OF_ATTRS * sizeof(attribute*));
if(ds->hash_table==NULL){
printf("failed memory allocation request\n");
exit(EXIT_FAILURE);
}
for(j=0;j<MAX_NUM_OF_ATTRS;j++)
ds->hash_table[j]=NULL;
for(j=0;j<MAX_NUM_OF_ATTRS;j++){
index=hash(expressions[j].name,MAX_NUM_OF_ATTRS);
if(ds->hash_table[j]==NULL){
ds->hash_table[index]=(struct attribute*)malloc(sizeof(struct attribute));
ds->hash_table[index]->next=NULL;
}
else{
current_attribute=ds->hash_table[index]->next;
while(current_attribute->next != NULL){
current_attribute=current_attribute->next;
}
current_attribute->next=(struct attribute*)malloc(sizeof(struct attribute));
current_attribute->next->next=NULL;
}
}
return ds;
}
sorry for the grammatical mistakes; note:that is not the whole code;