So I have this c extension function which loads a python module and uses a list of c++ strings to get a specific global attribute from that module:
PyObject* get_global_constant(const char* module_name, std::vector<std::string> constant_names) {
/* Gets a global variable from a Python module */
PyObject *temp_module = PyImport_ImportModule(module_name);
PyObject *global_var = PyImport_AddModule(module_name);
for (std::string constant : constant_names) {
global_var = PyObject_GetAttrString(global_var, constant.c_str());
}
Py_DECREF(temp_module);
return global_var;
}
Does this leak?