diff options
author | Simon Marchi <simon.marchi@ericsson.com> | 2015-01-30 13:54:50 -0500 |
---|---|---|
committer | Simon Marchi <simon.marchi@ericsson.com> | 2015-01-30 13:54:50 -0500 |
commit | afa269ae41673cd5cc5f50d683a0f2d275a643e8 (patch) | |
tree | cd6896ed98d9a264c3bcc8f97aefd8bc3504fc40 /gdb/varobj.c | |
parent | 9fc1d6863b1f46fd639afc3dfbe0b4c6d809ac05 (diff) | |
download | gdb-afa269ae41673cd5cc5f50d683a0f2d275a643e8.zip gdb-afa269ae41673cd5cc5f50d683a0f2d275a643e8.tar.gz gdb-afa269ae41673cd5cc5f50d683a0f2d275a643e8.tar.bz2 |
Free results of varobj_get_type and type_to_string
varobj_get_type and type_to_string return an allocated string, which is
not freed at a couple of places.
New in v2:
* Rename char * type to type_name.
* Free in all cases in update_type_if_necessary.
gdb/ChangeLog:
* mi/mi-cmd-var.c (mi_cmd_var_info_type): Free result of
varobj_get_type.
(varobj_update_one): Same.
* varobj.c (update_type_if_necessary): Free curr_type_str and
new_type_str.
(varobj_get_type): Specify in comment that the result needs to be
freed by the caller.
Diffstat (limited to 'gdb/varobj.c')
-rw-r--r-- | gdb/varobj.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/gdb/varobj.c b/gdb/varobj.c index a10560f..dad284d 100644 --- a/gdb/varobj.c +++ b/gdb/varobj.c @@ -972,7 +972,8 @@ varobj_add_child (struct varobj *var, struct varobj_item *item) } /* Obtain the type of an object Variable as a string similar to the one gdb - prints on the console. */ + prints on the console. The caller is responsible for freeing the string. + */ char * varobj_get_type (struct varobj *var) @@ -1289,11 +1290,16 @@ update_type_if_necessary (struct varobj *var, struct value *new_value) { struct type *new_type; char *curr_type_str, *new_type_str; + int type_name_changed; new_type = value_actual_type (new_value, 0, 0); new_type_str = type_to_string (new_type); curr_type_str = varobj_get_type (var); - if (strcmp (curr_type_str, new_type_str) != 0) + type_name_changed = strcmp (curr_type_str, new_type_str) != 0; + xfree (curr_type_str); + xfree (new_type_str); + + if (type_name_changed) { var->type = new_type; |