Fix memory leak in add_symbol_file_command
[deliverable/binutils-gdb.git] / binutils / objcopy.c
index 4f481905ee9cdc853a3f72acdd4b32437a194b30..23a949d1ad695cf5fd5ff9bb31568770abb8ba2e 100644 (file)
@@ -2650,14 +2650,15 @@ copy_object (bfd *ibfd, bfd *obfd, const bfd_arch_info_type *input_arch)
              continue;
            }
 
-         bfd_byte * contents = xmalloc (size);
-         if (bfd_get_section_contents (ibfd, osec, contents, 0, size))
+         bfd_byte *contents;
+         if (bfd_malloc_and_get_section (ibfd, osec, &contents))
            {
              if (fwrite (contents, 1, size, f) != size)
                {
                  non_fatal (_("error writing section contents to %s (error: %s)"),
                             pdump->filename,
                             strerror (errno));
+                 free (contents);
                  return FALSE;
                }
            }
This page took 0.022896 seconds and 4 git commands to generate.