* [4/17] fix some BFD leaks
@ 2011-12-14 21:13 Tom Tromey
0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2011-12-14 21:13 UTC (permalink / raw)
To: gdb-patches
While writing the BFD refcount patch, I noticed a few places where we
open a BFD but then fail to close it.
This patch fixes the leaks.
Tom
From d04804ed12c0b77ddfb5a59cd9d53c8bfab08002 Mon Sep 17 00:00:00 2001
From: Tom Tromey <tromey@redhat.com>
Date: Mon, 5 Dec 2011 08:14:04 -0700
Subject: [PATCH 04/18] fix a couple of bfd leaks
* 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.
---
gdb/dsrec.c | 4 ++++
gdb/m32r-rom.c | 6 ++++++
gdb/remote-mips.c | 8 ++++++++
3 files changed, 18 insertions(+), 0 deletions(-)
diff --git a/gdb/dsrec.c b/gdb/dsrec.c
index 307bdd8..60591ba 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 d83f126..ea140a9 100644
--- a/gdb/m32r-rom.c
+++ b/gdb/m32r-rom.c
@@ -126,6 +126,7 @@ m32r_load (char *filename, int from_tty)
asection *s;
unsigned int i, data_count = 0;
struct timeval start_time, end_time;
+ struct cleanup *cleanup;
if (filename == NULL || filename[0] == 0)
filename = get_exec_file (1);
@@ -133,6 +134,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);
@@ -190,6 +192,7 @@ m32r_load (char *filename, int from_tty)
confused... */
clear_symtab_users (0);
+ do_cleanups (cleanup);
}
static void
@@ -432,6 +435,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");
@@ -523,6 +527,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)
@@ -564,6 +569,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 90490a6..87d4804 100644
--- a/gdb/remote-mips.c
+++ b/gdb/remote-mips.c
@@ -2788,6 +2788,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);
@@ -2799,9 +2800,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;
}
@@ -2855,6 +2858,7 @@ mips_load_srec (char *args)
send_srec (srec, reclen, abfd->start_address);
serial_flush_input (mips_desc);
+ do_cleanups (cleanup);
}
/*
@@ -3371,6 +3375,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);
@@ -3381,10 +3386,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;
}
@@ -3508,6 +3515,7 @@ pmon_load_fast (char *file)
pmon_end_download (final, bintotal);
}
+ do_cleanups (cleanup);
return;
}
--
1.7.6.4
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2011-12-14 21:10 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-14 21:13 [4/17] fix some BFD leaks Tom Tromey
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).