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

* deffilep.y: Replace "if (x) free (x)" with "free (x)" thoughout.
	* emultempl/elf.em: Likewise.
	* emultempl/msp430.em: Likewise.
	* emultempl/pe.em: Likewise.
	* emultempl/pep.em: Likewise.
	* emultempl/ppc64elf.em: Likewise.
	* emultempl/xtensaelf.em: Likewise.
	* ldelf.c: Likewise.
	* ldfile.c: Likewise.
	* ldmain.c: Likewise.
	* ldmisc.c: Likewise.
	* lexsup.c: Likewise.
	* pe-dll.c: Likewise.
This commit is contained in:
Alan Modra 2020-05-20 22:50:49 +09:30
parent 3d45296946
commit 5e2ab61254
14 changed files with 56 additions and 84 deletions

View File

@ -1,3 +1,19 @@
2020-05-21 Alan Modra <amodra@gmail.com>
* deffilep.y: Replace "if (x) free (x)" with "free (x)" thoughout.
* emultempl/elf.em: Likewise.
* emultempl/msp430.em: Likewise.
* emultempl/pe.em: Likewise.
* emultempl/pep.em: Likewise.
* emultempl/ppc64elf.em: Likewise.
* emultempl/xtensaelf.em: Likewise.
* ldelf.c: Likewise.
* ldfile.c: Likewise.
* ldmain.c: Likewise.
* ldmisc.c: Likewise.
* lexsup.c: Likewise.
* pe-dll.c: Likewise.
2020-05-20 Nelson Chu <nelson.chu@sifive.com> 2020-05-20 Nelson Chu <nelson.chu@sifive.com>
* testsuite/ld-riscv-elf/attr-merge-arch-01.d: Updated * testsuite/ld-riscv-elf/attr-merge-arch-01.d: Updated

View File

