Use gdb::byte_vector in pascal_object_print_value
authorTom Tromey <tom@tromey.com>
Mon, 14 Aug 2017 06:15:33 +0000 (00:15 -0600)
committerTom Tromey <tom@tromey.com>
Sat, 9 Sep 2017 20:10:49 +0000 (14:10 -0600)
This changes pascal_object_print_value to use a gdb::byte_vector.
This removes a cleanup.  This change also points out how the previous
code had a possible use-after-free bug.

ChangeLog
2017-09-09  Tom Tromey  <tom@tromey.com>

* p-valprint.c (pascal_object_print_value): Use gdb::byte_vector.

gdb/ChangeLog
gdb/p-valprint.c

index 2ccf4e68326cd826b9143db2aedb49ff7ba43350..fd1f3609df192bad6474598babcde3bafcc5b39e 100644 (file)
@@ -1,3 +1,7 @@
+2017-09-09  Tom Tromey  <tom@tromey.com>
+
+       * p-valprint.c (pascal_object_print_value): Use gdb::byte_vector.
+
 2017-09-09  Tom Tromey  <tom@tromey.com>
 
        * stack.c (func_command): Use gdb::def_vector.
index 1cd69cc2b111ec83cbd5c2e774d55c06f0c173c2..d12b63638b9b7aff71999b101db99ba48e01c910 100644 (file)
@@ -38,6 +38,7 @@
 #include "cp-abi.h"
 #include "cp-support.h"
 #include "objfiles.h"
+#include "common/byte-vector.h"
 \f
 
 /* Decorations for Pascal.  */
@@ -730,6 +731,7 @@ pascal_object_print_value (struct type *type, const gdb_byte *valaddr,
       const gdb_byte *base_valaddr = NULL;
       LONGEST thisoffset;
       int skip = 0;
+      gdb::byte_vector buf;
 
       if (BASETYPE_VIA_VIRTUAL (type, i))
        {
@@ -769,20 +771,15 @@ pascal_object_print_value (struct type *type, const gdb_byte *valaddr,
 
          if (boffset < 0 || boffset >= TYPE_LENGTH (type))
            {
-             gdb_byte *buf;
-             struct cleanup *back_to;
+             buf.resize (TYPE_LENGTH (baseclass));
 
-             buf = (gdb_byte *) xmalloc (TYPE_LENGTH (baseclass));
-             back_to = make_cleanup (xfree, buf);
-
-             base_valaddr = buf;
-             if (target_read_memory (address + boffset, buf,
+             base_valaddr = buf.data ();
+             if (target_read_memory (address + boffset, buf.data (),
                                      TYPE_LENGTH (baseclass)) != 0)
                skip = 1;
              address = address + boffset;
              thisoffset = 0;
              boffset = 0;
-             do_cleanups (back_to);
            }
          else
            base_valaddr = valaddr;
This page took 0.031901 seconds and 4 git commands to generate.