Replace "if (x) free (x)" with "free (x)", binutils

* addr2line.c: Replace "if (x) free (x)" with "free (x)" throughout.
	* dlltool.c: Likewise.
	* elfcomm.c: Likewise.
	* rddbg.c: Likewise.
	* readelf.c: Likewise.
	* stabs.c: Likewise.
	* windmc.c: Likewise.
	* windres.c: Likewise.
	* wrstabs.c: Likewise.
This commit is contained in:
Alan Modra 2020-05-20 22:48:41 +09:30
parent c95949892f
commit 9db70fc365
10 changed files with 92 additions and 176 deletions

View File

@ -1,3 +1,15 @@
2020-05-21 Alan Modra <amodra@gmail.com>
* addr2line.c: Replace "if (x) free (x)" with "free (x)" throughout.
* dlltool.c: Likewise.
* elfcomm.c: Likewise.
* rddbg.c: Likewise.
* readelf.c: Likewise.
* stabs.c: Likewise.
* windmc.c: Likewise.
* windres.c: Likewise.
* wrstabs.c: Likewise.
2020-05-21 Alan Modra <amodra@gmail.com> 2020-05-21 Alan Modra <amodra@gmail.com>
* readelf.c (get_num_dynamic_syms): Bounds check mipsxlat array * readelf.c (get_num_dynamic_syms): Bounds check mipsxlat array

View File

@ -314,8 +314,7 @@ translate_addresses (bfd *abfd, asection *section)
else else
printf ("\n"); printf ("\n");
if (alloc != NULL) free (alloc);
free (alloc);
} }
if (base_names && filename != NULL) if (base_names && filename != NULL)
@ -410,11 +409,8 @@ process_file (const char *file_name, const char *section_name,
translate_addresses (abfd, section); translate_addresses (abfd, section);
if (syms != NULL) free (syms);
{ syms = NULL;
free (syms);
syms = NULL;
}
bfd_close (abfd); bfd_close (abfd);

View File

@ -1253,8 +1253,7 @@ def_import (const char *app_name, const char *module, const char *dllext,
append_import (application_name, module, ord_val, its_name); append_import (application_name, module, ord_val, its_name);
if (buf) free (buf);
free (buf);
} }
void void
@ -1335,7 +1334,7 @@ run (const char *what, char *args)
pid = pexecute (argv[0], (char * const *) argv, program_name, temp_base, pid = pexecute (argv[0], (char * const *) argv, program_name, temp_base,
&errmsg_fmt, &errmsg_arg, PEXECUTE_ONE | PEXECUTE_SEARCH); &errmsg_fmt, &errmsg_arg, PEXECUTE_ONE | PEXECUTE_SEARCH);
free(argv); free (argv);
if (pid == -1) if (pid == -1)
{ {
@ -3388,15 +3387,8 @@ dll_name_list_free_contents (dll_name_list_node_type * entry)
if (entry) if (entry)
{ {
if (entry->next) if (entry->next)
{ dll_name_list_free_contents (entry->next);
dll_name_list_free_contents (entry->next); free (entry->dllname);
entry->next = NULL;
}
if (entry->dllname)
{
free (entry->dllname);
entry->dllname = NULL;
}
free (entry); free (entry);
} }
} }

View File

