Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix double drop in StreamExt::cycle#903

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
yoshuawuyts merged 1 commit intoasync-rs:masterfromtaiki-e:stream-cycle
Nov 5, 2020

Conversation

taiki-e
Copy link
Contributor

StreamExt::cycle dropsource field without updating field ifsource field's destructor panicked.

ManuallyDrop::drop(&mut this.source);
this.source =ManuallyDrop::new(this.orig.clone());

This is unsound because it causes double drop if the user catches panic in the scope where theCycle is alive.

Repro:

#[test]#[should_panic(expected ="second")]fntest(){use async_std::stream::*;use futures::task::{noop_waker,Context,Poll};use std::{panic, pin::Pin, thread};#[derive(Clone,Default)]structS{dropped:bool,}implStreamforS{typeItem =();fnpoll_next(self:Pin<&mutSelf>, _:&mutContext<'_>) ->Poll<Option<Self::Item>>{Poll::Ready(None)}}implDropforS{fndrop(&mutself){if !thread::panicking(){if std::mem::replace(&mutself.dropped,true){panic!("second")}else{panic!("first")}}}}letmut s =Box::pin(S::default().cycle());let w =noop_waker();let cx =&mutContext::from_waker(&w);let _ = panic::catch_unwind(panic::AssertUnwindSafe(||{let _ = s.as_mut().poll_next(cx);// <-- dropped the first clone of `s`}));// <-- dropped the first clone of`s` again since `source` field wasn't updated}

lovesegfault and yoshuawuyts reacted with heart emoji
Copy link
Contributor

@yoshuawuytsyoshuawuyts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Oh, thanks for catching this!

@yoshuawuytsyoshuawuyts merged commita2ea3c7 intoasync-rs:masterNov 5, 2020
@taiki-etaiki-e deleted the stream-cycle branchNovember 5, 2020 11:28
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@yoshuawuytsyoshuawuytsyoshuawuyts approved these changes

@dignifiedquiredignifiedquireAwaiting requested review from dignifiedquire

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@taiki-e@yoshuawuyts

[8]ページ先頭

©2009-2025 Movatter.jp