Skip to content

Commit b1c2475

Browse files
committed
Fix reference count issue in pyref module function
1 parent b76d90f commit b1c2475

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

c++/cpp2py/pyref.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ namespace cpp2py {
101101
/// Import the module and returns a pyref to it
102102
static pyref module(std::string const &module_name) {
103103
// Maybe the module was already imported?
104-
PyObject *mod = PyImport_GetModule(PyUnicode_FromString(module_name.c_str()));
104+
pyref mod_name = PyUnicode_FromString(module_name.c_str());
105+
PyObject *mod = PyImport_GetModule(mod_name);
105106

106107
// If not, import normally
107108
if (mod == nullptr) mod = PyImport_ImportModule(module_name.c_str());

0 commit comments

Comments
 (0)