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.
This commit is contained in:
parent
1e3b796d58
commit
cd9da5b077
2 changed files with 13 additions and 11 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
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>
|
2016-10-21 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
* maint.h (scoped_command_stats): New class.
|
* maint.h (scoped_command_stats): New class.
|
||||||
|
|
|
@ -212,7 +212,6 @@ dump_memory_to_file (const char *cmd, const char *mode, const char *file_format)
|
||||||
CORE_ADDR hi;
|
CORE_ADDR hi;
|
||||||
ULONGEST count;
|
ULONGEST count;
|
||||||
const char *filename;
|
const char *filename;
|
||||||
gdb_byte *buf;
|
|
||||||
const char *lo_exp;
|
const char *lo_exp;
|
||||||
const char *hi_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
|
/* FIXME: Should use read_memory_partial() and a magic blocking
|
||||||
value. */
|
value. */
|
||||||
buf = (gdb_byte *) xmalloc (count);
|
gdb::unique_ptr<gdb_byte[]> buf (new gdb_byte[count]);
|
||||||
make_cleanup (xfree, buf);
|
read_memory (lo, buf.get (), count);
|
||||||
read_memory (lo, buf, count);
|
|
||||||
|
|
||||||
/* Have everything. Open/write the data. */
|
/* Have everything. Open/write the data. */
|
||||||
if (file_format == NULL || strcmp (file_format, "binary") == 0)
|
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
|
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);
|
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);
|
struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
|
||||||
FILE *file = fopen_with_cleanup (filename, FOPEN_RB);
|
FILE *file = fopen_with_cleanup (filename, FOPEN_RB);
|
||||||
gdb_byte *buf;
|
|
||||||
long len;
|
long len;
|
||||||
|
|
||||||
/* Get the file size for reading. */
|
/* Get the file size for reading. */
|
||||||
|
@ -553,13 +550,13 @@ restore_binary_file (const char *filename, struct callback_data *data)
|
||||||
perror_with_name (filename);
|
perror_with_name (filename);
|
||||||
|
|
||||||
/* Now allocate a buffer and read the file contents. */
|
/* Now allocate a buffer and read the file contents. */
|
||||||
buf = (gdb_byte *) xmalloc (len);
|
gdb::unique_ptr<gdb_byte[]> buf (new gdb_byte[len]);
|
||||||
make_cleanup (xfree, buf);
|
if (fread (buf.get (), 1, len, file) != len)
|
||||||
if (fread (buf, 1, len, file) != len)
|
|
||||||
perror_with_name (filename);
|
perror_with_name (filename);
|
||||||
|
|
||||||
/* Now write the buffer into target memory. */
|
/* 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)
|
if (len != 0)
|
||||||
warning (_("restore: memory write failed (%s)."), safe_strerror (len));
|
warning (_("restore: memory write failed (%s)."), safe_strerror (len));
|
||||||
do_cleanups (cleanup);
|
do_cleanups (cleanup);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue