if (!inst->pythonconf_dict) {
ERROR("Unable to create python dict for config");
error:
- if (inst->pythonconf_dict) {
- Py_DecRef(inst->pythonconf_dict);
- inst->pythonconf_dict = NULL;
- }
+ Py_XDECREF(inst->pythonconf_dict);
+ inst->pythonconf_dict = NULL;
python_error_log(inst, NULL);
return -1;
}
if ((python_module_import_config(inst, conf, module) < 0) ||
(python_module_import_constants(inst, module) < 0)) {
- Py_DecRef(module);
+ Py_DECREF(module);
return NULL;
}
* with Python C extensions if they use GIL lock functions.
*/
if (!inst->single_interpreter_mode || !global_module) {
+ PyObject *module;
+
/*
* Initialise a new Python 2.7 module, with our default methods
*/
- inst->module = Py_InitModule3("radiusd", module_methods, "FreeRADIUS python module");
- if (!inst->module) {
+ module = Py_InitModule3("radiusd", module_methods, "FreeRADIUS python module");
+ if (!module) {
ERROR("Failed creating module");
python_error_log(inst, NULL);
error:
+ Py_XDECREF(module);
PyEval_SaveThread();
return -1;
}
* module is owned by sys.modules, so we also need
* to own the module to prevent it being freed early.
*/
- Py_IncRef(inst->module);
+ Py_INCREF(module);
+
+ if ((python_module_import_config(inst, conf, module) < 0) ||
+ (python_module_import_constants(inst, module) < 0)) goto error;
- if ((python_module_import_config(inst, conf, inst->module) < 0) ||
- (python_module_import_constants(inst, inst->module) < 0)) goto error;
+ if (inst->single_interpreter_mode) global_module = module;
- if (inst->single_interpreter_mode) global_module = inst->module;
+ inst->module = module;
} else {
inst->module = global_module;
- Py_IncRef(inst->module);
+ Py_INCREF(inst->module);
inst->pythonconf_dict = PyObject_GetAttrString(inst->module, "config");
- Py_IncRef(inst->pythonconf_dict);
+ Py_INCREF(inst->pythonconf_dict);
}
path = python_path_build(inst, inst, conf);
* We incremented the reference count earlier
* during module initialisation.
*/
- Py_DecRef(inst->module);
+ Py_XDECREF(inst->module);
/*
* Only destroy if it's a subinterpreter
#endif
PYTHON_FUNC_DESTROY(detach);
- Py_DecRef(inst->pythonconf_dict);
+ Py_XDECREF(inst->pythonconf_dict);
PyEval_SaveThread();
/*