PR23781, _bfd_pe_bfd_copy_private_bfd_data_common memory leak
authorAlan Modra <amodra@gmail.com>
Tue, 16 Oct 2018 04:53:20 +0000 (15:23 +1030)
committerAlan Modra <amodra@gmail.com>
Tue, 16 Oct 2018 06:11:57 +0000 (16:41 +1030)
PR 23781
* peXXigen.c (_bfd_XX_bfd_copy_private_bfd_data_common): Free data
before returning.

bfd/ChangeLog
bfd/peXXigen.c

index 5031fff93d1a299b5a1c309c84dcdb559cb46c67..ab665ed08ec385fa070a34d6d43b13afe8606109 100644 (file)
@@ -1,3 +1,9 @@
+2018-10-16  Alan Modra  <amodra@gmail.com>
+
+       PR 23781
+       * peXXigen.c (_bfd_XX_bfd_copy_private_bfd_data_common): Free data
+       before returning.
+
 2018-10-16  Alan Modra  <amodra@gmail.com>
 
        PR 23534
index 1645ef4b77cb682e2593c633b4feaad61306a04a..1271d4edbbe54d17361f2330399eb421ad5a31c3 100644 (file)
@@ -2993,6 +2993,7 @@ _bfd_XX_bfd_copy_private_bfd_data_common (bfd * ibfd, bfd * obfd)
                   "exceeds space left in section (%" PRIx64 ")"),
                 obfd, ope->pe_opthdr.DataDirectory[PE_DEBUG_DATA].Size,
                 (uint64_t) (section->size - (addr - section->vma)));
+             free (data);
              return FALSE;
            }
          /* PR 23110.  */
@@ -3002,6 +3003,7 @@ _bfd_XX_bfd_copy_private_bfd_data_common (bfd * ibfd, bfd * obfd)
              _bfd_error_handler
                (_("%pB: Data Directory size (%#lx) is negative"),
                 obfd, ope->pe_opthdr.DataDirectory[PE_DEBUG_DATA].Size);
+             free (data);
              return FALSE;
            }
 
@@ -3030,8 +3032,10 @@ _bfd_XX_bfd_copy_private_bfd_data_common (bfd * ibfd, bfd * obfd)
          if (!bfd_set_section_contents (obfd, section, data, 0, section->size))
            {
              _bfd_error_handler (_("failed to update file offsets in debug directory"));
+             free (data);
              return FALSE;
            }
+         free (data);
        }
       else if (section)
        {