Free results of varobj_get_type and type_to_string
authorSimon Marchi <simon.marchi@ericsson.com>
Fri, 30 Jan 2015 18:54:50 +0000 (13:54 -0500)
committerSimon Marchi <simon.marchi@ericsson.com>
Fri, 30 Jan 2015 18:54:50 +0000 (13:54 -0500)
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.

gdb/ChangeLog
gdb/mi/mi-cmd-var.c
gdb/varobj.c

index af5da9bfb0d8ce855dba1b3a842c9058a7bd8660..3f3f3f389c1b1e38695fd412e1d1d9b9dcc3acde 100644 (file)
@@ -1,3 +1,13 @@
+2015-01-30  Simon Marchi  <simon.marchi@ericsson.com>
+
+       * 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.
+
 2015-01-29  Doug Evans  <dje@google.com>
 
        PR symtab/17890
index 01838b1946d0ed687759d9ed6a7d97a401670520..d873a177649d8b35f430112b3868615436477113 100644 (file)
@@ -447,14 +447,18 @@ mi_cmd_var_info_type (char *command, char **argv, int argc)
 {
   struct ui_out *uiout = current_uiout;
   struct varobj *var;
+  char *type_name;
 
   if (argc != 1)
     error (_("-var-info-type: Usage: NAME."));
 
   /* Get varobj handle, if a valid var obj name was specified.  */
   var = varobj_get_handle (argv[0]);
+  type_name = varobj_get_type (var);
 
-  ui_out_field_string (uiout, "type", varobj_get_type (var));
+  ui_out_field_string (uiout, "type", type_name);
+
+  xfree (type_name);
 }
 
 void
@@ -765,7 +769,12 @@ varobj_update_one (struct varobj *var, enum print_values print_values,
        }
 
       if (r->type_changed)
-       ui_out_field_string (uiout, "new_type", varobj_get_type (r->varobj));
+       {
+         char *type_name = varobj_get_type (r->varobj);
+
+         ui_out_field_string (uiout, "new_type", type_name);
+         xfree (type_name);
+       }
 
       if (r->type_changed || r->children_changed)
        ui_out_field_int (uiout, "new_num_children", 
index a10560f9fa98a22f7917dd3531bcc3d0e5f847fe..dad284d67a5690f5832531925b82abd2f96d7ee3 100644 (file)
@@ -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;
 
This page took 0.028212 seconds and 4 git commands to generate.