Replace "if (x) free (x)" with "free (x)", ld
authorAlan Modra <amodra@gmail.com>
Wed, 20 May 2020 13:20:49 +0000 (22:50 +0930)
committerAlan Modra <amodra@gmail.com>
Thu, 21 May 2020 01:15:33 +0000 (10:45 +0930)
* 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.

14 files changed:
ld/ChangeLog
ld/deffilep.y
ld/emultempl/elf.em
ld/emultempl/msp430.em
ld/emultempl/pe.em
ld/emultempl/pep.em
ld/emultempl/ppc64elf.em
ld/emultempl/xtensaelf.em
ld/ldelf.c
ld/ldfile.c
ld/ldmain.c
ld/ldmisc.c
ld/lexsup.c
ld/pe-dll.c

index d95d5cfc2171edc4874b961e98b8269aeb749d4b..d12f3727ff13390d0d92040712f06955f756b5be 100644 (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>
 
        * testsuite/ld-riscv-elf/attr-merge-arch-01.d: Updated
index b9105d4aa181956d44e2d88f82d52dc93b527cc7..51cb1d7fcde6d38160a9b8698b4324153fa50869 100644 (file)
@@ -434,19 +434,15 @@ def_file_free (def_file *fdef)
 
   if (!fdef)
     return;
-  if (fdef->name)
-    free (fdef->name);
-  if (fdef->description)
-    free (fdef->description);
+  free (fdef->name);
+  free (fdef->description);
 
   if (fdef->section_defs)
     {
       for (i = 0; i < fdef->num_section_defs; i++)
        {
-         if (fdef->section_defs[i].name)
-           free (fdef->section_defs[i].name);
-         if (fdef->section_defs[i].class)
-           free (fdef->section_defs[i].class);
+         free (fdef->section_defs[i].name);
+         free (fdef->section_defs[i].class);
        }
       free (fdef->section_defs);
     }
@@ -455,13 +451,10 @@ def_file_free (def_file *fdef)
     {
       for (i = 0; i < fdef->num_exports; i++)
        {
-         if (fdef->exports[i].internal_name
-             && fdef->exports[i].internal_name != fdef->exports[i].name)
+         if (fdef->exports[i].internal_name != fdef->exports[i].name)
            free (fdef->exports[i].internal_name);
-         if (fdef->exports[i].name)
-           free (fdef->exports[i].name);
-         if (fdef->exports[i].its_name)
-           free (fdef->exports[i].its_name);
+         free (fdef->exports[i].name);
+         free (fdef->exports[i].its_name);
        }
       free (fdef->exports);
     }
@@ -470,13 +463,10 @@ def_file_free (def_file *fdef)
     {
       for (i = 0; i < fdef->num_imports; i++)
        {
-         if (fdef->imports[i].internal_name
-             && fdef->imports[i].internal_name != fdef->imports[i].name)
+         if (fdef->imports[i].internal_name != fdef->imports[i].name)
            free (fdef->imports[i].internal_name);
-         if (fdef->imports[i].name)
-           free (fdef->imports[i].name);
-         if (fdef->imports[i].its_name)
-           free (fdef->imports[i].its_name);
+         free (fdef->imports[i].name);
+         free (fdef->imports[i].its_name);
        }
       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",
               def_filename, linenumber, is_dll ? "LIBRARY" : "NAME",
               name);
-      if (def->name)
-       free (def->name);
+      free (def->name);
       /* Append the default suffix, if none specified.  */
       if (strchr (image_name, '.') == 0)
        {
index eac2ce2f4ca2f5e87fb0c14f6216ba368aee59ed..4fd6fdffe75fdadcb61bd1c6b146ec6431e86169 100644 (file)
@@ -620,11 +620,8 @@ gld${EMULATION_NAME}_handle_option (int optc)
       return FALSE;
 
     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)
        optarg = DEFAULT_BUILD_ID_STYLE;
       if (strcmp (optarg, "none"))
index 850c3a836ce605ef1c77001d7502eade22536079..c823a6d9b5868846ce3c00f662462bb27c5741c6 100644 (file)
@@ -330,8 +330,7 @@ gld${EMULATION_NAME}_place_orphan (asection * s,
  end:
   free (upper_name);
   free (lower_name);
-  if (buf)
-    free (buf);
+  free (buf);
   return lower;
 }
 EOF
index 8c5ee762334b387ef9e35a5a9aaea43267c1453f..3899c9d92c8d43ce6596adef4092628f8bd6ba6c 100644 (file)
@@ -884,11 +884,8 @@ gld${EMULATION_NAME}_handle_option (int optc)
       pe_dll_characteristics |= IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE;
       break;
     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)
        optarg = DEFAULT_BUILD_ID_STYLE;
       if (strcmp (optarg, "none"))
index ea8e768ea93f7825e9546d08ff029286ec26ddf5..a0a7023e7067ae0c358130d843266cc613958de4 100644 (file)
@@ -831,11 +831,8 @@ gld${EMULATION_NAME}_handle_option (int optc)
       pe_dll_characteristics |= IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE;
       break;
     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)
        optarg = DEFAULT_BUILD_ID_STYLE;
       if (strcmp (optarg, "none"))
index 6633f8156acf2dd135032e8b01ae2bd45ba59261..a2834c8525730503d4bb49837d2280492c7ba0e6 100644 (file)
@@ -602,8 +602,7 @@ gld${EMULATION_NAME}_finish (void)
       fprintf (stderr, "%s: %s\n", program_name, line);
     }
   fflush (stderr);
