Fix problems in CTF handling code exposed by the Coverity static analysis tool.
authorNick Clifton <nickc@redhat.com>
Wed, 22 Jul 2020 15:07:48 +0000 (16:07 +0100)
committerNick Clifton <nickc@redhat.com>
Wed, 22 Jul 2020 15:07:48 +0000 (16:07 +0100)
readelf * readelf.c (parse_args): Silence potential warnings about a
memory resource leak when allocating space for ctf option values.
(dump_section_as_ctf): Fix typo checking dump_ctf_strtab_name
variable.

libctf * ctf-archive.c (ctf_arc_write): Avoid calling close twice on the
same file descriptor.

binutils/ChangeLog
binutils/readelf.c
libctf/ChangeLog
libctf/ctf-archive.c

index ab59cda43df39ff3cd6b934023ebcf3cea1f04e2..7aead1a6609acb96ab8cb51fad3316b96329dd98 100644 (file)
@@ -1,3 +1,10 @@
+2020-07-22  Nick Clifton  <nickc@redhat.com>
+
+       * readelf.c (parse_args): Silence potential warnings about a
+       memory resource leak when allocating space for ctf option values.
+       (dump_section_as_ctf): Fix typo checking dump_ctf_strtab_name
+       variable.
+
 2020-07-21  Nick Clifton  <nickc@redhat.com>
 
        * po/sv.po: Updated Swedish translation.
index 2406304fe35a832ac53aa7b1a367f3f7afed4264..c3cbd2cb235584d8aa4f4f74874e03d3097c152f 100644 (file)
@@ -4827,12 +4827,15 @@ parse_args (struct dump_data *dumpdata, int argc, char ** argv)
          request_dump (dumpdata, CTF_DUMP);
          break;
        case OPTION_CTF_SYMBOLS:
+         free (dump_ctf_symtab_name);
          dump_ctf_symtab_name = strdup (optarg);
          break;
        case OPTION_CTF_STRINGS:
+         free (dump_ctf_strtab_name);
          dump_ctf_strtab_name = strdup (optarg);
          break;
        case OPTION_CTF_PARENT:
+         free (dump_ctf_parent_name);
          dump_ctf_parent_name = strdup (optarg);
          break;
        case OPTION_DYN_SYMS:
@@ -14296,7 +14299,7 @@ dump_section_as_ctf (Elf_Internal_Shdr * section, Filedata * filedata)
       symsectp = shdr_to_ctf_sect (&symsect, symtab_sec, filedata);
       symsect.cts_data = symdata;
     }
-  if (dump_ctf_strtab_name && dump_ctf_symtab_name[0] != 0)
+  if (dump_ctf_strtab_name && dump_ctf_strtab_name[0] != 0)
     {
       if ((strtab_sec = find_section (filedata, dump_ctf_strtab_name)) == NULL)
        {
index bf604421bb2b7ead9873913cae0fc243a26345c1..c061ef80b6e437f83485daab4a46262326ce9ccc 100644 (file)
@@ -1,3 +1,8 @@
+2020-07-22  Nick Clifton  <nickc@redhat.com>
+
+       * ctf-archive.c (ctf_arc_write): Avoid calling close twice on the
+       same file descriptor.
+
 2020-07-04  Nick Clifton  <nickc@redhat.com>
 
        Binutils 2.35 branch created.
index ac13d6dd5e9e7a632ffde80fa6dac1f67f619a3b..d857c0109c8d60a6b9af23f6913e3fc7b43b8bfa 100644 (file)
@@ -228,23 +228,16 @@ ctf_arc_write (const char *file, ctf_file_t ** ctf_files, size_t ctf_file_cnt,
 
   err = ctf_arc_write_fd (fd, ctf_files, ctf_file_cnt, names, threshold);
   if (err)
-    goto err;
+    goto err_close;
 
   if ((err = close (fd)) < 0)
-    {
-      ctf_dprintf ("ctf_arc_write(): Cannot close after writing to archive: "
-                  "%s\n", strerror (errno));
-      goto err_close;
-    }
-
- err:
-  close (fd);
-  if (err < 0)
-    unlink (file);
-
-  return err;
+    ctf_dprintf ("ctf_arc_write(): Cannot close after writing to archive: "
+                "%s\n", strerror (errno));
+  goto err;
 
  err_close:
+  (void) close (fd);
+ err:
   if (err < 0)
     unlink (file);