Skip to content

Commit

Permalink
Merge #2690
Browse files Browse the repository at this point in the history
2690: Fix memory leak when obtaining the stack bounds of a thread r=syrusakbary a=Amanieu

`pthread_attr_destroy` must be called to free a `pthread_attr_t`.

Co-authored-by: Amanieu d'Antras <amanieu@gmail.com>
  • Loading branch information
bors[bot] and Amanieu authored Nov 18, 2021
2 parents 139f422 + 1092713 commit 287deb1
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/vm/src/trap/traphandlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,16 @@ cfg_if::cfg_if! {
unsafe fn thread_stack() -> (usize, usize) {
let this_thread = libc::pthread_self();
let mut thread_attrs: libc::pthread_attr_t = mem::zeroed();
#[cfg(not(target_os = "freebsd"))]
libc::pthread_getattr_np(this_thread, &mut thread_attrs);
#[cfg(target_os = "freebsd")]
libc::pthread_attr_get_np(this_thread, &mut thread_attrs);
let mut stackaddr: *mut libc::c_void = ptr::null_mut();
let mut stacksize: libc::size_t = 0;
libc::pthread_attr_getstack(&thread_attrs, &mut stackaddr, &mut stacksize);
#[cfg(not(target_os = "freebsd"))]
let ok = libc::pthread_getattr_np(this_thread, &mut thread_attrs);
#[cfg(target_os = "freebsd")]
let ok = libc::pthread_attr_get_np(this_thread, &mut thread_attrs);
if ok == 0 {
libc::pthread_attr_getstack(&thread_attrs, &mut stackaddr, &mut stacksize);
libc::pthread_attr_destroy(&mut thread_attrs);
}
(stackaddr as usize, stacksize)
}

Expand Down

0 comments on commit 287deb1

Please sign in to comment.