diff mbox

[OB] Add missing cleanup in exec_file_locate_attach

Message ID 1455728537-27577-1-git-send-email-gbenson@redhat.com
State New
Headers show

Commit Message

Gary Benson Feb. 17, 2016, 5:02 p.m. UTC
Hi all,

exec_file_locate_attach allocates memory for full_exec_path (using
either exec_file_find, source_full_path_of or xstrdup) but this
memory is never freed.  This commit adds the necessary cleanup.

Pushed as obvious.

Cheers,
Gary

--
gdb/ChangeLog:

	* exec.c (exec_file_locate_attach): Add missing cleanup.
---
 gdb/ChangeLog |    4 ++++
 gdb/exec.c    |    5 +++++
 2 files changed, 9 insertions(+), 0 deletions(-)

Comments

Gary Benson Feb. 17, 2016, 5:05 p.m. UTC | #1
Gary Benson wrote:
> exec_file_locate_attach allocates memory for full_exec_path (using
> either exec_file_find, source_full_path_of or xstrdup) but this
> memory is never freed.  This commit adds the necessary cleanup.

This isn't the fix I talked about, just something I found on the way.
I didn't mean to copy everyone on this little patch :)  The real fix
is coming tomorrow morning.

Cheers,
Gary
Luis Machado Feb. 17, 2016, 6:10 p.m. UTC | #2
On 02/17/2016 03:02 PM, Gary Benson wrote:
> Hi all,
>
> exec_file_locate_attach allocates memory for full_exec_path (using
> either exec_file_find, source_full_path_of or xstrdup) but this
> memory is never freed.  This commit adds the necessary cleanup.
>
> Pushed as obvious.


Well spotted!
Gary Benson Feb. 18, 2016, 9:54 a.m. UTC | #3
Luis Machado wrote:
> On 02/17/2016 03:02 PM, Gary Benson wrote:
> > exec_file_locate_attach allocates memory for full_exec_path (using
> > either exec_file_find, source_full_path_of or xstrdup) but this
> > memory is never freed.  This commit adds the necessary cleanup.
> > 
> > Pushed as obvious.
> 
> Well spotted!

Thanks :)

Cheers,
Gary
diff mbox

Patch

diff --git a/gdb/exec.c b/gdb/exec.c
index 23c89c2..0b8c077 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -141,6 +141,7 @@  void
 exec_file_locate_attach (int pid, int from_tty)
 {
   char *exec_file, *full_exec_path = NULL;
+  struct cleanup *old_chain;
 
   /* Do nothing if we already have an executable filename.  */
   exec_file = (char *) get_exec_file (0);
@@ -170,8 +171,12 @@  exec_file_locate_attach (int pid, int from_tty)
 	full_exec_path = xstrdup (exec_file);
     }
 
+  old_chain = make_cleanup (xfree, full_exec_path);
+
   exec_file_attach (full_exec_path, from_tty);
   symbol_file_add_main (full_exec_path, from_tty);
+
+  do_cleanups (old_chain);
 }
 
 /* Set FILENAME as the new exec file.