From patchwork Tue Sep 27 04:08:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 16062 Received: (qmail 104421 invoked by alias); 27 Sep 2016 04:51:26 -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 104361 invoked by uid 89); 27 Sep 2016 04:51:25 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=no version=3.3.2 spammy= X-HELO: gproxy10-pub.mail.unifiedlayer.com Received: from gproxy10-pub.mail.unifiedlayer.com (HELO gproxy10-pub.mail.unifiedlayer.com) (69.89.20.226) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with SMTP; Tue, 27 Sep 2016 04:51:15 +0000 Received: (qmail 21025 invoked by uid 0); 27 Sep 2016 04:51:13 -0000 Received: from unknown (HELO cmgw2) (10.0.90.83) by gproxy10.mail.unifiedlayer.com with SMTP; 27 Sep 2016 04:51:13 -0000 Received: from box522.bluehost.com ([74.220.219.122]) by cmgw2 with id oUr91t00H2f2jeq01UrCbF; Mon, 26 Sep 2016 22:51:12 -0600 X-Authority-Analysis: v=2.1 cv=F4vEKMRN 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=GW1xBdLrtEIA:10 a=zstS-IiYAAAA:8 a=FtLFWNm7aHwvG0_EFo0A:9 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 71-218-192-86.hlrn.qwest.net ([71.218.192.86]:56110 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.86_1) (envelope-from ) id 1bojhV-0006Nj-Vc; Mon, 26 Sep 2016 22:09:02 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 14/22] Replace two xmallocs with vector Date: Mon, 26 Sep 2016 22:08:42 -0600 Message-Id: <1474949330-4307-15-git-send-email-tom@tromey.com> In-Reply-To: <1474949330-4307-1-git-send-email-tom@tromey.com> References: <1474949330-4307-1-git-send-email-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1bojhV-0006Nj-Vc X-Source-Sender: 71-218-192-86.hlrn.qwest.net (bapiya.Home) [71.218.192.86]:56110 X-Source-Auth: tom+tromey.com X-Email-Count: 23 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== This replaces a couple of uses of xmalloc with a std::vector, also removing a couple of cleanups. 2016-09-26 Tom Tromey * cli/cli-dump.c (dump_memory_to_file): Use std::vector. (restore_binary_file): Likewise. --- gdb/ChangeLog | 5 +++++ gdb/cli/cli-dump.c | 21 +++++++++------------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 476dbb3..42101fc 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 std::vector. + (restore_binary_file): Likewise. + +2016-09-26 Tom Tromey + * stabsread.c (read_struct_type): Remove unnecessary cleanup. 2016-09-26 Tom Tromey diff --git a/gdb/cli/cli-dump.c b/gdb/cli/cli-dump.c index 611b0c3..2b4d1be 100644 --- a/gdb/cli/cli-dump.c +++ b/gdb/cli/cli-dump.c @@ -31,7 +31,7 @@ #include "cli/cli-utils.h" #include "gdb_bfd.h" #include "filestuff.h" - +#include static const char * scan_expression_with_cleanup (const char **cmd, const char *def) @@ -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); + std::vector buf (count); + read_memory (lo, buf.data (), 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.data (), count); } else { - dump_bfd_file (filename, mode, file_format, lo, buf, count); + dump_bfd_file (filename, mode, file_format, lo, buf.data (), 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) + std::vector buf (len); + if (fread (buf.data (), 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.data (), len); if (len != 0) warning (_("restore: memory write failed (%s)."), safe_strerror (len)); do_cleanups (cleanup);