From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25755 invoked by alias); 4 Aug 2017 09:41:13 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 25732 invoked by uid 89); 4 Aug 2017 09:41:12 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.8 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: smtp.polymtl.ca Received: from smtp.polymtl.ca (HELO smtp.polymtl.ca) (132.207.4.11) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 04 Aug 2017 09:41:09 +0000 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id v749f3pp028105 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 4 Aug 2017 05:41:07 -0400 Received: by simark.ca (Postfix, from userid 112) id 04C7A1EA05; Fri, 4 Aug 2017 05:41:03 -0400 (EDT) Received: from simark.ca (localhost [127.0.0.1]) by simark.ca (Postfix) with ESMTP id DBECE1E043; Fri, 4 Aug 2017 05:41:01 -0400 (EDT) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Fri, 04 Aug 2017 09:41:00 -0000 From: Simon Marchi To: Tom Tromey Cc: gdb-patches@sourceware.org Subject: Re: [RFA] Use gdb::unique_xmalloc_ptr when calling tilde_expand In-Reply-To: <20170803214348.27356-1-tom@tromey.com> References: <20170803214348.27356-1-tom@tromey.com> Message-ID: X-Sender: simon.marchi@polymtl.ca User-Agent: Roundcube Webmail/1.3.0 X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Fri, 4 Aug 2017 09:41:03 +0000 X-IsSubscribed: yes X-SW-Source: 2017-08/txt/msg00062.txt.bz2 Hi Tom, On 2017-08-03 23:43, Tom Tromey wrote: > This patch changes most sites calling tilde_expand to use > gdb::unique_xmalloc_ptr, rather than a cleanup. It also changes > scan_expression_with_cleanup to return a unique pointer, because the > patch was already touching code in that area. The patch looks good to me. I noted two formatting nits (that were present before this patch), could you fix them before pushing? > @@ -224,14 +210,12 @@ dump_memory_to_file (const char *cmd, const char > *mode, const char *file_format) > /* Have everything. Open/write the data. */ > if (file_format == NULL || strcmp (file_format, "binary") == 0) > { > - dump_binary_file (filename, mode, buf.data (), count); > + dump_binary_file (filename.get (), mode, buf.data (), count); > } > else > { > - dump_bfd_file (filename, mode, file_format, lo, buf.data (), > count); > + dump_bfd_file (filename.get (), mode, file_format, lo, buf.data > (), count); > } Remove these unnecessary curly braces. > @@ -589,18 +568,18 @@ restore_command (char *args_in, int from_tty) > > if (info_verbose) > printf_filtered ("Restore file %s offset 0x%lx start 0x%lx end > 0x%lx\n", > - filename, (unsigned long) data.load_offset, > + filename.get (), (unsigned long) data.load_offset, > (unsigned long) data.load_start, > (unsigned long) data.load_end); > > if (binary_flag) > { > - restore_binary_file (filename, &data); > + restore_binary_file (filename.get (), &data); > } Same here. > diff --git a/gdb/tracefile-tfile.c b/gdb/tracefile-tfile.c > index fb4283f..37bd96a 100644 > --- a/gdb/tracefile-tfile.c > +++ b/gdb/tracefile-tfile.c > @@ -423,7 +423,6 @@ static void > tfile_open (const char *arg, int from_tty) > { > char *temp; > - struct cleanup *old_chain; > int flags; > int scratch_chan; > char header[TRACE_HEADER_SIZE]; > @@ -433,34 +432,27 @@ tfile_open (const char *arg, int from_tty) > struct trace_status *ts; > struct uploaded_tp *uploaded_tps = NULL; > struct uploaded_tsv *uploaded_tsvs = NULL; > - char *filename; > > target_preopen (from_tty); > if (!arg) > error (_("No trace file specified.")); > > - filename = tilde_expand (arg); > - if (!IS_ABSOLUTE_PATH(filename)) > - { > - temp = concat (current_directory, "/", filename, (char *) NULL); > - xfree (filename); > - filename = temp; > - } > - > - old_chain = make_cleanup (xfree, filename); > + gdb::unique_xmalloc_ptr filename (tilde_expand (arg)); > + if (!IS_ABSOLUTE_PATH (filename.get ())) > + filename.reset (concat (current_directory, "/", filename.get (), > + (char *) NULL)); > > flags = O_BINARY | O_LARGEFILE; > flags |= O_RDONLY; > - scratch_chan = gdb_open_cloexec (filename, flags, 0); > + scratch_chan = gdb_open_cloexec (filename.get (), flags, 0); > if (scratch_chan < 0) > - perror_with_name (filename); > + perror_with_name (filename.get ()); > > /* Looks semi-reasonable. Toss the old trace file and work on the > new. */ > > - discard_cleanups (old_chain); /* Don't free filename any more. */ > unpush_target (&tfile_ops); > > - trace_filename = xstrdup (filename); > + trace_filename = filename.release (); Hmm, the old code discarded the cleanup and did an xstrdup, that seems like a leak that you fixed :) Thanks, Simon