-  if (msg != NULL)
-    free (msg);
+  free (msg);
 
   finish_default ();
 }
index 2d9f594969f54a3e6a8065e72e731fa0342a1a93..932721c6f16d086c6854df5b199c191cb125bbc1 100644 (file)
@@ -216,18 +216,15 @@ replace_insn_sec_with_prop_sec (bfd *abfd,
 
   remove_section (abfd, insn_sec);
 
-  if (insn_contents)
-    free (insn_contents);
+  free (insn_contents);
 
   return TRUE;
 
  cleanup:
   if (prop_sec && prop_sec->owner)
     remove_section (abfd, prop_sec);
-  if (insn_contents)
-    free (insn_contents);
-  if (internal_relocs)
-    free (internal_relocs);
+  free (insn_contents);
+  free (internal_relocs);
 
   return FALSE;
 }
@@ -271,8 +268,7 @@ replace_instruction_table_sections (bfd *abfd, asection *sec)
                 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];
        }
-      if (deps->sections != NULL)
-       free (deps->sections);
+      free (deps->sections);
       deps->sections = new_sections;
       deps->size = new_size;
     }
@@ -675,9 +670,7 @@ free_reloc_deps_graph (reloc_deps_graph *deps)
        }
       xtensa_set_section_deps (deps, sec, NULL);
     }
-  if (deps->sections)
-    free (deps->sections);
-
+  free (deps->sections);
   free (deps);
 }
 
index fa4bf9f7278393a6a30a8e2e17b6ae7fdb606755..efb4b77382e483cb19d1d6a03074698a32615cd4 100644 (file)
@@ -783,8 +783,7 @@ ldelf_parse_ld_so_conf_include (struct ldelf_ld_so_conf *info,
   ldelf_parse_ld_so_conf (info, pattern);
 #endif
 
-  if (newp)
-    free (newp);
+  free (newp);
 }
 
 static bfd_boolean
index 53112c86947fdf222e9517f5b3db4a36a56ff5ad..60b28d3f0ce84d7a6d13b9ea4ac861985a5a3cf2 100644 (file)
@@ -240,8 +240,8 @@ ldfile_try_open_bfd (const char *attempt,
                                skip = 1;
                            }
                          free (arg1);
-                         if (arg2) free (arg2);
-                         if (arg3) free (arg3);
+                         free (arg2);
+                         free (arg3);
                          break;
                        case NAME:
                        case LNAME:
@@ -250,8 +250,7 @@ ldfile_try_open_bfd (const char *attempt,
                          free (yylval.name);
                          break;
                        case INT:
-                         if (yylval.bigint.str)
-                           free (yylval.bigint.str);
+                         free (yylval.bigint.str);
                          break;
                        }
                      token = yylex ();
index 04a3f7a5117801ca7fa6ec35757966bdeaa01017..3499e7c784ed0c77dd566cab6df02bb5eb634b69 100644 (file)
@@ -1349,8 +1349,7 @@ undefined_symbol (struct bfd_link_info *info,
   else
     {
       error_count = 0;
-      if (error_name != NULL)
-       free (error_name);
+      free (error_name);
       error_name = xstrdup (name);
     }
 
index cc090a5101033d3929a9bb1904d8745e4d3acadf..418e8d5c6eda8a3a570b90e39ce60eacd94939d4 100644 (file)
@@ -375,13 +375,11 @@ vfinfo (FILE *fp, const char *fmt, va_list ap, bfd_boolean is_warning)
                                    abfd, functionname);
 
                            last_bfd = abfd;
-                           if (last_file != NULL)
-                             free (last_file);
+                           free (last_file);
                            last_file = NULL;
                            if (filename)
                              last_file = xstrdup (filename);
-                           if (last_function != NULL)
-                             free (last_function);
+                           free (last_function);
                            last_function = xstrdup (functionname);
                          }
                        discard_last = FALSE;
@@ -412,16 +410,10 @@ vfinfo (FILE *fp, const char *fmt, va_list ap, bfd_boolean is_warning)
                if (discard_last)
                  {
                    last_bfd = NULL;
-                   if (last_file != NULL)
-                     {
-                       free (last_file);
-                       last_file = NULL;
-                     }
-                   if (last_function != NULL)
-                     {
-                       free (last_function);
-                       last_function = NULL;
-                     }
+                   free (last_file);
+                   last_file = NULL;
+                   free (last_function);
+                   last_function = NULL;
                  }
              }
              break;
index c02041d5f103252f1ef4d777b04b7ed3661d3c97..fe9526b527197e6d2adbb3026367e5ed0d3f634f 100644 (file)
@@ -1485,8 +1485,7 @@ parse_args (unsigned argc, char **argv)
        case 'Y':
          if (CONST_STRNEQ (optarg, "P,"))
            optarg += 2;
-         if (default_dirlist != NULL)
-           free (default_dirlist);
+         free (default_dirlist);
          default_dirlist = xstrdup (optarg);
          break;
        case 'y':
index 60504293f35878e0518185e2495db6c70777aa8e..f72b6583411847ee327049fb48917a0d8b887db8 100644 (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_noname |= e[i].flag_noname;
          e[j - 1].flag_data |= e[i].flag_data;
-         if (e[i].name)
-           free (e[i].name);
-         if (e[i].internal_name)
-           free (e[i].internal_name);
-         if (e[i].its_name)
-           free (e[i].its_name);
+         free (e[i].name);
+         free (e[i].internal_name);
+         free (e[i].its_name);
        }
       else
        {