PR gdb/17210 concerns a possible memory leak in read_memory_robust.
The bug can happen because read_memory_robust allocates memory, does
not install any cleanups, and invokes QUIT. Similarly, target_read
calls QUIT, so it too can potentially throw.
The fix is to install cleanups to guard the allocated memory.
Built and regtested on x86-64 Fedora 23. I couldn't think of a way to
test this, so no new test; and of course this means it should have
more careful review.
2016-06-29 Tom Tromey <tom@tromey.com>
PR gdb/17210:
* target.c (free_memory_read_result_vector): Take a pointer to the
VEC as an argument.
(read_memory_robust): Install a cleanup for "result".
* mi/mi-main.c (mi_cmd_data_read_memory_bytes): Update.
+2016-06-29 Tom Tromey <tom@tromey.com>
+
+ PR gdb/17210:
+ * target.c (free_memory_read_result_vector): Take a pointer to the
+ VEC as an argument.
+ (read_memory_robust): Install a cleanup for "result".
+ * mi/mi-main.c (mi_cmd_data_read_memory_bytes): Update.
+
2016-06-29 Manish Goregaokar <manish@mozilla.com>
gdb/ChangeLog:
2016-06-29 Manish Goregaokar <manish@mozilla.com>
gdb/ChangeLog:
result = read_memory_robust (current_target.beneath, addr, length);
result = read_memory_robust (current_target.beneath, addr, length);
- cleanups = make_cleanup (free_memory_read_result_vector, result);
+ cleanups = make_cleanup (free_memory_read_result_vector, &result);
if (VEC_length (memory_read_result_s, result) == 0)
error (_("Unable to read memory."));
if (VEC_length (memory_read_result_s, result) == 0)
error (_("Unable to read memory."));
void
free_memory_read_result_vector (void *x)
{
void
free_memory_read_result_vector (void *x)
{
- VEC(memory_read_result_s) *v = (VEC(memory_read_result_s) *) x;
+ VEC(memory_read_result_s) **v = (VEC(memory_read_result_s) **) x;
memory_read_result_s *current;
int ix;
memory_read_result_s *current;
int ix;
- for (ix = 0; VEC_iterate (memory_read_result_s, v, ix, current); ++ix)
+ for (ix = 0; VEC_iterate (memory_read_result_s, *v, ix, current); ++ix)
{
xfree (current->data);
}
{
xfree (current->data);
}
- VEC_free (memory_read_result_s, v);
+ VEC_free (memory_read_result_s, *v);
}
VEC(memory_read_result_s) *
}
VEC(memory_read_result_s) *
{
VEC(memory_read_result_s) *result = 0;
int unit_size = gdbarch_addressable_memory_unit_size (target_gdbarch ());
{
VEC(memory_read_result_s) *result = 0;
int unit_size = gdbarch_addressable_memory_unit_size (target_gdbarch ());
+ struct cleanup *cleanup = make_cleanup (free_memory_read_result_vector,
+ &result);
LONGEST xfered_total = 0;
while (xfered_total < len)
LONGEST xfered_total = 0;
while (xfered_total < len)
{
LONGEST to_read = min (len - xfered_total, region_len);
gdb_byte *buffer = (gdb_byte *) xmalloc (to_read * unit_size);
{
LONGEST to_read = min (len - xfered_total, region_len);
gdb_byte *buffer = (gdb_byte *) xmalloc (to_read * unit_size);
+ struct cleanup *inner_cleanup = make_cleanup (xfree, buffer);
LONGEST xfered_partial =
target_read (ops, TARGET_OBJECT_MEMORY, NULL,
LONGEST xfered_partial =
target_read (ops, TARGET_OBJECT_MEMORY, NULL,
{
/* Got an error reading full chunk. See if maybe we can read
some subrange. */
{
/* Got an error reading full chunk. See if maybe we can read
some subrange. */
+ do_cleanups (inner_cleanup);
read_whatever_is_readable (ops, offset + xfered_total,
offset + xfered_total + to_read,
unit_size, &result);
read_whatever_is_readable (ops, offset + xfered_total,
offset + xfered_total + to_read,
unit_size, &result);
else
{
struct memory_read_result r;
else
{
struct memory_read_result r;
+
+ discard_cleanups (inner_cleanup);
r.data = buffer;
r.begin = offset + xfered_total;
r.end = r.begin + xfered_partial;
r.data = buffer;
r.begin = offset + xfered_total;
r.end = r.begin + xfered_partial;
+
+ discard_cleanups (cleanup);