Fix segfault if pthread_getattr_np fails
glibc destroys[1] the passed pthread_attr_t if pthread_getattr_np() fails. Destroying it again leads to a segfault. Fix it by only destroying it on success for glibc. [1]: https://sourceware.org/git/?p=glibc.git;a=blob;f=nptl/pthread_getattr_np.c;h=ce437205e41dc05653e435f6188768cccdd91c99;hb=HEAD#l205
This commit is contained in:
@@ -305,7 +305,9 @@ pub mod guard {
|
|||||||
assert_eq!(libc::pthread_attr_getstack(&attr, &mut stackaddr, &mut stacksize), 0);
|
assert_eq!(libc::pthread_attr_getstack(&attr, &mut stackaddr, &mut stacksize), 0);
|
||||||
ret = Some(stackaddr);
|
ret = Some(stackaddr);
|
||||||
}
|
}
|
||||||
assert_eq!(libc::pthread_attr_destroy(&mut attr), 0);
|
if e == 0 || cfg!(not(target_env = "gnu")) {
|
||||||
|
assert_eq!(libc::pthread_attr_destroy(&mut attr), 0);
|
||||||
|
}
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -446,7 +448,9 @@ pub mod guard {
|
|||||||
Some(stackaddr..stackaddr + guardsize)
|
Some(stackaddr..stackaddr + guardsize)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
assert_eq!(libc::pthread_attr_destroy(&mut attr), 0);
|
if e == 0 || cfg!(not(target_env = "gnu")) {
|
||||||
|
assert_eq!(libc::pthread_attr_destroy(&mut attr), 0);
|
||||||
|
}
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user