From d6ad71ba41afb220549d1c7fe61edd6bddd128ad Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Wed, 18 Jul 2012 19:38:39 +0000 Subject: [PATCH] * remote-mips.c (mips_load_srec): Use make_cleanup_bfd_close. (pmon_load_fast): Likewise. * m32r-rom.c (m32r_load): Use make_cleanup_bfd_close. (m32r_upload_command): Likewise. * dsrec.c (load_srec): Use make_cleanup_bfd_close. * solib-darwin.c (darwin_solib_get_all_image_info_addr_at_init): Use make_cleanup_bfd_close. --- gdb/ChangeLog | 10 ++++++++++ gdb/dsrec.c | 4 ++++ gdb/m32r-rom.c | 6 ++++++ gdb/remote-mips.c | 8 ++++++++ gdb/solib-darwin.c | 19 +++++++++++++------ 5 files changed, 41 insertions(+), 6 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index e07597ed758..29ccc0c95c8 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,13 @@ +2012-07-18 Tom Tromey + + * remote-mips.c (mips_load_srec): Use make_cleanup_bfd_close. + (pmon_load_fast): Likewise. + * m32r-rom.c (m32r_load): Use make_cleanup_bfd_close. + (m32r_upload_command): Likewise. + * dsrec.c (load_srec): Use make_cleanup_bfd_close. + * solib-darwin.c (darwin_solib_get_all_image_info_addr_at_init): + Use make_cleanup_bfd_close. + 2012-07-18 Tom Tromey * symfile.c (symfile_bfd_open): Don't copy name. Call diff --git a/gdb/dsrec.c b/gdb/dsrec.c index 54f29717360..8eefe1e0bf4 100644 --- a/gdb/dsrec.c +++ b/gdb/dsrec.c @@ -57,6 +57,7 @@ load_srec (struct serial *desc, const char *file, bfd_vma load_offset, int reclen; time_t start_time, end_time; unsigned long data_count = 0; + struct cleanup *cleanup; srec = (char *) alloca (maxrecsize + 1); @@ -67,9 +68,11 @@ load_srec (struct serial *desc, const char *file, bfd_vma load_offset, return; } + cleanup = make_cleanup_bfd_close (abfd); if (bfd_check_format (abfd, bfd_object) == 0) { printf_filtered (_("File is not an object file\n")); + do_cleanups (cleanup); return; } @@ -171,6 +174,7 @@ load_srec (struct serial *desc, const char *file, bfd_vma load_offset, serial_flush_input (desc); report_transfer_performance (data_count, start_time, end_time); + do_cleanups (cleanup); } /* diff --git a/gdb/m32r-rom.c b/gdb/m32r-rom.c index 92a73d0513e..9dbcd2609c8 100644 --- a/gdb/m32r-rom.c +++ b/gdb/m32r-rom.c @@ -125,6 +125,7 @@ m32r_load (char *filename, int from_tty) bfd *abfd; unsigned int data_count = 0; struct timeval start_time, end_time; + struct cleanup *cleanup; if (filename == NULL || filename[0] == 0) filename = get_exec_file (1); @@ -132,6 +133,7 @@ m32r_load (char *filename, int from_tty) abfd = gdb_bfd_ref (bfd_openr (filename, 0)); if (!abfd) error (_("Unable to open file %s."), filename); + cleanup = make_cleanup_bfd_close (abfd); if (bfd_check_format (abfd, bfd_object) == 0) error (_("File is not an object file.")); gettimeofday (&start_time, NULL); @@ -189,6 +191,7 @@ m32r_load (char *filename, int from_tty) confused... */ clear_symtab_users (0); + do_cleanups (cleanup); } static void @@ -435,6 +438,7 @@ m32r_upload_command (char *args, int from_tty) char buf[1024]; struct hostent *hostent; struct in_addr inet_addr; + struct cleanup *cleanup; /* First check to see if there's an ethernet port! */ monitor_printf ("ust\r"); @@ -526,6 +530,7 @@ m32r_upload_command (char *args, int from_tty) gettimeofday (&end_time, NULL); abfd = gdb_bfd_ref (bfd_openr (args, 0)); + cleanup = make_cleanup_bfd_close (abfd); if (abfd != NULL) { /* Download is done -- print section statistics. */ if (bfd_check_format (abfd, bfd_object) == 0) @@ -566,6 +571,7 @@ m32r_upload_command (char *args, int from_tty) confused... */ clear_symtab_users (0); + do_cleanups (cleanup); } /* Provide a prototype to silence -Wmissing-prototypes. */ diff --git a/gdb/remote-mips.c b/gdb/remote-mips.c index 30fd94835a9..5020d2aa73f 100644 --- a/gdb/remote-mips.c +++ b/gdb/remote-mips.c @@ -2784,6 +2784,7 @@ mips_load_srec (char *args) unsigned int i; unsigned int srec_frame = 200; int reclen; + struct cleanup *cleanup; static int hashmark = 1; buffer = alloca (srec_frame * 2 + 256); @@ -2795,9 +2796,11 @@ mips_load_srec (char *args) return; } + cleanup = make_cleanup_bfd_close (abfd); if (bfd_check_format (abfd, bfd_object) == 0) { printf_filtered ("File is not an object file\n"); + do_cleanups (cleanup); return; } @@ -2851,6 +2854,7 @@ mips_load_srec (char *args) send_srec (srec, reclen, abfd->start_address); serial_flush_input (mips_desc); + do_cleanups (cleanup); } /* @@ -3367,6 +3371,7 @@ pmon_load_fast (char *file) int bintotal = 0; int final = 0; int finished = 0; + struct cleanup *cleanup; buffer = (char *) xmalloc (MAXRECSIZE + 1); binbuf = (unsigned char *) xmalloc (BINCHUNK); @@ -3377,10 +3382,12 @@ pmon_load_fast (char *file) printf_filtered ("Unable to open file %s\n", file); return; } + cleanup = make_cleanup_bfd_close (abfd); if (bfd_check_format (abfd, bfd_object) == 0) { printf_filtered ("File is not an object file\n"); + do_cleanups (cleanup); return; } @@ -3504,6 +3511,7 @@ pmon_load_fast (char *file) pmon_end_download (final, bintotal); } + do_cleanups (cleanup); return; } diff --git a/gdb/solib-darwin.c b/gdb/solib-darwin.c index 242f8cc1f6b..8d8da7e604c 100644 --- a/gdb/solib-darwin.c +++ b/gdb/solib-darwin.c @@ -357,6 +357,7 @@ darwin_solib_get_all_image_info_addr_at_init (struct darwin_info *info) gdb_byte *interp_name; CORE_ADDR load_addr = 0; bfd *dyld_bfd = NULL; + struct cleanup *cleanup; /* This method doesn't work with an attached process. */ if (current_inferior ()->attach_flag) @@ -367,24 +368,30 @@ darwin_solib_get_all_image_info_addr_at_init (struct darwin_info *info) if (!interp_name) return; + cleanup = make_cleanup (null_cleanup, NULL); + /* Create a bfd for the interpreter. */ dyld_bfd = gdb_bfd_ref (bfd_openr (interp_name, gnutarget)); if (dyld_bfd) { bfd *sub; + make_cleanup_bfd_close (dyld_bfd); sub = bfd_mach_o_fat_extract (dyld_bfd, bfd_object, gdbarch_bfd_arch_info (target_gdbarch)); if (sub) - dyld_bfd = sub; - else { - gdb_bfd_unref (dyld_bfd); - dyld_bfd = NULL; + dyld_bfd = gdb_bfd_ref (sub); + make_cleanup_bfd_close (sub); } + else + dyld_bfd = NULL; } if (!dyld_bfd) - return; + { + do_cleanups (cleanup); + return; + } /* We find the dynamic linker's base address by examining the current pc (which should point at the entry point for the @@ -396,7 +403,7 @@ darwin_solib_get_all_image_info_addr_at_init (struct darwin_info *info) info->all_image_addr = lookup_symbol_from_bfd (dyld_bfd, "_dyld_all_image_infos"); - gdb_bfd_unref (dyld_bfd); + do_cleanups (cleanup); if (info->all_image_addr == 0) return; -- 2.30.2