diff mbox

[0/3] More cleanup elimination / gdb::unique_ptr

Message ID 87funwlqo7.fsf@tromey.com
State New
Headers show

Commit Message

Tom Tromey Oct. 16, 2016, 7:05 a.m. UTC
>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:

Pedro> I'm not sure whether patch #2 is just delayed, or whether it was
Pedro> too big for the list (172K on disk).

I found a buglet in patch #2.  Namely, in rust-lang.c there are some
assignments using concat that aren't converted to properly use
std::string.  This results in a memory leak.

In particular look at rust_get_disr_info - I've appended a hunk from a
patch of mine (untested), but note mine deletes the do_cleanups, which
you don't want to do.

Tom
diff mbox

Patch

diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 5b81283..148e980 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -172,17 +171,15 @@  rust_get_disr_info (struct type *type, const gdb_byte *valaddr,
       if (value == 0)
 	{
 	  ret.field_no = RUST_ENCODED_ENUM_HIDDEN;
-	  ret.name = concat (TYPE_NAME (type), "::", token, (char *) NULL);
+	  ret.name = std::string (TYPE_NAME (type)) + "::" + token;
 	}
       else
 	{
 	  ret.field_no = RUST_ENCODED_ENUM_REAL;
-	  ret.name = concat (TYPE_NAME (type), "::",
-			     rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (type, 0))),
-			     (char *) NULL);
+	  ret.name = (std::string (TYPE_NAME (type)) + "::"
+		      + rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (type, 0))));
 	}
 
-      do_cleanups (cleanup);
       return ret;
     }