fix leaks 32bit

This commit is contained in:
gbrochar 2024-10-25 14:51:59 +02:00
parent 7983e97be3
commit 6c42540095
1 changed files with 10 additions and 1 deletions

View File

@ -134,6 +134,7 @@ char *get_sym_char32(Elf32_Sym sym, Elf32_Shdr sec, int *tool) {
} }
return ("n"); return ("n");
} }
int nm32(t_mapped_file mapped_file, char *path, t_verbosity verbosity, t_ordering ordering) { int nm32(t_mapped_file mapped_file, char *path, t_verbosity verbosity, t_ordering ordering) {
t_root *tree = NULL; t_root *tree = NULL;
t_entry *entry = (t_entry *)malloc(sizeof(t_entry)); t_entry *entry = (t_entry *)malloc(sizeof(t_entry));
@ -182,6 +183,8 @@ int nm32(t_mapped_file mapped_file, char *path, t_verbosity verbosity, t_orderin
else { else {
str = sec_str; str = sec_str;
} }
if (str != sec_str)
free(sec_str);
// ici la str (le symbole) est bon, on la charge dans le truc, ensuite on genere la vrai string a afficher, avant de sort // ici la str (le symbole) est bon, on la charge dans le truc, ensuite on genere la vrai string a afficher, avant de sort
entry->symbol = ft_strdup(str); entry->symbol = ft_strdup(str);
free(str); free(str);
@ -194,7 +197,7 @@ int nm32(t_mapped_file mapped_file, char *path, t_verbosity verbosity, t_orderin
// ici le sym char a ete calculer, a partir de la on determine la verbosity // ici le sym char a ete calculer, a partir de la on determine la verbosity
// ici on fait if entry->verbosity >= verbosity, si c'est pas bon on skip toute la suite // ici on fait if entry->verbosity >= verbosity, si c'est pas bon on skip toute la suite
entry->verbosity = DEFAULT_VERBOSITY; entry->verbosity = DEFAULT_VERBOSITY;
if ((sym_char[0] == 'a' && sym.st_info == 4) || sym_char[0] == 'N' || tool == 1)// || entry->symbol[0] == '.') if ((sym_char[0] == 'a' && sym.st_info == 4) || sym_char[0] == 'N' || tool == 1)
entry->verbosity = ALL; entry->verbosity = ALL;
if (sym_char[0] == 'u' || sym_char[0] == 'v' || sym_char[0] == 'w' || (sym_char[0] >= 'A' && sym_char[0] <= 'Z' && sym_char[0] != 'N')) if (sym_char[0] == 'u' || sym_char[0] == 'v' || sym_char[0] == 'w' || (sym_char[0] >= 'A' && sym_char[0] <= 'Z' && sym_char[0] != 'N'))
entry->verbosity = GLOBAL; entry->verbosity = GLOBAL;
@ -242,12 +245,18 @@ int nm32(t_mapped_file mapped_file, char *path, t_verbosity verbosity, t_orderin
break; break;
} }
fflush(stdout); fflush(stdout);
} else {
free(entry->symbol);
free(sym_char);
} }
} }
} }
} }
free(entry);
// ici on affiche tout ou no symbols en cas de list vide
if (tree) { if (tree) {
ft_putrbt(tree, &put_entry); ft_putrbt(tree, &put_entry);
ft_delrbt(tree, &free_entry);
} else { } else {
ft_printf("sss", "nm: ", path, ": no symbols\n"); ft_printf("sss", "nm: ", path, ": no symbols\n");
} }