Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Double free in final code when creating split on the first element of the list #300

Open
irbull opened this issue Jun 28, 2024 · 1 comment

Comments

@irbull
Copy link

irbull commented Jun 28, 2024

I am getting a double free when splitting on the first element in the list:

    #[test]
    fn test_double_free() {
        let mut list = LinkedList::new();
        list.push_back(7);
        list.push_back(8);
        list.push_back(9);

        let mut cur = list.cursor_mut();
        cur.move_next();
        cur.split_before();
    }

(╯°□°)╯︵ ┻━┻

@irbull
Copy link
Author

irbull commented Jun 28, 2024

The bug is when you are pointing at the first node and you call split_before

        // We have this:
        //
        //     list.front -> A <-> B <-> C <-> D <- list.back
        //                   ^
        //                  cur
        //
        //
        // And we want to produce this:
        //
        //     list.front -> A -> C <-> D <- list.back
        //                   ^
        //                  cur
        //
        //
        //    return.front -> None <- return.back

We don't set front and back to None in this case. The length is right (it's 0), but front and back point to a node.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant