Test failing for unknown reason


#1

All I can see is

error: An unknown error occurred

build log - https://travis-ci.org/mmrath/rbuf

Individually all tests are passing locally. but cargo test is failing locally as well for same reason as travis


#2

Not sure if I looked at the right place, but the log there has a segfault towards the end.


#3

It is a plain old segfault. Fortunately your crate only has 2 lines of unsafe code so we know the bug must be in one of those.

unsafe {
    let val = self.values[index].swap(&mut None, Ordering::SeqCst);
    bucket.push((*val).take().unwrap());
}

Here the None is part of the stack frame of this function and goes out of scope, which leaves &mut None (of type *mut Option<V>) as a dangling pointer.


#4

@dtolnay Thank you very much. I was wondering why the behaviour is not consistent, this answers. I will try to resolve.


#5

You’ve got to love how Rust makes it so easy to find memory issues…


#6

Coming from Java, this is so different though. I was finally able to resolve the problem.