mirror of
https://github.com/AuxXxilium/kmod.git
synced 2024-12-24 18:56:46 +07:00
python: add proper error handling to loaded_modules()
We need to check the result of basically all Py* calls and cleanup properly if they fail.
This commit is contained in:
parent
31aa6834ba
commit
705187f17b
@ -97,15 +97,32 @@ kmod_obj_loaded_modules(PyObject *self, PyObject *unused_args)
|
||||
}
|
||||
|
||||
PyObject *pylist = PyList_New(0);
|
||||
if (!pylist) {
|
||||
kmod_module_unref_list(list);
|
||||
return PyErr_NoMemory();
|
||||
}
|
||||
|
||||
/* refcountapallooza. */
|
||||
kmod_list_foreach(itr, list) {
|
||||
struct kmod_module *mod = kmod_module_get_module(itr);
|
||||
const char *name = kmod_module_get_name(mod);
|
||||
long size = kmod_module_get_size(mod);
|
||||
|
||||
PyObject *entry = Py_BuildValue("(sl)", name, size);
|
||||
if (!entry) {
|
||||
Py_DECREF(pylist);
|
||||
kmod_module_unref(mod);
|
||||
kmod_module_unref_list(list);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyList_Append(pylist, entry);
|
||||
if (PyList_Append(pylist, entry) == -1) {
|
||||
Py_DECREF(entry);
|
||||
Py_DECREF(pylist);
|
||||
kmod_module_unref(mod);
|
||||
kmod_module_unref_list(list);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_DECREF(entry);
|
||||
kmod_module_unref(mod);
|
||||
|
Loading…
Reference in New Issue
Block a user