[runtime] Fix a crash if the thread name is set before the thread is started.
authorZoltan Varga <vargaz@gmail.com>
Tue, 1 Apr 2014 18:32:19 +0000 (18:32 +0000)
committerZoltan Varga <vargaz@gmail.com>
Tue, 1 Apr 2014 18:32:33 +0000 (18:32 +0000)
mono/metadata/threads.c

index 656e73e81bedc6f2ab2ce128618fee5e55b14838..43e57280ee1f22ce9510fca0d439f5a36fc6c4bd 100755 (executable)
@@ -669,6 +669,8 @@ static guint32 WINAPI start_wrapper_internal(void *data)
 
        thread_cleanup (internal);
 
+       internal->tid = 0;
+
        /* Remove the reference to the thread object in the TLS data,
         * so the thread object can be finalized.  This won't be
         * reached if the thread threw an uncaught exception, so those
@@ -1182,8 +1184,11 @@ mono_thread_set_name_internal (MonoInternalThread *this_obj, MonoString *name, g
 
        if (this_obj->name) {
                char *tname = mono_string_to_utf8 (name);
-               mono_profiler_thread_name (this_obj->tid, tname);
-               mono_thread_info_set_name (this_obj->tid, tname);
+
+               if (this_obj->tid) {
+                       mono_profiler_thread_name (this_obj->tid, tname);
+                       mono_thread_info_set_name (this_obj->tid, tname);
+               }
                mono_free (tname);
        }
 }