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.
+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.
2016-10-21 Tom Tromey <tom@tromey.com>
* maint.h (scoped_command_stats): New class.
CORE_ADDR hi;
ULONGEST count;
const char *filename;
CORE_ADDR hi;
ULONGEST count;
const char *filename;
const char *lo_exp;
const char *hi_exp;
const char *lo_exp;
const char *hi_exp;
/* FIXME: Should use read_memory_partial() and a magic blocking
value. */
/* 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)
{
/* 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);
- 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);
{
struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
FILE *file = fopen_with_cleanup (filename, FOPEN_RB);
{
struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
FILE *file = fopen_with_cleanup (filename, FOPEN_RB);
long len;
/* Get the file size for reading. */
long len;
/* Get the file size for reading. */
perror_with_name (filename);
/* Now allocate a buffer and read the file contents. */
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. */
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);
if (len != 0)
warning (_("restore: memory write failed (%s)."), safe_strerror (len));
do_cleanups (cleanup);