pybind/pybind11

[BUG]: Potential leaks when using enum_

Open

#3 865 ouverte le 12 avr. 2022

Voir sur GitHub
 (9 commentaires) (0 réactions) (0 assignés)C++ (2 005 forks)batch import
help wanted

Métriques du dépôt

Stars
 (14 677 stars)
Métriques de merge PR
 (Merge moyen 5j 2h) (10 PRs mergées en 30 j)

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);
}

Guide contributeur