From: Simon Marchi Date: Fri, 30 Jan 2015 18:56:56 +0000 (-0500) Subject: Free results of varobj_get_expression X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ca83fa81892ab61870295cb5397c59daff1a55e0;p=binutils-gdb.git Free results of varobj_get_expression varobj_get_expression returns an allocated string, which must be freed by the caller. gdb/ChangeLog: * mi-cmd-var.c (print_varobj): Free varobj_get_expression result. (mi_cmd_var_info_expression): Same. * varobj.c (varobj_get_expression): Mention in the comment that the result must by freed by the caller. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 3f3f3f389c1..6738267ec6f 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,11 @@ +2015-01-30 Simon Marchi + + * mi-cmd-var.c (print_varobj): Free varobj_get_expression + result. + (mi_cmd_var_info_expression): Same. + * varobj.c (varobj_get_expression): Mention in the comment that + the result must by freed by the caller. + 2015-01-30 Simon Marchi * mi/mi-cmd-var.c (mi_cmd_var_info_type): Free result of diff --git a/gdb/mi/mi-cmd-var.c b/gdb/mi/mi-cmd-var.c index d873a177649..d9b37f85f5b 100644 --- a/gdb/mi/mi-cmd-var.c +++ b/gdb/mi/mi-cmd-var.c @@ -55,7 +55,12 @@ print_varobj (struct varobj *var, enum print_values print_values, ui_out_field_string (uiout, "name", varobj_get_objname (var)); if (print_expression) - ui_out_field_string (uiout, "exp", varobj_get_expression (var)); + { + char *exp = varobj_get_expression (var); + + ui_out_field_string (uiout, "exp", exp); + xfree (exp); + } ui_out_field_int (uiout, "numchild", varobj_get_num_children (var)); if (mi_print_value_p (var, print_values)) @@ -485,6 +490,7 @@ mi_cmd_var_info_expression (char *command, char **argv, int argc) struct ui_out *uiout = current_uiout; const struct language_defn *lang; struct varobj *var; + char *exp; if (argc != 1) error (_("-var-info-expression: Usage: NAME.")); @@ -495,7 +501,10 @@ mi_cmd_var_info_expression (char *command, char **argv, int argc) lang = varobj_get_language (var); ui_out_field_string (uiout, "lang", lang->la_natural_name); - ui_out_field_string (uiout, "exp", varobj_get_expression (var)); + + exp = varobj_get_expression (var); + ui_out_field_string (uiout, "exp", exp); + xfree (exp); } void diff --git a/gdb/varobj.c b/gdb/varobj.c index dad284d67a5..6c9257ddeba 100644 --- a/gdb/varobj.c +++ b/gdb/varobj.c @@ -492,7 +492,8 @@ varobj_get_objname (struct varobj *var) return var->obj_name; } -/* Given the handle, return the expression represented by the object. */ +/* Given the handle, return the expression represented by the object. The + result must be freed by the caller. */ char * varobj_get_expression (struct varobj *var)