From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from barracuda.ebox.ca (barracuda.ebox.ca [96.127.255.19]) by sourceware.org (Postfix) with ESMTPS id 4DF1E387084E for ; Thu, 25 Jun 2020 15:55:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 4DF1E387084E X-ASG-Debug-ID: 1593100518-0c856e29fd58f6e0001-fS2M51 Received: from smtp.ebox.ca (smtp.ebox.ca [96.127.255.82]) by barracuda.ebox.ca with ESMTP id PltBymXEDl8xAqhH (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 25 Jun 2020 11:55:18 -0400 (EDT) X-Barracuda-Envelope-From: simon.marchi@efficios.com X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from epycamd.internal.efficios.com (192-222-181-218.qc.cable.ebox.net [192.222.181.218]) by smtp.ebox.ca (Postfix) with ESMTP id CB5B7441B21; Thu, 25 Jun 2020 11:55:18 -0400 (EDT) From: Simon Marchi X-Barracuda-Effective-Source-IP: 192-222-181-218.qc.cable.ebox.net[192.222.181.218] X-Barracuda-Apparent-Source-IP: 192.222.181.218 X-Barracuda-RBL-IP: 192.222.181.218 To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH] gdb: make inferior::terminal a unique ptr Date: Thu, 25 Jun 2020 11:55:17 -0400 X-ASG-Orig-Subj: [PATCH] gdb: make inferior::terminal a unique ptr Message-Id: <20200625155517.32173-1-simon.marchi@efficios.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Barracuda-Connect: smtp.ebox.ca[96.127.255.82] X-Barracuda-Start-Time: 1593100518 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://96.127.255.19:443/cgi-mod/mark.cgi X-Barracuda-Scan-Msg-Size: 2493 X-Virus-Scanned: by bsmtpd at ebox.ca X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.50 X-Barracuda-Spam-Status: No, SCORE=0.50 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=8.0 tests=BSF_RULE7568M X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.82800 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 0.50 BSF_RULE7568M Custom Rule 7568M X-Spam-Status: No, score=-24.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_SOFTFAIL, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Jun 2020 15:55:21 -0000 This changes the inferior::terminal field to be a unique pointer, so its deallocation is automatically managed. gdb/ChangeLog: * inferior.h (struct inferior) : Change type to gdb::unique_xmalloc_ptr. * inferior.c (inferior::~inferior): Don't free inf->terminal. * infcmd.c (set_inferior_io_terminal): Don't free terminal field, adjust to unique pointer. (get_inferior_io_terminal): Adjust to unique pointer. Change-Id: Iedb6459b4f9eeae812b0cb9d514b5707d5107cdb --- gdb/infcmd.c | 6 ++---- gdb/inferior.c | 1 - gdb/inferior.h | 3 ++- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/gdb/infcmd.c b/gdb/infcmd.c index 42b050d3c4e..48d6a91c0c2 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -108,10 +108,8 @@ int stopped_by_random_signal; void set_inferior_io_terminal (const char *terminal_name) { - xfree (current_inferior ()->terminal); - if (terminal_name != NULL && *terminal_name != '\0') - current_inferior ()->terminal = xstrdup (terminal_name); + current_inferior ()->terminal.reset (xstrdup (terminal_name)); else current_inferior ()->terminal = NULL; } @@ -119,7 +117,7 @@ set_inferior_io_terminal (const char *terminal_name) const char * get_inferior_io_terminal (void) { - return current_inferior ()->terminal; + return current_inferior ()->terminal.get (); } static void diff --git a/gdb/inferior.c b/gdb/inferior.c index 2f4ced0788d..d3bece029dd 100644 --- a/gdb/inferior.c +++ b/gdb/inferior.c @@ -79,7 +79,6 @@ inferior::~inferior () discard_all_inferior_continuations (inf); inferior_free_data (inf); xfree (inf->args); - xfree (inf->terminal); target_desc_info_free (inf->tdesc_info); } diff --git a/gdb/inferior.h b/gdb/inferior.h index 95af474eede..5002b0b8b3d 100644 --- a/gdb/inferior.h +++ b/gdb/inferior.h @@ -52,6 +52,7 @@ struct thread_info; #include "symfile-add-flags.h" #include "gdbsupport/refcounted-object.h" #include "gdbsupport/forward-scope-exit.h" +#include "gdbsupport/gdb_unique_ptr.h" #include "gdbsupport/common-inferior.h" #include "gdbthread.h" @@ -456,7 +457,7 @@ class inferior : public refcounted_object gdb::unique_xmalloc_ptr cwd; /* The name of terminal device to use for I/O. */ - char *terminal = NULL; + gdb::unique_xmalloc_ptr terminal; /* The terminal state as set by the last target_terminal::terminal_* call. */ -- 2.27.0