Commit 5db504f4ebc9b60afc31d62dc0d4c72cd1e98b3f
1 parent
293e356c
Ajout de la fonction free_tree qui libère la mémoire. Valgind détecte une erreur…
…, à trouver et corriger.
Showing
1 changed file
with
9 additions
and
10 deletions
Show diff stats
... | ... | @@ -236,18 +236,17 @@ void print_first(Node Tree) |
236 | 236 | } |
237 | 237 | } |
238 | 238 | |
239 | -/*void free_tree(Node Tree) | |
239 | +void free_tree(Node* Tree) | |
240 | 240 | { |
241 | - int index=0; | |
242 | - while(index<NB_CARAC) | |
241 | + if(*Tree!=NULL) | |
243 | 242 | { |
244 | - if(Tree->next[index]!=NULL) | |
245 | - free_tree(Tree->next[index]); | |
246 | - else | |
247 | - index++; | |
243 | + for(int i=0; i<NB_CARAC; i++) | |
244 | + { | |
245 | + free_tree(&(*Tree)->next[i]); | |
246 | + } | |
247 | + free(*Tree); | |
248 | 248 | } |
249 | - free(Tree); | |
250 | - }*/ | |
249 | +} | |
251 | 250 | |
252 | 251 | int main(int argc, char *argv[]) |
253 | 252 | { |
... | ... | @@ -270,6 +269,6 @@ int main(int argc, char *argv[]) |
270 | 269 | |
271 | 270 | printf("erreurs : %d\n", error); |
272 | 271 | |
273 | - //free_tree(tree); | |
272 | + free_tree(&tree); | |
274 | 273 | return 0; |
275 | 274 | } | ... | ... |