pybind/pybind11

[BUG]: Potential leaks when using enum_

Open

#3,865 建立於 2022年4月12日

在 GitHub 查看
 (9 留言) (0 反應) (0 負責人)C++ (14,677 star) (2,005 fork)batch import
help wanted

描述

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

貢獻者指南