Bonjour a vous tous,
Voila j'ai un petit problème d'environ 16 non-free lorsque je le teste avec valgrind... Pour un petit programme comme ca...
Si vous pouviez m'indiquer ce qui ne convient pas
Merci d'avance
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71 #include <stdio.h> #include <stdlib.h> #define max(a,b)((a>b)?a:b) /* structure recursive pour un arbre binaire */ typedef struct noeud { char Info; struct noeud *FilsG; struct noeud *FilsD; } Noeud, *Arbre; typedef struct table { int n; char *t; }Table; void DetruireArbre (Arbre a) { if (!a) return; DetruireArbre (a->FilsG); DetruireArbre (a->FilsD); free(a); a=NULL; } Arbre DeTableVersArbreBis (Table *tab, int i) { Arbre a = malloc(sizeof(Noeud)); if (!a){printf ("erreur allocation memoire de l'arbre\n"); return NULL;} if (i>=tab->n) {free (a); return NULL;} a->Info = tab->t[i]; a->FilsG = DeTableVersArbreBis(tab,2*i+1); a->FilsD = DeTableVersArbreBis(tab,2*i+2); return a; } Arbre DeTableVersArbre (Table *tab) { return DeTableVersArbreBis(tab,0); } void DetruireTable (Table *tab) { if (!tab) return; free (tab->t); free (tab); } int main (int argc, char *argv[]) { Table *tab = malloc (sizeof (Table)); tab->n=7; tab->t = malloc (sizeof(char)*tab->n); tab->t[0]='A'; tab->t[1]='B'; tab->t[2]='C'; tab->t[3]='D'; tab->t[4]='E'; tab->t[5]='F'; tab->t[6]='G'; Arbre a = DeTableVersArbre(tab); DetruireArbre (a); DetruireTable (tab); return EXIT_SUCCESS; }
Partager