aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2016-09-24 21:21:35 -0600
committerTom Tromey <tom@tromey.com>2016-10-21 14:17:35 -0600
commitcd9da5b077c21f0984cfbdac060ced6f4945ce06 (patch)
treef9ab9d7adc7b55c3744a9b3729af3a2eb7876701
parent1e3b796d58ac3c4396e1739f44a0a41de6335eef (diff)
downloadgdb-cd9da5b077c21f0984cfbdac060ced6f4945ce06.zip
gdb-cd9da5b077c21f0984cfbdac060ced6f4945ce06.tar.gz
gdb-cd9da5b077c21f0984cfbdac060ced6f4945ce06.tar.bz2
Replace two xmallocs with unique_ptr
This replaces a couple of uses of xmalloc with gdb::unique_ptr, also removing a couple of cleanups. 2016-10-21 Tom Tromey <tom@tromey.com> * cli/cli-dump.c (dump_memory_to_file): Use gdb::unique_ptr. (restore_binary_file): Likewise.
-rw-r--r--gdb/ChangeLog5
-rw-r--r--gdb/cli/cli-dump.c19
2 files changed, 13 insertions, 11 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 1c58ab6..e28e774 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
2016-10-21 Tom Tromey <tom@tromey.com>
+ * cli/cli-dump.c (dump_memory_to_file): Use gdb::unique_ptr.
+ (restore_binary_file): Likewise.
+
+2016-10-21 Tom Tromey <tom@tromey.com>
+
* 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<gdb_byte[]> 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<gdb_byte[]> 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);