diff options
| author | Vytautas Astrauskas <astrauv@amazon.com> | 2020-04-01 12:46:14 -0700 |
|---|---|---|
| committer | Vytautas Astrauskas <astrauv@amazon.com> | 2020-04-01 12:46:14 -0700 |
| commit | baa6d557a7b965ff8277f940a43e0ce3df3b8913 (patch) | |
| tree | 9df4e2e35e838a428357e81a8cb0b1910d6fa273 /src/libstd/sys/cloudabi | |
| parent | 5382347064ac47a2a5ac56b57cec0d91b9b40edc (diff) | |
In Thread::new, add a comment that a panic could cause a memory leak.
Diffstat (limited to 'src/libstd/sys/cloudabi')
| -rw-r--r-- | src/libstd/sys/cloudabi/thread.rs | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/libstd/sys/cloudabi/thread.rs b/src/libstd/sys/cloudabi/thread.rs index 9d95a61c315..abc15b18e32 100644 --- a/src/libstd/sys/cloudabi/thread.rs +++ b/src/libstd/sys/cloudabi/thread.rs @@ -31,12 +31,15 @@ impl Thread { assert_eq!(libc::pthread_attr_setstacksize(&mut attr, stack_size), 0); let ret = libc::pthread_create(&mut native, &attr, thread_start, p as *mut _); + // Note: if the thread creation fails and this assert fails, then p will + // be leaked. However, an alternative design could cause double-free + // which is clearly worse. assert_eq!(libc::pthread_attr_destroy(&mut attr), 0); return if ret != 0 { // The thread failed to start and as a result p was not consumed. Therefore, it is // safe to reconstruct the box so that it gets deallocated. - let _ = Box::from_raw(p); + drop(Box::from_raw(p)); Err(io::Error::from_raw_os_error(ret)) } else { Ok(Thread { id: native }) |
