From patchwork Thu Oct 13 21:10:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 16494 Received: (qmail 4804 invoked by alias); 13 Oct 2016 21:11:48 -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 4273 invoked by uid 89); 13 Oct 2016 21:11:42 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=no version=3.3.2 spammy=sk:read_me, H*RU:sk:gproxy5, Hx-spam-relays-external:sk:gproxy5, H*RU:67.222.38.55 X-HELO: gproxy5-pub.mail.unifiedlayer.com Received: from gproxy5-pub.mail.unifiedlayer.com (HELO gproxy5-pub.mail.unifiedlayer.com) (67.222.38.55) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with SMTP; Thu, 13 Oct 2016 21:11:32 +0000 Received: (qmail 13708 invoked by uid 0); 13 Oct 2016 21:11:05 -0000 Received: from unknown (HELO CMOut01) (10.0.90.82) by gproxy5.mail.unifiedlayer.com with SMTP; 13 Oct 2016 21:11:05 -0000 Received: from box522.bluehost.com ([74.220.219.122]) by CMOut01 with id v9AM1t00J2f2jeq019AQmP; Thu, 13 Oct 2016 15:10:24 -0600 X-Authority-Analysis: v=2.1 cv=beT4Do/B c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=CH0kA5CcgfcA:10 a=zstS-IiYAAAA:8 a=FtLFWNm7aHwvG0_EFo0A:9 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 174-16-143-211.hlrn.qwest.net ([174.16.143.211]:42448 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.86_1) (envelope-from ) id 1bunGg-00011Z-IX; Thu, 13 Oct 2016 15:10:22 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA v2 10/17] Replace two xmallocs with unique_ptr Date: Thu, 13 Oct 2016 15:10:05 -0600 Message-Id: <1476393012-29987-11-git-send-email-tom@tromey.com> In-Reply-To: <1476393012-29987-1-git-send-email-tom@tromey.com> References: <1476393012-29987-1-git-send-email-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1bunGg-00011Z-IX X-Source-Sender: 174-16-143-211.hlrn.qwest.net (bapiya.Home) [174.16.143.211]:42448 X-Source-Auth: tom+tromey.com X-Email-Count: 11 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== This replaces a couple of uses of xmalloc with gdb::unique_ptr, also removing a couple of cleanups. 2016-09-26 Tom Tromey * cli/cli-dump.c (dump_memory_to_file): Use gdb::unique_ptr. (restore_binary_file): Likewise. --- gdb/ChangeLog | 5 +++++ gdb/cli/cli-dump.c | 19 ++++++++----------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index f476299..0d5f425 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,10 @@ 2016-09-26 Tom Tromey + * cli/cli-dump.c (dump_memory_to_file): Use gdb::unique_ptr. + (restore_binary_file): Likewise. + +2016-09-26 Tom Tromey + * maint.h (scoped_command_stats): New class. (make_command_stats_cleanup): Don't declare. * maint.c (struct cmd_stats): Remove. diff --git a/gdb/cli/cli-dump.c b/gdb/cli/cli-dump.c index 611b0c3..eb7f69d 100644 --- a/gdb/cli/cli-dump.c +++ b/gdb/cli/cli-dump.c @@ -212,7 +212,6 @@ dump_memory_to_file (const char *cmd, const char *mode, const char *file_format) CORE_ADDR hi; ULONGEST count; const char *filename; - gdb_byte *buf; const char *lo_exp; const char *hi_exp; @@ -237,18 +236,17 @@ dump_memory_to_file (const char *cmd, const char *mode, const char *file_format) /* FIXME: Should use read_memory_partial() and a magic blocking value. */ - buf = (gdb_byte *) xmalloc (count); - make_cleanup (xfree, buf); - read_memory (lo, buf, count); + gdb::unique_ptr buf (new gdb_byte[count]); + read_memory (lo, buf.get (), count); /* Have everything. Open/write the data. */ if (file_format == NULL || strcmp (file_format, "binary") == 0) { - dump_binary_file (filename, mode, buf, count); + dump_binary_file (filename, mode, buf.get (), count); } else { - dump_bfd_file (filename, mode, file_format, lo, buf, count); + dump_bfd_file (filename, mode, file_format, lo, buf.get (), count); } do_cleanups (old_cleanups); @@ -518,7 +516,6 @@ restore_binary_file (const char *filename, struct callback_data *data) { struct cleanup *cleanup = make_cleanup (null_cleanup, NULL); FILE *file = fopen_with_cleanup (filename, FOPEN_RB); - gdb_byte *buf; long len; /* Get the file size for reading. */ @@ -553,13 +550,13 @@ restore_binary_file (const char *filename, struct callback_data *data) perror_with_name (filename); /* Now allocate a buffer and read the file contents. */ - buf = (gdb_byte *) xmalloc (len); - make_cleanup (xfree, buf); - if (fread (buf, 1, len, file) != len) + gdb::unique_ptr buf (new gdb_byte[len]); + if (fread (buf.get (), 1, len, file) != len) perror_with_name (filename); /* Now write the buffer into target memory. */ - len = target_write_memory (data->load_start + data->load_offset, buf, len); + len = target_write_memory (data->load_start + data->load_offset, + buf.get (), len); if (len != 0) warning (_("restore: memory write failed (%s)."), safe_strerror (len)); do_cleanups (cleanup);