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

[BUG]: Crashed with importing ruptures package. #4150

Closed
2 of 3 tasks
leonleeann opened this issue Aug 22, 2022 · 3 comments
Closed
2 of 3 tasks

[BUG]: Crashed with importing ruptures package. #4150

leonleeann opened this issue Aug 22, 2022 · 3 comments
Labels
triage New bug, unverified

Comments

@leonleeann
Copy link

Required prerequisites

Problem description

I'm using pybind11 to build a c++ main program that importing a python package ruptures at runtime.

We can simplly install it by pip3 install ruptures.
I tried ruptures-1.1.6 and 1.1.7, results are same.

Once I call py::finalize_interpreter(); in c++, the program crashs.
Error output:

free(): invalid pointer

Reproducible example code

#include <pybind11/embed.h>
#include <pybind11/pybind11.h>

namespace py = pybind11;

int main() {
// 	py::scoped_interpreter guard {};
	py::initialize_interpreter();

	auto mod_py = py::module::import( "ruptures" );

	py::finalize_interpreter();
	return EXIT_SUCCESS;
};
@leonleeann leonleeann added the triage New bug, unverified label Aug 22, 2022
@henryiii
Copy link
Collaborator

I'm guessing this is #4105.

@henryiii
Copy link
Collaborator

This code is broken in both 2.9.2 and 2.10.0. If I remove the initialize_interpreter/finalize_interpreter and instead use the scooted_interpreture guard, it works fine in both 2.9.2 and 2.10.0.

@rwgk
Copy link
Collaborator

rwgk commented Oct 24, 2022

You can fix the reproducer in the PR description like this:

#include <pybind11/embed.h>
#include <pybind11/pybind11.h>

namespace py = pybind11;

int main() {
//      py::scoped_interpreter guard {};
        py::initialize_interpreter();

        {
            auto mod_py = py::module::import( "ruptures" );
        }

        py::finalize_interpreter();
        return EXIT_SUCCESS;
}

With the original reproducer, mod_py is destructed only after the interpreter is finalized, causing a SEGFAULT in Python/pystate.c _Py_GetConfig() in my environment (I used gdb to see that). (The free(): invalid pointer you saw is probably just another symptom of undefined behavior.)

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

No branches or pull requests

3 participants