@ -434,19 +434,15 @@ def_file_free (def_file *fdef)
if (!fdef) if (!fdef)
return; return;
if (fdef->name) free (fdef->name);
free (fdef->name); free (fdef->description);
if (fdef->description)
free (fdef->description);
if (fdef->section_defs) if (fdef->section_defs)
{ {
for (i = 0; i < fdef->num_section_defs; i++) for (i = 0; i < fdef->num_section_defs; i++)
{ {
if (fdef->section_defs[i].name) free (fdef->section_defs[i].name);
free (fdef->section_defs[i].name); free (fdef->section_defs[i].class);
if (fdef->section_defs[i].class)
free (fdef->section_defs[i].class);
} }
free (fdef->section_defs); free (fdef->section_defs);
} }
@ -455,13 +451,10 @@ def_file_free (def_file *fdef)
{ {
for (i = 0; i < fdef->num_exports; i++) for (i = 0; i < fdef->num_exports; i++)
{ {
if (fdef->exports[i].internal_name if (fdef->exports[i].internal_name != fdef->exports[i].name)
&& fdef->exports[i].internal_name != fdef->exports[i].name)
free (fdef->exports[i].internal_name); free (fdef->exports[i].internal_name);
if (fdef->exports[i].name) free (fdef->exports[i].name);
free (fdef->exports[i].name); free (fdef->exports[i].its_name);
if (fdef->exports[i].its_name)
free (fdef->exports[i].its_name);
} }
free (fdef->exports); free (fdef->exports);
} }
@ -470,13 +463,10 @@ def_file_free (def_file *fdef)
{ {
for (i = 0; i < fdef->num_imports; i++) for (i = 0; i < fdef->num_imports; i++)
{ {
if (fdef->imports[i].internal_name if (fdef->imports[i].internal_name != fdef->imports[i].name)
&& fdef->imports[i].internal_name != fdef->imports[i].name)
free (fdef->imports[i].internal_name); free (fdef->imports[i].internal_name);
if (fdef->imports[i].name) free (fdef->imports[i].name);
free (fdef->imports[i].name); free (fdef->imports[i].its_name);
if (fdef->imports[i].its_name)
free (fdef->imports[i].its_name);
} }
free (fdef->imports); free (fdef->imports);
} }
@ -1049,8 +1039,7 @@ def_image_name (const char *name, bfd_vma base, int is_dll)
einfo ("%s:%d: Warning: path components stripped from %s, '%s'\n", einfo ("%s:%d: Warning: path components stripped from %s, '%s'\n",
def_filename, linenumber, is_dll ? "LIBRARY" : "NAME", def_filename, linenumber, is_dll ? "LIBRARY" : "NAME",
name); name);
if (def->name) free (def->name);
free (def->name);
/* Append the default suffix, if none specified. */ /* Append the default suffix, if none specified. */
if (strchr (image_name, '.') == 0) if (strchr (image_name, '.') == 0)
{ {

View File

@ -620,11 +620,8 @@ gld${EMULATION_NAME}_handle_option (int optc)
return FALSE; return FALSE;
case OPTION_BUILD_ID: case OPTION_BUILD_ID:
if (ldelf_emit_note_gnu_build_id != NULL) free ((char *) ldelf_emit_note_gnu_build_id);
{ ldelf_emit_note_gnu_build_id = NULL;
free ((char *) ldelf_emit_note_gnu_build_id);
ldelf_emit_note_gnu_build_id = NULL;
}
if (optarg == NULL) if (optarg == NULL)
optarg = DEFAULT_BUILD_ID_STYLE; optarg = DEFAULT_BUILD_ID_STYLE;
if (strcmp (optarg, "none")) if (strcmp (optarg, "none"))

View File

@ -330,8 +330,7 @@ gld${EMULATION_NAME}_place_orphan (asection * s,
end: end:
free (upper_name); free (upper_name);
free (lower_name); free (lower_name);
if (buf) free (buf);
free (buf);
return lower; return lower;
} }
EOF EOF

View File

@ -884,11 +884,8 @@ gld${EMULATION_NAME}_handle_option (int optc)
pe_dll_characteristics |= IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE; pe_dll_characteristics |= IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE;
break; break;
case OPTION_BUILD_ID: case OPTION_BUILD_ID:
if (emit_build_id != NULL) free ((char *) emit_build_id);
{ emit_build_id = NULL;
free ((char *) emit_build_id);
emit_build_id = NULL;
}
if (optarg == NULL) if (optarg == NULL)
optarg = DEFAULT_BUILD_ID_STYLE; optarg = DEFAULT_BUILD_ID_STYLE;
if (strcmp (optarg, "none")) if (strcmp (optarg, "none"))

View File

@ -831,11 +831,8 @@ gld${EMULATION_NAME}_handle_option (int optc)
pe_dll_characteristics |= IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE; pe_dll_characteristics |= IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE;
break; break;
case OPTION_BUILD_ID: case OPTION_BUILD_ID:
if (emit_build_id != NULL) free ((char *) emit_build_id);
{ emit_build_id = NULL;
free ((char *) emit_build_id);
emit_build_id = NULL;
}
if (optarg == NULL) if (optarg == NULL)
optarg = DEFAULT_BUILD_ID_STYLE; optarg = DEFAULT_BUILD_ID_STYLE;
if (strcmp (optarg, "none")) if (strcmp (optarg, "none"))

View File

@ -602,8 +602,7 @@ gld${EMULATION_NAME}_finish (void)
fprintf (stderr, "%s: %s\n", program_name, line); fprintf (stderr, "%s: %s\n", program_name, line);
} }
fflush (stderr); fflush (stderr);
if (msg != NULL) free (msg);
free (msg);
finish_default (); finish_default ();
} }

View File

@ -216,18 +216,15 @@ replace_insn_sec_with_prop_sec (bfd *abfd,
remove_section (abfd, insn_sec); remove_section (abfd, insn_sec);
if (insn_contents) free (insn_contents);
free (insn_contents);
return TRUE; return TRUE;
cleanup: cleanup:
if (prop_sec && prop_sec->owner) if (prop_sec && prop_sec->owner)
remove_section (abfd, prop_sec); remove_section (abfd, prop_sec);
if (insn_contents) free (insn_contents);
free (insn_contents); free (internal_relocs);
if (internal_relocs)
free (internal_relocs);
return FALSE; return FALSE;
} }
@ -271,8 +268,7 @@ replace_instruction_table_sections (bfd *abfd, asection *sec)
insn_sec_name, abfd, message); insn_sec_name, abfd, message);
} }
} }
if (owned_prop_sec_name) free (owned_prop_sec_name);
free (owned_prop_sec_name);
} }
@ -636,8 +632,7 @@ xtensa_append_section_deps (reloc_deps_graph *deps, asection *sec)
{ {
new_sections[i] = deps->sections[i]; new_sections[i] = deps->sections[i];
} }
if (deps->sections != NULL) free (deps->sections);
free (deps->sections);
deps->sections = new_sections; deps->sections = new_sections;
deps->size = new_size; deps->size = new_size;
} }
@ -675,9 +670,7 @@ free_reloc_deps_graph (reloc_deps_graph *deps)
} }
xtensa_set_section_deps (deps, sec, NULL); xtensa_set_section_deps (deps, sec, NULL);
} }
if (deps->sections) free (deps->sections);
free (deps->sections);
free (deps); free (deps);
} }

