public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: Binutils <binutils@sourceware.org>
Subject: [patch] Fix PowerPC targets minor memory leaks found by Coverity
Date: Fri, 24 Jan 2014 13:38:00 -0000	[thread overview]
Message-ID: <20140124133831.GA27933@host2.jankratochvil.net> (raw)

Hi,

I find reasons of each of the patch chunk obvious but I did not test the patch
in any way.


Regards,
Jan


bfd/
2014-01-24  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* coff-rs6000.c (xcoff_write_archive_contents_big): Free OFFSETS in
	return paths.  Three times.
	* elf32-ppc.c (ppc_elf_relax_section): Free FIXUPS in error_return
	return path.
	* elf64-ppc.c (ppc64_elf_link_hash_table_create): Free HTAB in all
	return paths.
	(ppc64_elf_tls_optimize): Free TOC_REF in return path.
	(ppc64_elf_edit_toc): Free USED in return path.

diff --git a/bfd/coff-rs6000.c b/bfd/coff-rs6000.c
index 1170c7f..2b5f952 100644
--- a/bfd/coff-rs6000.c
+++ b/bfd/coff-rs6000.c
@@ -2404,7 +2404,10 @@ xcoff_write_archive_contents_big (bfd *abfd)
       PRINT20 (ahdrp->nextoff, iterator.next.offset);
 
       if (!do_pad (abfd, iterator.current.leading_padding))
-	return FALSE;
+	{
+	  free (offsets);
+	  return FALSE;
+	}
 
       BFD_ASSERT (iterator.current.offset == bfd_tell (abfd));
       namlen = iterator.current.padded_namlen;
@@ -2414,7 +2417,10 @@ xcoff_write_archive_contents_big (bfd *abfd)
 	  || bfd_seek (iterator.current.member, 0, SEEK_SET) != 0
 	  || !do_copy (abfd, iterator.current.member)
 	  || !do_pad (abfd, iterator.current.trailing_padding))
-	return FALSE;
+	{
+	  free (offsets);
+	  return FALSE;
+	}
 
       offsets[i] = iterator.current.offset;
       prevoff = iterator.current.offset;
@@ -2459,7 +2465,10 @@ xcoff_write_archive_contents_big (bfd *abfd)
   member_table_size += member_table_size & 1;
   member_table = bfd_zmalloc (member_table_size);
   if (member_table == NULL)
-    return FALSE;
+    {
+      free (offsets);
+      return FALSE;
+    }
 
   hdr = (struct xcoff_ar_hdr_big *) member_table;
 
diff --git a/bfd/elf32-ppc.c b/bfd/elf32-ppc.c
index 61c45d8..fe4f37b 100644
--- a/bfd/elf32-ppc.c
+++ b/bfd/elf32-ppc.c
@@ -7134,6 +7134,13 @@ ppc_elf_relax_section (bfd *abfd,
   return TRUE;
 
  error_return:
+  do
+    {
+      struct one_fixup *f = fixups;
+      fixups = fixups->next;
+      free (f);
+    }
+  while (fixups);
   if (isymbuf != NULL && (unsigned char *) isymbuf != symtab_hdr->contents)
     free (isymbuf);
   if (contents != NULL
diff --git a/bfd/elf64-ppc.c b/bfd/elf64-ppc.c
index c97a39e..9be8bfc 100644
--- a/bfd/elf64-ppc.c
+++ b/bfd/elf64-ppc.c
@@ -4168,19 +4168,31 @@ ppc64_elf_link_hash_table_create (bfd *abfd)
   /* Init the stub hash table too.  */
   if (!bfd_hash_table_init (&htab->stub_hash_table, stub_hash_newfunc,
 			    sizeof (struct ppc_stub_hash_entry)))
-    return NULL;
+    {
+      _bfd_elf_link_hash_table_free ((struct bfd_link_hash_table *) htab);
+      return NULL;
+    }
 
   /* And the branch hash table.  */
   if (!bfd_hash_table_init (&htab->branch_hash_table, branch_hash_newfunc,
 			    sizeof (struct ppc_branch_hash_entry)))
-    return NULL;
+    {
+      bfd_hash_table_free (&htab->stub_hash_table);
+      _bfd_elf_link_hash_table_free ((struct bfd_link_hash_table *) htab);
+      return NULL;
+    }
 
   htab->tocsave_htab = htab_try_create (1024,
 					tocsave_htab_hash,
 					tocsave_htab_eq,
 					NULL);
   if (htab->tocsave_htab == NULL)
-    return NULL;
+    {
+      bfd_hash_table_free (&htab->branch_hash_table);
+      bfd_hash_table_free (&htab->stub_hash_table);
+      _bfd_elf_link_hash_table_free ((struct bfd_link_hash_table *) htab);
+      return NULL;
+    }
 
   /* Initializing two fields of the union is just cosmetic.  We really
      only care about glist, but when compiled on a 32-bit host the
@@ -8073,7 +8085,10 @@ ppc64_elf_tls_optimize (struct bfd_link_info *info)
 	      relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL,
 						    info->keep_memory);
 	      if (relstart == NULL)
-		return FALSE;
+		{
+		  free (toc_ref);
+		  return FALSE;
+		}
 
 	      relend = relstart + sec->reloc_count;
 	      for (rel = relstart; rel < relend; rel++)
@@ -8781,7 +8796,10 @@ ppc64_elf_edit_toc (struct bfd_link_info *info)
 	  relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL,
 						info->keep_memory);
 	  if (relstart == NULL)
-	    goto error_ret;
+	    {
+	      free (used);
+	      goto error_ret;
+	    }
 
 	  /* Mark toc entries referenced as used.  */
 	  do

             reply	other threads:[~2014-01-24 13:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-24 13:38 Jan Kratochvil [this message]
2014-01-27  0:12 ` Alan Modra
2014-02-04 19:19   ` [commit] " Jan Kratochvil

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140124133831.GA27933@host2.jankratochvil.net \
    --to=jan.kratochvil@redhat.com \
    --cc=binutils@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).