aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@ericsson.com>2017-09-16 13:45:55 +0200
committerSimon Marchi <simon.marchi@ericsson.com>2017-09-16 13:45:55 +0200
commitbd77e8ff276864d6622f2433b8a499bf4332fa65 (patch)
tree2938620ea6db4ddc79a580660fb73574d5cab299 /gdb
parentc4dfafabc575f4995a5aa18241adc275e63c846c (diff)
downloadgdb-bd77e8ff276864d6622f2433b8a499bf4332fa65.zip
gdb-bd77e8ff276864d6622f2433b8a499bf4332fa65.tar.gz
gdb-bd77e8ff276864d6622f2433b8a499bf4332fa65.tar.bz2
mi_load_progress: Use unique_ptr to manage ui_out lifetime
In mi_load_progress, we xfree a ui_out object. Because ui_out is not trivially destructible, it should be freed with delete. This patch makes use of a unique_ptr to do it. gdb/ChangeLog: * mi/mi-main.c (mi_load_progress): Make uiout variable a unique_ptr. diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c index 0ee2605..0359dc1 100644 --- a/gdb/mi/mi-main.c +++ b/gdb/mi/mi-main.c @@ -2325,7 +2325,6 @@ mi_load_progress (const char *section_name, static char *previous_sect_name = NULL; int new_section; struct ui_out *saved_uiout; - struct ui_out *uiout; struct mi_interp *mi = (struct mi_interp *) current_interpreter (); /* This function is called through deprecated_show_load_progress @@ -2333,17 +2332,19 @@ mi_load_progress (const char *section_name, of this function. */ saved_uiout = current_uiout; + std::unique_ptr<ui_out> uiout; + if (current_interp_named_p (INTERP_MI) || current_interp_named_p (INTERP_MI2)) - current_uiout = mi_out_new (2); + uiout.reset (mi_out_new (2)); else if (current_interp_named_p (INTERP_MI1)) - current_uiout = mi_out_new (1); + uiout.reset (mi_out_new (1)); else if (current_interp_named_p (INTERP_MI3)) - current_uiout = mi_out_new (3); + uiout.reset (mi_out_new (3)); else return; - uiout = current_uiout; + current_uiout = uiout.get (); new_section = (previous_sect_name ? strcmp (previous_sect_name, section_name) : 1); @@ -2356,12 +2357,12 @@ mi_load_progress (const char *section_name, fputs_unfiltered (current_token, mi->raw_stdout); fputs_unfiltered ("+download", mi->raw_stdout); { - ui_out_emit_tuple tuple_emitter (uiout, NULL); + ui_out_emit_tuple tuple_emitter (uiout.get (), NULL); uiout->field_string ("section", section_name); uiout->field_int ("section-size", total_section); uiout->field_int ("total-size", grand_total); } - mi_out_put (uiout, mi->raw_stdout); + mi_out_put (uiout.get (), mi->raw_stdout); fputs_unfiltered ("\n", mi->raw_stdout); gdb_flush (mi->raw_stdout); } @@ -2374,19 +2375,18 @@ mi_load_progress (const char *section_name, fputs_unfiltered (current_token, mi->raw_stdout); fputs_unfiltered ("+download", mi->raw_stdout); { - ui_out_emit_tuple tuple_emitter (uiout, NULL); + ui_out_emit_tuple tuple_emitter (uiout.get (), NULL); uiout->field_string ("section", section_name); uiout->field_int ("section-sent", sent_so_far); uiout->field_int ("section-size", total_section); uiout->field_int ("total-sent", total_sent); uiout->field_int ("total-size", grand_total); } - mi_out_put (uiout, mi->raw_stdout); + mi_out_put (uiout.get (), mi->raw_stdout); fputs_unfiltered ("\n", mi->raw_stdout); gdb_flush (mi->raw_stdout); } - xfree (uiout); current_uiout = saved_uiout; }
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog5
-rw-r--r--gdb/mi/mi-main.c20
2 files changed, 15 insertions, 10 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index c4f55a8..a7a87ee 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2017-09-16 Simon Marchi <simon.marchi@ericsson.com>
+
+ * mi/mi-main.c (mi_load_progress): Make uiout variable
+ a unique_ptr.
+
2017-09-15 Pedro Alves <palves@redhat.com>
* compile/compile-c-types.c (convert_enum, convert_int)
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 0ee2605..0359dc1 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -2325,7 +2325,6 @@ mi_load_progress (const char *section_name,
static char *previous_sect_name = NULL;
int new_section;
struct ui_out *saved_uiout;
- struct ui_out *uiout;
struct mi_interp *mi = (struct mi_interp *) current_interpreter ();
/* This function is called through deprecated_show_load_progress
@@ -2333,17 +2332,19 @@ mi_load_progress (const char *section_name,
of this function. */
saved_uiout = current_uiout;
+ std::unique_ptr<ui_out> uiout;
+
if (current_interp_named_p (INTERP_MI)
|| current_interp_named_p (INTERP_MI2))
- current_uiout = mi_out_new (2);
+ uiout.reset (mi_out_new (2));
else if (current_interp_named_p (INTERP_MI1))
- current_uiout = mi_out_new (1);
+ uiout.reset (mi_out_new (1));
else if (current_interp_named_p (INTERP_MI3))
- current_uiout = mi_out_new (3);
+ uiout.reset (mi_out_new (3));
else
return;
- uiout = current_uiout;
+ current_uiout = uiout.get ();
new_section = (previous_sect_name ?
strcmp (previous_sect_name, section_name) : 1);
@@ -2356,12 +2357,12 @@ mi_load_progress (const char *section_name,
fputs_unfiltered (current_token, mi->raw_stdout);
fputs_unfiltered ("+download", mi->raw_stdout);
{
- ui_out_emit_tuple tuple_emitter (uiout, NULL);
+ ui_out_emit_tuple tuple_emitter (uiout.get (), NULL);
uiout->field_string ("section", section_name);
uiout->field_int ("section-size", total_section);
uiout->field_int ("total-size", grand_total);
}
- mi_out_put (uiout, mi->raw_stdout);
+ mi_out_put (uiout.get (), mi->raw_stdout);
fputs_unfiltered ("\n", mi->raw_stdout);
gdb_flush (mi->raw_stdout);
}
@@ -2374,19 +2375,18 @@ mi_load_progress (const char *section_name,
fputs_unfiltered (current_token, mi->raw_stdout);
fputs_unfiltered ("+download", mi->raw_stdout);
{
- ui_out_emit_tuple tuple_emitter (uiout, NULL);
+ ui_out_emit_tuple tuple_emitter (uiout.get (), NULL);
uiout->field_string ("section", section_name);
uiout->field_int ("section-sent", sent_so_far);
uiout->field_int ("section-size", total_section);
uiout->field_int ("total-sent", total_sent);
uiout->field_int ("total-size", grand_total);
}
- mi_out_put (uiout, mi->raw_stdout);
+ mi_out_put (uiout.get (), mi->raw_stdout);
fputs_unfiltered ("\n", mi->raw_stdout);
gdb_flush (mi->raw_stdout);
}
- xfree (uiout);
current_uiout = saved_uiout;
}