From patchwork Sun Sep 10 12:55:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 22789 Received: (qmail 95155 invoked by alias); 10 Sep 2017 12:55:37 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 95144 invoked by uid 89); 10 Sep 2017 12:55:36 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: sessmg22.ericsson.net Received: from sessmg22.ericsson.net (HELO sessmg22.ericsson.net) (193.180.251.58) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 10 Sep 2017 12:55:34 +0000 Received: from ESESSHC002.ericsson.se (Unknown_Domain [153.88.183.24]) by sessmg22.ericsson.net (Symantec Mail Security) with SMTP id 1F.2D.20899.34635B95; Sun, 10 Sep 2017 14:55:31 +0200 (CEST) Received: from EUR02-HE1-obe.outbound.protection.outlook.com (153.88.183.145) by oa.msg.ericsson.com (153.88.183.24) with Microsoft SMTP Server (TLS) id 14.3.352.0; Sun, 10 Sep 2017 14:55:30 +0200 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=simon.marchi@ericsson.com; Received: from elxacz23q12.localdomain (95.204.106.138) by AM3PR07MB308.eurprd07.prod.outlook.com (2a01:111:e400:881b::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.56.4; Sun, 10 Sep 2017 12:55:29 +0000 From: Simon Marchi To: CC: Simon Marchi Subject: [PATCH 1/2] mi_load_progress: Use unique_ptr to manage ui_out lifetime Date: Sun, 10 Sep 2017 14:55:19 +0200 Message-ID: <1505048120-32214-1-git-send-email-simon.marchi@ericsson.com> MIME-Version: 1.0 X-ClientProxiedBy: HE1P189CA0028.EURP189.PROD.OUTLOOK.COM (2603:10a6:7:53::41) To AM3PR07MB308.eurprd07.prod.outlook.com (2a01:111:e400:881b::19) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e10188f4-d9c1-488b-9cfe-08d4f84b3737 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(300000502095)(300135100095)(22001)(2017030254152)(300000503095)(300135400095)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095); SRVR:AM3PR07MB308; X-Microsoft-Exchange-Diagnostics: 1; AM3PR07MB308; 3:KOWkqWorsu0EowoH5EyV9GG9RrlWCEoPO0DBxkfrt4hoaZVonql1Yxgqcvjr3j/1b5FTFGRJGcVbhN/FWeuF+bI1suVGieKAyXNuhFDzZY+iIDC/kTPh7O0MmMOz0EShm7TUva4VQDOyHJGOm8EYb5jPOTGtAVJFn55bvUQUwAvtL1CqYGJH65BdD4uXpbIcuVOLLMKcN8UCqEHXiKlTZRmO0wAwLnD/EmNYFBn+RCCTGpyua2B+c0UCKeVUmgX9; 25:LuweOlpBGO6KaCEFT0aqCLZugqatnWkC29tn4LHvz9HMRL1pwS+qLE6maBsLzhdsBd+fvCP28PdhuKEuE+tKgyyYSTfKvzQKmMpQD8KvO+qI+XHIu4ogTgO9uxvorHgQ+AvzFaKodY8BT4tQ2SJWMwU1cwMXc1rmoB5JwS0CX5yaXDEst/Ptx5kYEosMmAu6mI+XZLKGaXivfyvDsiWvQxGwc+OR+PAkMJKV2yDDlbHp/km0bn+bDSV3A95dqhV7tABE6z8ZSfPJAwqokHAct+61cp4gVwrd796uTfg4bzp8FdNWBqyt+WYcsgpQ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51e3bC3DhiChinFLRbVo+DeXzuK6+x8+iadE5cL0uMgucQOeWshWQCN7nAXQHYpd X-Exchange-Antispam-Report-Test: UriScan:; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(8121501046)(5005006)(10201501046)(100000703101)(100105400095)(93006095)(93001095)(3002001)(6041248)(20161123560025)(20161123564025)(20161123558100)(20161123562025)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:AM3PR07MB308; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:AM3PR07MB308; X-Forefront-PRVS: 04267075BD X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(7370300001)(4630300001)(6009001)(189002)(54534003)(199003)(68736007)(5003940100001)(86362001)(6666003)(4326008)(107886003)(110136004)(42186005)(50986999)(6512007)(81166006)(81156014)(53936002)(3846002)(6116002)(8676002)(2361001)(101416001)(33646002)(2351001)(105586002)(106356001)(36756003)(478600001)(48376002)(97736004)(50466002)(25786009)(305945005)(47776003)(66066001)(7736002)(50226002)(5660300001)(6916009)(189998001)(7350300001)(2906002)(6506006)(6486002); DIR:OUT; SFP:1101; SCL:1; SRVR:AM3PR07MB308; H:elxacz23q12.localdomain; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: ericsson.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AM3PR07MB308; 23:k7BnjGokX9MNV7esLh7rASMJAOXvoWgktBUtrChJBe?= =?us-ascii?Q?PuJAOINSEjWaaVgGpP3mn1CFtrg/1w80oHmj8UJixOq2Lo/FQ1UMgBBDnNAt?= =?us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pamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Sep 2017 12:55:29.4490 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM3PR07MB308 X-OriginatorOrg: ericsson.com X-IsSubscribed: yes 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 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; } --- gdb/mi/mi-main.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) 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 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; }