]> git.lizzy.rs Git - rust.git/commitdiff
std: Be sure to call pthread_attr_destroy
authorAlex Crichton <alex@alexcrichton.com>
Fri, 11 Apr 2014 05:38:05 +0000 (22:38 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Fri, 11 Apr 2014 05:38:05 +0000 (22:38 -0700)
On some OSes (such as freebsd), pthread_attr_init allocates memory, so this is
necessary to deallocate that memory.

Closes #13420

src/libstd/rt/thread.rs

index b1c7c5aab020f0cb2135d2adedb7bd8b6d213569..4aa85bc4c72a624431ee6ce97217592ae4762c4c 100644 (file)
@@ -245,6 +245,7 @@ pub unsafe fn create(stack: uint, p: ~proc():Send) -> rust_thread {
         let arg: *libc::c_void = cast::transmute(p);
         assert_eq!(pthread_create(&mut native, &attr,
                                   super::thread_start, arg), 0);
+        assert_eq!(pthread_attr_destroy(&mut attr), 0);
         native
     }
 
@@ -303,6 +304,7 @@ fn pthread_create(native: *mut libc::pthread_t,
         fn pthread_join(native: libc::pthread_t,
                         value: **libc::c_void) -> libc::c_int;
         fn pthread_attr_init(attr: *mut libc::pthread_attr_t) -> libc::c_int;
+        fn pthread_attr_destroy(attr: *mut libc::pthread_attr_t) -> libc::c_int;
         fn pthread_attr_setstacksize(attr: *mut libc::pthread_attr_t,
                                      stack_size: libc::size_t) -> libc::c_int;
         fn pthread_attr_setdetachstate(attr: *mut libc::pthread_attr_t,