From c12c4b947d5788f31071287d63bcc16475dfeaa6 Mon Sep 17 00:00:00 2001 From: Jay Krell Date: Mon, 29 Jul 2019 02:31:14 -0700 Subject: [PATCH] Fix thread name leak in debugger. (mono/mono#15858) Commit migrated from https://github.com/mono/mono/commit/b5c0c831da328b8ab7b7283a38fa56baaa7ae380 --- src/mono/mono/metadata/threads.c | 2 +- src/mono/mono/mini/debugger-agent.c | 11 +++-------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/mono/mono/metadata/threads.c b/src/mono/mono/metadata/threads.c index a7da09e..af4d7c4 100644 --- a/src/mono/mono/metadata/threads.c +++ b/src/mono/mono/metadata/threads.c @@ -1822,7 +1822,7 @@ mono_thread_get_name (MonoInternalThread *this_obj, guint32 *name_len) * mono_thread_get_name_utf8: * \returns the name of the thread in UTF-8. * Return NULL if the thread has no name. - * The returned memory is owned by the caller. + * The returned memory is owned by the caller (g_free it). */ char * mono_thread_get_name_utf8 (MonoThread *thread) diff --git a/src/mono/mono/mini/debugger-agent.c b/src/mono/mono/mini/debugger-agent.c index eb9113f..c4405d8 100644 --- a/src/mono/mono/mini/debugger-agent.c +++ b/src/mono/mono/mini/debugger-agent.c @@ -8665,19 +8665,14 @@ thread_commands (int command, guint8 *p, guint8 *end, Buffer *buf) switch (command) { case CMD_THREAD_GET_NAME: { - guint32 name_len; - gunichar2 *s = mono_thread_get_name (thread, &name_len); + char *s = mono_thread_get_name_utf8 (thread_obj); if (!s) { buffer_add_int (buf, 0); } else { - char *name; - glong len; - - name = g_utf16_to_utf8 (s, name_len, NULL, &len, NULL); - g_assert (name); + const size_t len = strlen (s); buffer_add_int (buf, len); - buffer_add_data (buf, (guint8*)name, len); + buffer_add_data (buf, (guint8*)s, len); g_free (s); } break; -- 2.7.4