Skip to content

Panics on drop will cause double drops. #3

Closed

Description

@Stebalien

IntoIter and ArrayVec need to be poisoned to prevent dropping before being drained; otherwise, if one of the elements panics on drop, it will be dropped twice. I've worked on a couple of solutions but they all have design tradeoffs so I figured I'd just let you fix it.

Drain doesn't have this issue because the ArrayVec's length is set to 0 when the Drain is initialized.

Activity

  1. Stebalien commented on Aug 20, 2015

    @Stebalien
    Author

    Test cases (abusing rust's panic on drop -> abort).

    #[test]
    #[should_panic]
    fn test_drop_panic() {
        struct DropPanic;
    
        impl Drop for DropPanic {
            fn drop(&mut self) {
                panic!("drop");
            }
        }
    
        let mut array = ArrayVec::<[DropPanic; 1]>::new();
        array.push(DropPanic);
    }
    
    #[test]
    #[should_panic]
    fn test_drop_panic_into_iter() {
        struct DropPanic;
    
        impl Drop for DropPanic {
            fn drop(&mut self) {
                panic!("drop");
            }
        }
    
        let mut array = ArrayVec::<[DropPanic; 1]>::new();
        array.push(DropPanic);
        array.into_iter();
    }
  2. bluss commented on Aug 20, 2015

    @bluss
    Owner

    Thanks! I guess this won't be easy..

  3. added 2 commits that reference this issue on Aug 20, 2015
    34cc319
    9be5400
  4. added a commit that references this issue on Aug 20, 2015
    24473a8
  5. bluss commented on Aug 20, 2015

    @bluss
    Owner

    For the lols, please read #5. Hey you said you would leave it for me to fix! But I do think you have the sane version, and I the insane..

  6. added a commit that references this issue on Aug 20, 2015
    c35760e
  7. bluss commented on Aug 21, 2015

    @bluss
    Owner

    Fixed in version 0.3.10. Use (unstable) feature flag nodrop/no_drop_flag to recover size. (However, it's not completely equivalent in terms of overhead, even if the size is the same.)

  8. bluss commented on Aug 21, 2015

    @bluss
    Owner

    Great, now it's fixed in smallvec too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions