[threads] Add checks around libc calls (#5240)
authorLudovic Henry <ludovic@xamarin.com>
Wed, 19 Jul 2017 21:50:07 +0000 (17:50 -0400)
committerGitHub <noreply@github.com>
Wed, 19 Jul 2017 21:50:07 +0000 (17:50 -0400)
mono/utils/mono-threads-linux.c

index f4980b6b6c5d0a3ffd262eb6e2ff2b0a41605a37..d757cd66c318ec6e87a072d2597e2606909d8c3c 100644 (file)
@@ -13,13 +13,27 @@ void
 mono_threads_platform_get_stack_bounds (guint8 **staddr, size_t *stsize)
 {
        pthread_attr_t attr;
+       gint res;
 
        *staddr = NULL;
        *stsize = (size_t)-1;
 
-       pthread_getattr_np (pthread_self (), &attr);
-       pthread_attr_getstack (&attr, (void**)staddr, stsize);
-       pthread_attr_destroy (&attr);
+       res = pthread_attr_init (&attr);
+       if (G_UNLIKELY (res != 0))
+               g_error ("%s: pthread_attr_init failed with \"%s\" (%d)", __func__, g_strerror (res), res);
+
+       res = pthread_getattr_np (pthread_self (), &attr);
+       if (G_UNLIKELY (res != 0))
+               g_error ("%s: pthread_getattr_np failed with \"%s\" (%d)", __func__, g_strerror (res), res);
+
+       res = pthread_attr_getstack (&attr, (void**)staddr, stsize);
+       if (G_UNLIKELY (res != 0))
+               g_error ("%s: pthread_attr_getstack failed with \"%s\" (%d)", __func__, g_strerror (res), res);
+
+       res = pthread_attr_destroy (&attr);
+       if (G_UNLIKELY (res != 0))
+               g_error ("%s: pthread_attr_destroy failed with \"%s\" (%d)", __func__, g_strerror (res), res);
+
 }
 
 #endif