BUG/MINOR: spoa/python: Cleanup ipaddress objects if initialization fails
This change is to ensure objects from the ipaddress module are cleaned
up when spoa module initialization fails.
In general the interpreter would just crash, but in a code where import
is conditional (try/except), then we would keep those objects around
This patch must be backported as far as 2.0.
(cherry picked from commit d1c0cf80bceb352b6bf33064b352f6dbe2b0b39c)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 7dde8ae61ee58ef8457f9c9ab6d908fa8c01ea2b)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit f090f0e357fd97fabd99465d2084a5d1e77e77f5)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit f3c1e799a62126a0d4fd2a26c75bf3df545cf13b)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
diff --git a/contrib/spoa_server/ps_python.c b/contrib/spoa_server/ps_python.c
index 3ce85c8..b383680 100644
--- a/contrib/spoa_server/ps_python.c
+++ b/contrib/spoa_server/ps_python.c
@@ -304,18 +304,24 @@
ipv4_address = PyObject_GetAttrString(module_ipaddress, "IPv4Address");
if (ipv4_address == NULL) {
+ Py_DECREF(module_ipaddress);
PyErr_Print();
return 0;
}
ipv6_address = PyObject_GetAttrString(module_ipaddress, "IPv6Address");
if (ipv6_address == NULL) {
+ Py_DECREF(ipv4_address);
+ Py_DECREF(module_ipaddress);
PyErr_Print();
return 0;
}
m = Py_InitModule("spoa", spoa_methods);
if (m == NULL) {
+ Py_DECREF(ipv4_address);
+ Py_DECREF(ipv6_address);
+ Py_DECREF(module_ipaddress);
PyErr_Print();
return 0;
}