Patchwork [1/6] Free results of varobj_get_expression

login
register
mail settings
Submitter Simon Marchi
Date Jan. 29, 2015, 7:28 p.m.
Message ID <1422559716-5480-1-git-send-email-simon.marchi@ericsson.com>
Download mbox | patch
Permalink /patch/4844/
State New
Headers show

Comments

Simon Marchi - Jan. 29, 2015, 7:28 p.m.
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.
---
 gdb/mi/mi-cmd-var.c | 13 +++++++++++--
 gdb/varobj.c        |  3 ++-
 2 files changed, 13 insertions(+), 3 deletions(-)
Joel Brobecker - Jan. 30, 2015, 3:12 a.m.
On Thu, Jan 29, 2015 at 02:28:31PM -0500, Simon Marchi wrote:
> 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.

OK!

Thank you,
Simon Marchi - Jan. 30, 2015, 6:57 p.m.
On 15-01-29 10:12 PM, Joel Brobecker wrote:
> On Thu, Jan 29, 2015 at 02:28:31PM -0500, Simon Marchi wrote:
>> 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.
> 
> OK!
> 
> Thank you,

Pushed, thanks!

Patch

diff --git a/gdb/mi/mi-cmd-var.c b/gdb/mi/mi-cmd-var.c
index d873a17..d9b37f8 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 dad284d..6c9257d 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)