Skip to content

[BUG]: Simply creating subinterpreter leaks memory #5794

@justend29

Description

@justend29

Required prerequisites

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

90bc05c

Problem description

The mere use of a subinterpreter leaks memory. Memory leaks were found with python 3.12 and 3.13 For example:

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

int main() {
  pybind11::initialize_interpreter();
  const auto sub_python = pybind11::subinterpreter::create();
}

From the pybind11 project source, I am building this minimal example with the following command

g++ test.cpp -fsanitize=address  -I /usr/include/python3.13 -I ./include -l python3.13

Reference of g++ version:

g++ --version
g++ (GCC) 15.1.1 20250729
Copyright (C) 2025 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

The sanitizer's output is included as an attachment: sanitizer.txt

Reproducible example code

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

int main() {
  pybind11::initialize_interpreter();
  const auto sub_python = pybind11::subinterpreter::create();
}

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

Not a regression

Metadata

Metadata

Assignees

No one assigned

    Labels

    triageNew bug, unverified

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions