This is the mail archive of the gdb-cvs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] gdb: Add cleanup to avoid memory leak on error.


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=c1b009eed88d41b22c9faf68d0dc15967292f6c9

commit c1b009eed88d41b22c9faf68d0dc15967292f6c9
Author: Andrew Burgess <andrew.burgess@embecosm.com>
Date:   Thu May 21 00:51:23 2015 +0200

    gdb: Add cleanup to avoid memory leak on error.
    
    Use cleanup to avoid leaking memory if an error occurs during tui
    start up.
    
    gdb/ChangeLog:
    
    	* tui/tui-layout.c (tui_set_layout_for_display_command): Ensure
    	buf_ptr is freed.

Diff:
---
 gdb/ChangeLog        | 5 +++++
 gdb/tui/tui-layout.c | 4 +++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 3c80d3a..f9b91d5 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
 2015-05-21  Andrew Burgess  <andrew.burgess@embecosm.com>
 
+	* tui/tui-layout.c (tui_set_layout_for_display_command): Ensure
+	buf_ptr is freed.
+
+2015-05-21  Andrew Burgess  <andrew.burgess@embecosm.com>
+
 	* tui/tui-layout.c (tui_layout_command): Move call to tui_enable
 	into ...
 	(tui_set_layout_for_display_command): ...here, before calling
diff --git a/gdb/tui/tui-layout.c b/gdb/tui/tui-layout.c
index abd9810..0255c39 100644
--- a/gdb/tui/tui-layout.c
+++ b/gdb/tui/tui-layout.c
@@ -409,10 +409,12 @@ tui_set_layout_by_name (const char *layout_name)
       char *buf_ptr;
       enum tui_layout_type new_layout = UNDEFINED_LAYOUT;
       enum tui_layout_type cur_layout = tui_current_layout ();
+      struct cleanup *old_chain;
 
       buf_ptr = (char *) xstrdup (layout_name);
       for (i = 0; (i < strlen (layout_name)); i++)
 	buf_ptr[i] = toupper (buf_ptr[i]);
+      old_chain = make_cleanup (xfree, buf_ptr);
 
       /* First check for ambiguous input.  */
       if (strlen (buf_ptr) <= 1 && *buf_ptr == 'S')
@@ -450,7 +452,7 @@ tui_set_layout_by_name (const char *layout_name)
 	      tui_set_layout (new_layout);
 	    }
 	}
-      xfree (buf_ptr);
+      do_cleanups (old_chain);
     }
   else
     status = TUI_FAILURE;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]