From 82a7e5bb708200aa9ba8b982edd60eacedd3fd8b Mon Sep 17 00:00:00 2001 From: Ludovic Henry Date: Wed, 19 Jul 2017 17:50:07 -0400 Subject: [PATCH] [threads] Add checks around libc calls (#5240) --- mono/utils/mono-threads-linux.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/mono/utils/mono-threads-linux.c b/mono/utils/mono-threads-linux.c index f4980b6b6c5..d757cd66c31 100644 --- a/mono/utils/mono-threads-linux.c +++ b/mono/utils/mono-threads-linux.c @@ -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 -- 2.25.1