about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2020-09-09 11:10:43 -0400
committerTavian Barnes <tavianator@tavianator.com>2020-09-09 11:10:43 -0400
commita684153f2920729f9fc3ea27ddb77d7cc3543214 (patch)
tree68ab222c3d8799a75c2b023eb755eb130a8c29a4
parenta06edda3ad9abd4f07d07bbe46cb488efeebbbd0 (diff)
downloadrust-a684153f2920729f9fc3ea27ddb77d7cc3543214.tar.gz
rust-a684153f2920729f9fc3ea27ddb77d7cc3543214.zip
Only call pthread_attr_destroy() after getattr_np() succeeds on all libcs
The calling convention of pthread_getattr_np() is to initialize the
pthread_attr_t, so _destroy() is only necessary on success (and _init()
isn't necessary beforehand).  On the other hand, FreeBSD wants the
attr_t to be initialized before pthread_attr_get_np(), and therefore it
should always be destroyed afterwards.
-rw-r--r--library/std/src/sys/unix/thread.rs6
1 files changed, 4 insertions, 2 deletions
diff --git a/library/std/src/sys/unix/thread.rs b/library/std/src/sys/unix/thread.rs
index 569aedd7411..652219e28f6 100644
--- a/library/std/src/sys/unix/thread.rs
+++ b/library/std/src/sys/unix/thread.rs
@@ -294,6 +294,7 @@ pub mod guard {
     unsafe fn get_stack_start() -> Option<*mut libc::c_void> {
         let mut ret = None;
         let mut attr: libc::pthread_attr_t = crate::mem::zeroed();
+        #[cfg(target_os = "freebsd")]
         assert_eq!(libc::pthread_attr_init(&mut attr), 0);
         #[cfg(target_os = "freebsd")]
         let e = libc::pthread_attr_get_np(libc::pthread_self(), &mut attr);
@@ -305,7 +306,7 @@ pub mod guard {
             assert_eq!(libc::pthread_attr_getstack(&attr, &mut stackaddr, &mut stacksize), 0);
             ret = Some(stackaddr);
         }
-        if e == 0 || cfg!(not(target_env = "gnu")) {
+        if e == 0 || cfg!(target_os = "freebsd") {
             assert_eq!(libc::pthread_attr_destroy(&mut attr), 0);
         }
         ret
@@ -405,6 +406,7 @@ pub mod guard {
     pub unsafe fn current() -> Option<Guard> {
         let mut ret = None;
         let mut attr: libc::pthread_attr_t = crate::mem::zeroed();
+        #[cfg(target_os = "freebsd")]
         assert_eq!(libc::pthread_attr_init(&mut attr), 0);
         #[cfg(target_os = "freebsd")]
         let e = libc::pthread_attr_get_np(libc::pthread_self(), &mut attr);
@@ -448,7 +450,7 @@ pub mod guard {
                 Some(stackaddr..stackaddr + guardsize)
             };
         }
-        if e == 0 || cfg!(not(target_env = "gnu")) {
+        if e == 0 || cfg!(target_os = "freebsd") {
             assert_eq!(libc::pthread_attr_destroy(&mut attr), 0);
         }
         ret