View File

@ -783,8 +783,7 @@ ldelf_parse_ld_so_conf_include (struct ldelf_ld_so_conf *info,
ldelf_parse_ld_so_conf (info, pattern); ldelf_parse_ld_so_conf (info, pattern);
#endif #endif
if (newp) free (newp);
free (newp);
} }
static bfd_boolean static bfd_boolean

View File

@ -240,8 +240,8 @@ ldfile_try_open_bfd (const char *attempt,
skip = 1; skip = 1;
} }
free (arg1); free (arg1);
if (arg2) free (arg2); free (arg2);
if (arg3) free (arg3); free (arg3);
break; break;
case NAME: case NAME:
case LNAME: case LNAME:
@ -250,8 +250,7 @@ ldfile_try_open_bfd (const char *attempt,
free (yylval.name); free (yylval.name);
break; break;
case INT: case INT:
if (yylval.bigint.str) free (yylval.bigint.str);
free (yylval.bigint.str);
break; break;
} }
token = yylex (); token = yylex ();

View File

@ -1349,8 +1349,7 @@ undefined_symbol (struct bfd_link_info *info,
else else
{ {
error_count = 0; error_count = 0;
if (error_name != NULL) free (error_name);
free (error_name);
error_name = xstrdup (name); error_name = xstrdup (name);
} }

View File

@ -375,13 +375,11 @@ vfinfo (FILE *fp, const char *fmt, va_list ap, bfd_boolean is_warning)
abfd, functionname); abfd, functionname);
last_bfd = abfd; last_bfd = abfd;
if (last_file != NULL) free (last_file);
free (last_file);
last_file = NULL; last_file = NULL;
if (filename) if (filename)
last_file = xstrdup (filename); last_file = xstrdup (filename);
if (last_function != NULL) free (last_function);
free (last_function);
last_function = xstrdup (functionname); last_function = xstrdup (functionname);
} }
discard_last = FALSE; discard_last = FALSE;
@ -412,16 +410,10 @@ vfinfo (FILE *fp, const char *fmt, va_list ap, bfd_boolean is_warning)
if (discard_last) if (discard_last)
{ {
last_bfd = NULL; last_bfd = NULL;
if (last_file != NULL) free (last_file);
{ last_file = NULL;
free (last_file); free (last_function);
last_file = NULL; last_function = NULL;
}
if (last_function != NULL)
{
free (last_function);
last_function = NULL;
}
} }
} }
break; break;

View File

@ -1485,8 +1485,7 @@ parse_args (unsigned argc, char **argv)
case 'Y': case 'Y':
if (CONST_STRNEQ (optarg, "P,")) if (CONST_STRNEQ (optarg, "P,"))
optarg += 2; optarg += 2;
if (default_dirlist != NULL) free (default_dirlist);
free (default_dirlist);
default_dirlist = xstrdup (optarg); default_dirlist = xstrdup (optarg);
break; break;
case 'y': case 'y':

View File

@ -891,12 +891,9 @@ process_def_file_and_drectve (bfd *abfd ATTRIBUTE_UNUSED, struct bfd_link_info *
e[j - 1].flag_constant |= e[i].flag_constant; e[j - 1].flag_constant |= e[i].flag_constant;
e[j - 1].flag_noname |= e[i].flag_noname; e[j - 1].flag_noname |= e[i].flag_noname;
e[j - 1].flag_data |= e[i].flag_data; e[j - 1].flag_data |= e[i].flag_data;
if (e[i].name) free (e[i].name);
free (e[i].name); free (e[i].internal_name);
if (e[i].internal_name) free (e[i].its_name);
free (e[i].internal_name);
if (e[i].its_name)
free (e[i].its_name);
} }
else else
{ {