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]: 2 successive py::scoped_interpreter -> double free or corruption (out) #5412

Open
2 of 3 tasks
user706 opened this issue Oct 15, 2024 · 1 comment
Open
2 of 3 tasks
Labels
triage New bug, unverified

Comments

@user706
Copy link

user706 commented Oct 15, 2024

Required prerequisites

What version (or hash if on master) of pybind11 are you using?

v2.13

Problem description

I get: double free or corruption (out)

Happens when having 2 successive non-overlapping py::scoped_interpreter (and doing module imports):

{
    py::scoped_interpreter inter;
    py::object imported = py::module::import("mysum"); // mysum.py imports e.g. numpy
}

{
    py::scoped_interpreter inter;                      // again
    py::object imported = py::module::import("mysum"); // crash !   double free or corruption (out)
}

Reproducible example code

Reproducible example: https://github.com/user706/pybind11_test

  • Fails only with numpy and py::array_t and "single" py::scoped_interpreter
    (~> branch main)
  • Does not fail, when having only single py::scoped_interpreter
    (~> branch works_when_having_only_single_scoped_interpreter -> see diff): why?
  • Does not fail, when changing to py::list
    (~> branch works_when_removing_numpy -> see diff): why? (perhaps because of no import)

Do this:

git clone https://github.com/user706/pybind11_test
cd pybind11_test
mkdir build/
cd    build/
cmake ..              # will clone https://github.com/pybind/pybind11.git (stable)
cmake --build . -j    # will also copy mysum.py into the build/ directory
./go                  # run (need a python with numpy)

result:

Sum is: 15
double free or corruption (out)
Aborted (core dumped)

It fails in this line, but only the 2nd time through the loop!!!

But if I simply change the following line
constexpr int NUM_LOOPS = 2;
to this
constexpr int NUM_LOOPS = 1;
then it will not fail.

Why does it fail with NUM_LOOPS = 2?
How can one fix it?

Thanks

Is this a regression? Put the last known working version here if it is.

Not a regression

@user706 user706 added the triage New bug, unverified label Oct 15, 2024
@user706
Copy link
Author

user706 commented Oct 16, 2024

Probably similar to this: #1439

=> But is there no way to have multiple successive (non-overlapping) py::scoped_interpreters ?

A criticial question could be:
what is the use of py::scoped_interpreter, if I cannot use 2 successive nonoverlapping instances of it???

@user706 user706 changed the title [BUG]: double free or corruption (out) [BUG]: 2 successive py::scoped_interpreter -> double free or corruption (out) Oct 16, 2024
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

1 participant