[mono-threads-windows] Allocate ThreadStartInfo on the stack
authorLudovic Henry <ludovic@xamarin.com>
Tue, 23 Aug 2016 17:13:23 +0000 (19:13 +0200)
committerLudovic Henry <ludovic@xamarin.com>
Wed, 24 Aug 2016 14:39:18 +0000 (16:39 +0200)
mono/utils/mono-threads-windows.c

index f64f5743ce55ad188e4552b6fc6d4422927e6f26..6c33743cfb63af5e231414c0698bab14c1233154 100644 (file)
@@ -194,48 +194,45 @@ inner_start_thread (LPVOID arg)
 HANDLE
 mono_threads_platform_create_thread (MonoThreadStart start_routine, gpointer arg, MonoThreadParm *tp, MonoNativeThreadId *out_tid)
 {
-       ThreadStartInfo *start_info;
+       ThreadStartInfo start_info;
        HANDLE result;
        DWORD thread_id;
        guint32 creation_flags = tp->creation_flags;
        int res;
 
-       start_info = g_malloc0 (sizeof (ThreadStartInfo));
-       if (!start_info)
-               return NULL;
-       mono_coop_sem_init (&(start_info->registered), 0);
-       start_info->arg = arg;
-       start_info->priority = tp->priority;
-       start_info->start_routine = start_routine;
-       start_info->suspend = creation_flags & CREATE_SUSPENDED;
+       memset (&start_info, 0, sizeof (start_info));
+       mono_coop_sem_init (&(start_info.registered), 0);
+       start_info.arg = arg;
+       start_info.start_routine = start_routine;
+       start_info.suspend = creation_flags & CREATE_SUSPENDED;
+       start_info.priority = tp->priority;
        creation_flags &= ~CREATE_SUSPENDED;
-       if (start_info->suspend) {
-               start_info->suspend_event = CreateEvent (NULL, TRUE, FALSE, NULL);
-               if (!start_info->suspend_event)
+       if (start_info.suspend) {
+               start_info.suspend_event = CreateEvent (NULL, TRUE, FALSE, NULL);
+               if (!start_info.suspend_event)
                        return NULL;
        }
 
-       result = CreateThread (NULL, tp->stack_size, inner_start_thread, start_info, creation_flags, &thread_id);
+       result = CreateThread (NULL, tp->stack_size, inner_start_thread, &start_info, creation_flags, &thread_id);
        if (result) {
-               res = mono_coop_sem_wait (&(start_info->registered), MONO_SEM_FLAGS_NONE);
+               res = mono_coop_sem_wait (&(start_info.registered), MONO_SEM_FLAGS_NONE);
                g_assert (res != -1);
 
                /* A new handle has been opened when attaching
                 * the thread, so we don't need this one */
                CloseHandle (result);
 
-               if (start_info->suspend) {
-                       g_assert (SuspendThread (result) != (DWORD)-1);
-                       SetEvent (start_info->suspend_event);
+               if (start_info.suspend) {
+                       g_assert (SuspendThread (start_info.handle) != (DWORD)-1);
+                       SetEvent (start_info.suspend_event);
                }
-       } else if (start_info->suspend) {
-               CloseHandle (start_info->suspend_event);
+       } else if (start_info.suspend) {
+               CloseHandle (start_info.suspend_event);
        }
        if (out_tid)
                *out_tid = thread_id;
-       mono_coop_sem_destroy (&(start_info->registered));
-       g_free (start_info);
-       return result;
+       mono_coop_sem_destroy (&(start_info.registered));
+       return start_info.handle;
 }