This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH] Fix FIXME: xstrdup should not be here
- From: Yao Qi <yao at codesourcery dot com>
- To: <gdb-patches at sourceware dot org>
- Date: Fri, 30 Aug 2013 09:27:26 +0800
- Subject: [PATCH] Fix FIXME: xstrdup should not be here
- Authentication-results: sourceware.org; auth=none
Hi,
This FIXME goes into my eyes, when I am about to modify something here,
/* Name is allocated by name_of_child. */
/* FIXME: xstrdup should not be here. */
This FIXME was introduced in the python pretty-pretter patches.
Python pretty-printing [6/6]
https://sourceware.org/ml/gdb-patches/2009-05/msg00467.html
create_child_with_value is called in two paths,
1. varobj_list_children -> create_child -> create_child_with_value,
2. install_dynamic_child -> install_dynamic_child -> varobj_add_child
-> create_child_with_value
In path #1, 'name' is allocated by name_of_child, as the original
comment said, we don't have to duplicate NAME in
create_child_with_value. In path #2, 'name' is got from
PyArg_ParseTuple, and we have to duplicate NAME.
This patch removes the call to xstrdup in create_child_with_value
and call xstrudp in update_dynamic_varobj_children (path #2).
Regression tested on x86_64-linux. It depends on patch
Convert 'name' of 'struct varobj' to 'const char *'.
https://sourceware.org/ml/gdb-patches/2013-08/msg00895.html
gdb:
2013-08-29 Yao Qi <yao@codesourcery.com>
* varobj.c (update_dynamic_varobj_children): Duplicate 'name'
and pass it to install_dynamic_child.
(create_child_with_value): Update comments. Don't dpulicate
'name'.
---
gdb/varobj.c | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/gdb/varobj.c b/gdb/varobj.c
index 55cd83e..e76ea61 100644
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -1225,7 +1225,8 @@ update_dynamic_varobj_children (struct varobj *var,
can_mention ? type_changed : NULL,
can_mention ? new : NULL,
can_mention ? unchanged : NULL,
- can_mention ? cchanged : NULL, i, name, v);
+ can_mention ? cchanged : NULL, i,
+ xstrdup (name), v);
do_cleanups (inner);
}
else
@@ -2439,9 +2440,8 @@ create_child_with_value (struct varobj *parent, int index, const char *name,
child = new_variable ();
- /* Name is allocated by name_of_child. */
- /* FIXME: xstrdup should not be here. */
- child->name = xstrdup (name);
+ /* NAME is allocated by caller. */
+ child->name = name;
child->index = index;
child->parent = parent;
child->root = parent->root;
--
1.7.7.6