From fb910ae92b4a489e9b31f9ec545bde9d09d6a40e Mon Sep 17 00:00:00 2001 From: Wenzel Jakob Date: Wed, 11 Dec 2019 21:26:46 +0100 Subject: [PATCH] Revert "Fix a memory leak when creating Python3 modules. (#2019)" This reverts commit 819802da9926535714acf2bffe690b04f90cb12b. --- include/pybind11/pybind11.h | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 8e9c55d1a..d95d61f7b 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -794,16 +794,11 @@ public: explicit module(const char *name, const char *doc = nullptr) { if (!options::show_user_defined_docstrings()) doc = nullptr; #if PY_MAJOR_VERSION >= 3 - PyModuleDef *def = PyMem_New(PyModuleDef, 1); + PyModuleDef *def = new PyModuleDef(); std::memset(def, 0, sizeof(PyModuleDef)); def->m_name = name; def->m_doc = doc; def->m_size = -1; - def->m_free = [](void* module ) { - if (module != nullptr) { - Py_XDECREF(PyModule_GetDef((PyObject*) module)); - } - }; Py_INCREF(def); m_ptr = PyModule_Create(def); #else