@ -744,14 +744,10 @@ setup_nested_archive (struct archive_info *nested_arch,
void void
release_archive (struct archive_info * arch) release_archive (struct archive_info * arch)
{ {
if (arch->file_name != NULL) free (arch->file_name);
free (arch->file_name); free (arch->index_array);
if (arch->index_array != NULL) free (arch->sym_table);
free (arch->index_array); free (arch->longnames);
if (arch->sym_table != NULL)
free (arch->sym_table);
if (arch->longnames != NULL)
free (arch->longnames);
} }
/* Get the name of an archive member from the current archive header. /* Get the name of an archive member from the current archive header.

View File

@ -319,8 +319,7 @@ read_symbol_stabs_debugging_info (bfd *abfd, asymbol **syms, long symcount,
sc[strlen (sc) - 1] = '\0'; sc[strlen (sc) - 1] = '\0';
n = concat (sc, bfd_asymbol_name (*ps), (const char *) NULL); n = concat (sc, bfd_asymbol_name (*ps), (const char *) NULL);
free (sc); free (sc);
if (f != NULL) free (f);
free (f);
f = n; f = n;
s = n; s = n;
} }
@ -372,8 +371,7 @@ static int saved_stabs_index;
static void static void
save_stab (int type, int desc, bfd_vma value, const char *string) save_stab (int type, int desc, bfd_vma value, const char *string)
{ {
if (saved_stabs[saved_stabs_index].string != NULL) free (saved_stabs[saved_stabs_index].string);
free (saved_stabs[saved_stabs_index].string);
saved_stabs[saved_stabs_index].type = type; saved_stabs[saved_stabs_index].type = type;
saved_stabs[saved_stabs_index].desc = desc; saved_stabs[saved_stabs_index].desc = desc;
saved_stabs[saved_stabs_index].value = value; saved_stabs[saved_stabs_index].value = value;
@ -428,11 +426,8 @@ free_saved_stabs (void)
for (i = 0; i < SAVE_STABS_COUNT; i++) for (i = 0; i < SAVE_STABS_COUNT; i++)
{ {
if (saved_stabs[i].string != NULL) free (saved_stabs[i].string);
{ saved_stabs[i].string = NULL;
free (saved_stabs[i].string);
saved_stabs[i].string = NULL;
}
} }
saved_stabs_index = 0; saved_stabs_index = 0;

View File

@ -7010,8 +7010,7 @@ process_section_groups (Filedata * filedata)
if (symtab_sec != sec) if (symtab_sec != sec)
{ {
symtab_sec = sec; symtab_sec = sec;
if (symtab) free (symtab);
free (symtab);
symtab = GET_ELF_SYMBOLS (filedata, symtab_sec, & num_syms); symtab = GET_ELF_SYMBOLS (filedata, symtab_sec, & num_syms);
} }
@ -7040,8 +7039,7 @@ process_section_groups (Filedata * filedata)
group_name = SECTION_NAME (filedata->section_headers + sym->st_shndx); group_name = SECTION_NAME (filedata->section_headers + sym->st_shndx);
strtab_sec = NULL; strtab_sec = NULL;
if (strtab) free (strtab);
free (strtab);
strtab = NULL; strtab = NULL;
strtab_size = 0; strtab_size = 0;
} }
@ -7051,8 +7049,7 @@ process_section_groups (Filedata * filedata)
if (symtab_sec->sh_link >= filedata->file_header.e_shnum) if (symtab_sec->sh_link >= filedata->file_header.e_shnum)
{ {
strtab_sec = NULL; strtab_sec = NULL;
if (strtab) free (strtab);
free (strtab);
strtab = NULL; strtab = NULL;
strtab_size = 0; strtab_size = 0;
} }
@ -7060,8 +7057,7 @@ process_section_groups (Filedata * filedata)
!= (sec = filedata->section_headers + symtab_sec->sh_link)) != (sec = filedata->section_headers + symtab_sec->sh_link))
{ {
strtab_sec = sec; strtab_sec = sec;
if (strtab) free (strtab);
free (strtab);
strtab = (char *) get_data (NULL, filedata, strtab_sec->sh_offset, strtab = (char *) get_data (NULL, filedata, strtab_sec->sh_offset,
1, strtab_sec->sh_size, 1, strtab_sec->sh_size,
@ -7169,17 +7165,14 @@ process_section_groups (Filedata * filedata)
group->root = g; group->root = g;
} }
if (start) free (start);
free (start);
group++; group++;
} }
} }
if (symtab) free (symtab);
free (symtab); free (strtab);
if (strtab)
free (strtab);
return TRUE; return TRUE;
} }
@ -7367,8 +7360,7 @@ process_ia64_vms_dynamic_relocs (Filedata * filedata)
} }
} }
if (strtab != NULL) free (strtab);
free (strtab);
return res; return res;
} }
@ -7514,8 +7506,7 @@ process_relocs (Filedata * filedata)
symtab, nsyms, strtab, strtablen, symtab, nsyms, strtab, strtablen,
is_rela, is_rela,
symsec->sh_type == SHT_DYNSYM); symsec->sh_type == SHT_DYNSYM);
if (strtab) free (strtab);
free (strtab);
free (symtab); free (symtab);
} }
else else
@ -8041,19 +8032,15 @@ ia64_process_unwind (Filedata * filedata)
&& aux.table_len > 0) && aux.table_len > 0)
dump_ia64_unwind (filedata, & aux); dump_ia64_unwind (filedata, & aux);
if (aux.table) free ((char *) aux.table);
free ((char *) aux.table); free ((char *) aux.info);
if (aux.info)
free ((char *) aux.info);
aux.table = NULL; aux.table = NULL;
aux.info = NULL; aux.info = NULL;
} }
} }
if (aux.symtab) free (aux.symtab);
free (aux.symtab); free ((char *) aux.strtab);
if (aux.strtab)
free ((char *) aux.strtab);
return res; return res;
} }
@ -8423,16 +8410,13 @@ hppa_process_unwind (Filedata * filedata)
res = FALSE; res = FALSE;
} }
if (aux.table) free ((char *) aux.table);
free ((char *) aux.table);
aux.table = NULL; aux.table = NULL;
} }
} }
if (aux.symtab) free (aux.symtab);
free (aux.symtab); free ((char *) aux.strtab);
if (aux.strtab)
free ((char *) aux.strtab);
return res; return res;
} }
@ -8492,11 +8476,8 @@ arm_print_vma_and_name (Filedata * filedata,
static void static void
arm_free_section (struct arm_section *arm_sec) arm_free_section (struct arm_section *arm_sec)
{ {
if (arm_sec->data != NULL) free (arm_sec->data);
free (arm_sec->data); free (arm_sec->rela);
if (arm_sec->rela != NULL)
free (arm_sec->rela);
} }
/* 1) If SEC does not match the one cached in ARM_SEC, then free the current /* 1) If SEC does not match the one cached in ARM_SEC, then free the current
@ -9530,10 +9511,8 @@ arm_process_unwind (Filedata * filedata)
} }
} }
if (aux.symtab) free (aux.symtab);
free (aux.symtab); free ((char *) aux.strtab);
if (aux.strtab)
free ((char *) aux.strtab);
return res; return res;
} }
@ -10062,16 +10041,10 @@ get_num_dynamic_syms (Filedata * filedata)
no_hash: no_hash:
if (num_of_syms == 0) if (num_of_syms == 0)
{ {
if (filedata->buckets) free (filedata->buckets);
{ filedata->buckets = NULL;
free (filedata->buckets); free (filedata->chains);
filedata->buckets = NULL; filedata->chains = NULL;
}
if (filedata->chains)
{
free (filedata->chains);
filedata->chains = NULL;
}
filedata->nbuckets = 0; filedata->nbuckets = 0;
} }
} }
@ -10229,21 +10202,12 @@ get_num_dynamic_syms (Filedata * filedata)
if (num_of_syms == 0) if (num_of_syms == 0)
{ {
no_gnu_hash: no_gnu_hash:
if (filedata->mipsxlat) free (filedata->mipsxlat);
{ filedata->mipsxlat = NULL;
free (filedata->mipsxlat); free (filedata->gnuchains);
filedata->mipsxlat = NULL; filedata->gnuchains = NULL;
} free (filedata->gnubuckets);
if (filedata->gnuchains) filedata->gnubuckets = NULL;
{
free (filedata->gnuchains);
filedata->gnuchains = NULL;
}
if (filedata->gnubuckets)
{
free (filedata->gnubuckets);
filedata->gnubuckets = NULL;
}
filedata->ngnubuckets = 0; filedata->ngnubuckets = 0;
filedata->ngnuchains = 0; filedata->ngnuchains = 0;
} }
@ -14654,12 +14618,9 @@ free_debug_section (enum dwarf_section_display_enum debug)
section->address = 0; section->address = 0;
section->size = 0; section->size = 0;
if (section->reloc_info != NULL) free (section->reloc_info);
{ section->reloc_info = NULL;
free (section->reloc_info); section->num_relocs = 0;
section->reloc_info = NULL;
section->num_relocs = 0;
}
} }
static bfd_boolean static bfd_boolean
@ -16763,8 +16724,7 @@ process_mips_specific (Filedata * filedata)
} }
sgot_print_fail: sgot_print_fail:
if (data) free (data);
free (data);
} }
return res; return res;
} }
@ -17396,8 +17356,7 @@ process_mips_specific (Filedata * filedata)
} }
got_print_fail: got_print_fail:
if (data) free (data);
free (data);
} }
if (mips_pltgot != 0 && jmprel != 0 && pltrel != 0 && pltrelsz != 0) if (mips_pltgot != 0 && jmprel != 0 && pltrel != 0 && pltrelsz != 0)
@ -17474,8 +17433,7 @@ process_mips_specific (Filedata * filedata)
} }
printf ("\n"); printf ("\n");
if (data) free (data);
free (data);
free (rels); free (rels);
} }
@ -19747,11 +19705,8 @@ process_notes_at (Filedata * filedata,
if (! process_note (& inote, filedata)) if (! process_note (& inote, filedata))
res = FALSE; res = FALSE;
if (temp != NULL) free (temp);
{ temp = NULL;
free (temp);
temp = NULL;
}
} }
free (pnotes); free (pnotes);
@ -20305,38 +20260,23 @@ process_object (Filedata * filedata)
filedata->string_table = NULL; filedata->string_table = NULL;
filedata->string_table_length = 0; filedata->string_table_length = 0;
if (filedata->dump.dump_sects != NULL) free (filedata->dump.dump_sects);
{ filedata->dump.dump_sects = NULL;
free (filedata->dump.dump_sects); filedata->dump.num_dump_sects = 0;
filedata->dump.dump_sects = NULL;
filedata->dump.num_dump_sects = 0;
}
if (filedata->dynamic_strings) free (filedata->dynamic_strings);
{ filedata->dynamic_strings = NULL;
free (filedata->dynamic_strings); filedata->dynamic_strings_length = 0;
filedata->dynamic_strings = NULL;
filedata->dynamic_strings_length = 0;
}
if (filedata->dynamic_symbols) free (filedata->dynamic_symbols);
{ filedata->dynamic_symbols = NULL;
free (filedata->dynamic_symbols); filedata->num_dynamic_syms = 0;
filedata->dynamic_symbols = NULL;
filedata->num_dynamic_syms = 0;
}
if (filedata->dynamic_syminfo) free (filedata->dynamic_syminfo);
{ filedata->dynamic_syminfo = NULL;
free (filedata->dynamic_syminfo);
filedata->dynamic_syminfo = NULL;
}
if (filedata->dynamic_section) free (filedata->dynamic_section);
{ filedata->dynamic_section = NULL;
free (filedata->dynamic_section);
filedata->dynamic_section = NULL;
}
while (filedata->symtab_shndx_list != NULL) while (filedata->symtab_shndx_list != NULL)
{ {
@ -20345,11 +20285,8 @@ process_object (Filedata * filedata)
filedata->symtab_shndx_list = next; filedata->symtab_shndx_list = next;
} }
if (filedata->section_headers_groups) free (filedata->section_headers_groups);
{ filedata->section_headers_groups = NULL;
free (filedata->section_headers_groups);
filedata->section_headers_groups = NULL;
}
if (filedata->section_groups) if (filedata->section_groups)
{ {
@ -20810,8 +20747,7 @@ main (int argc, char ** argv)
if (! process_file (argv[optind++])) if (! process_file (argv[optind++]))
err = TRUE; err = TRUE;
if (cmdline.dump_sects != NULL) free (cmdline.dump_sects);
free (cmdline.dump_sects);
free (dump_ctf_symtab_name); free (dump_ctf_symtab_name);
free (dump_ctf_strtab_name); free (dump_ctf_strtab_name);

View File

@ -2119,8 +2119,7 @@ parse_stab_struct_type (void * dhandle,
|| ! parse_stab_tilde_field (dhandle, info, pp, typenums, &vptrbase, || ! parse_stab_tilde_field (dhandle, info, pp, typenums, &vptrbase,
&ownvptr, p_end)) &ownvptr, p_end))
{ {
if (fields != NULL) free (fields);
free (fields);
return DEBUG_TYPE_NULL; return DEBUG_TYPE_NULL;
} }
@ -2955,12 +2954,9 @@ parse_stab_members (void * dhandle,
return TRUE; return TRUE;
fail: fail:
if (name != NULL) free (name);
free (name); free (variants);
if (variants != NULL) free (argtypes);
free (variants);
if (argtypes != NULL)
free (argtypes);
return FALSE; return FALSE;
} }
@ -3901,8 +3897,7 @@ stab_demangle_argtypes (void *dhandle, struct stab_handle *info,
return minfo.args; return minfo.args;
error_return: error_return:
if (minfo.typestrings != NULL) free (minfo.typestrings);
free (minfo.typestrings);
return NULL; return NULL;
} }
@ -4516,8 +4511,7 @@ stab_demangle_template (struct stab_demangle_info *minfo, const char **pp,
if (s3 == NULL || s4 == NULL) if (s3 == NULL || s4 == NULL)
{ {
stab_bad_demangle (orig); stab_bad_demangle (orig);
if (s3 != NULL) free (s3);
free (s3);
return FALSE; return FALSE;
} }

View File

@ -1161,12 +1161,9 @@ main (int argc, char **argv)
} }
write_bin (); write_bin ();
if (mc_nodes_lang) free (mc_nodes_lang);
free (mc_nodes_lang); free (mc_severity_codes);
if (mc_severity_codes) free (mc_facility_codes);
free (mc_severity_codes);
if (mc_facility_codes)
free (mc_facility_codes);
xexit (0); xexit (0);
return 0; return 0;

View File

@ -704,8 +704,7 @@ quot (const char *string)
if ((buflen < slen * 2 + 2) || ! buf) if ((buflen < slen * 2 + 2) || ! buf)
{ {
buflen = slen * 2 + 2; buflen = slen * 2 + 2;
if (buf) free (buf);
free (buf);
buf = (char *) xmalloc (buflen); buf = (char *) xmalloc (buflen);
} }

View File

@ -1224,8 +1224,7 @@ stab_method_type (void *p, bfd_boolean domainp, int argcount,
} }
strcat (buf, ";"); strcat (buf, ";");
if (args != NULL) free (args);
free (args);
if (! stab_push_string (info, buf, 0, definition, 0)) if (! stab_push_string (info, buf, 0, definition, 0))
return FALSE; return FALSE;