pybind/pybind11

[BUG]: Potential leaks when using enum_

Open

#3,865 opened on Apr 12, 2022

View on GitHub
 (9 comments) (0 reactions) (0 assignees)C++ (2,005 forks)batch import
help wanted

Repository metrics

Stars
 (14,677 stars)
PR merge metrics
 (Avg merge 5d 2h) (10 merged PRs in 30d)

Description

Required prerequisites

Problem description

Dear team, Asan reports possible memory leaks when wrapping enum from C++ (using py::enum_, precisely when a call to the value method is done.

Wrapping struct (using py::class_) seems to raise no leaks.

Config : python3.8 / gcc8.3, pybind v2.9.2

May be related to https://github.com/pybind/pybind11/issues/3228

Reproducible example code

#include <pybind11/pybind11.h>

enum Egg {
  Bar,
  Spam,  
};


namespace py = pybind11;

PYBIND11_MODULE(example, m) {
    py::enum_<Egg>(m, "Egg")
      .value("Bar", Egg::Bar)
      .value("Spam", Egg::Spam);
}

Contributor guide