aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2016-08-03 08:27:56 -0600
committerTom Tromey <tom@tromey.com>2016-08-03 09:04:08 -0600
commitd10153cfc6cb319a75ceb3e3d34ac30efa17e518 (patch)
treed2336732b4fa9c37f5d09253c793764efc7c438e /gdb
parent8d2a0a14e53945eb260c08752654bd03a240ecf7 (diff)
downloadgdb-d10153cfc6cb319a75ceb3e3d34ac30efa17e518.zip
gdb-d10153cfc6cb319a75ceb3e3d34ac30efa17e518.tar.gz
gdb-d10153cfc6cb319a75ceb3e3d34ac30efa17e518.tar.bz2
Avoid potential memory leak in find_frame_funname
The PR 18565 thread pointed out that, if cp_remove_params can throw (we aren't quite sure), then find_frame_funname could leak some memory. This patch avoids any potential issue by rearranging some code in find_frame_funname. Built and regtested on x86-64 Fedora 24. 2016-08-03 Tom Tromey <tom@tromey.com> * stack.c (find_frame_funname): Avoid any possible leak in case cp_remove_params can throw.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog5
-rw-r--r--gdb/stack.c16
2 files changed, 15 insertions, 6 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 6b2fb9c..48ecd67 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
2016-08-03 Tom Tromey <tom@tromey.com>
+ * stack.c (find_frame_funname): Avoid any possible leak in case
+ cp_remove_params can throw.
+
+2016-08-03 Tom Tromey <tom@tromey.com>
+
* NEWS: Mention new Python breakpoint events.
2016-08-02 Tom Tromey <tom@tromey.com>
diff --git a/gdb/stack.c b/gdb/stack.c
index b9e74df..e890949 100644
--- a/gdb/stack.c
+++ b/gdb/stack.c
@@ -1101,7 +1101,8 @@ find_frame_funname (struct frame_info *frame, char **funname,
}
else
{
- *funname = xstrdup (SYMBOL_PRINT_NAME (func));
+ const char *print_name = SYMBOL_PRINT_NAME (func);
+
*funlang = SYMBOL_LANGUAGE (func);
if (funcp)
*funcp = func;
@@ -1112,14 +1113,17 @@ find_frame_funname (struct frame_info *frame, char **funname,
stored in the symbol table, but we stored a version
with DMGL_PARAMS turned on, and here we don't want to
display parameters. So remove the parameters. */
- char *func_only = cp_remove_params (*funname);
+ char *func_only = cp_remove_params (print_name);
if (func_only)
- {
- xfree (*funname);
- *funname = func_only;
- }
+ *funname = func_only;
}
+
+ /* If we didn't hit the C++ case above, set *funname here.
+ This approach is taken to avoid having to install a
+ cleanup in case cp_remove_params can throw. */
+ if (*funname == NULL)
+ *funname = xstrdup (print_name);
}
}
else