summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorIlya Maximets <i.maximets@ovn.org>2022-07-22 21:16:42 +0200
committerIlya Maximets <i.maximets@ovn.org>2022-07-29 17:00:12 +0200
commit099d1c7454477bbb0245ac1f5aed7c4061c65e91 (patch)
treeddc11781785034d930fe258a5756100493459bae /python
parent318adf3f333868465040e1dd338ef3ee2866febe (diff)
downloadopenvswitch-099d1c7454477bbb0245ac1f5aed7c4061c65e91.tar.gz
python-c-ext: Handle initialization failures.
PyModule_AddObject() may fail and it doesn't steal references in this case. The error condition should be handled to avoid possible memory leaks. And while it's not strictly specified if PyModule_Create may fail, most of the examples in python documentation include handling of a NULL case. Acked-by: Mike Pattrick <mkp@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
Diffstat (limited to 'python')
-rw-r--r--python/ovs/_json.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/python/ovs/_json.c b/python/ovs/_json.c
index 0b980038b..c36a140a8 100644
--- a/python/ovs/_json.c
+++ b/python/ovs/_json.c
@@ -229,9 +229,17 @@ PyInit__json(void)
if (PyType_Ready(&json_ParserType) < 0) {
return NULL;
}
+
m = PyModule_Create(&moduledef);
+ if (!m) {
+ return NULL;
+ }
Py_INCREF(&json_ParserType);
- PyModule_AddObject(m, "Parser", (PyObject *) & json_ParserType);
+ if (PyModule_AddObject(m, "Parser", (PyObject *) &json_ParserType) < 0) {
+ Py_DECREF(&json_ParserType);
+ Py_DECREF(m);
+ return NULL;
+ }
return m;
}