]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: spoa/python: Cleanup ipaddress objects if initialization fails
authorGilchrist Dadaglo <dadaglo@amazon.com>
Tue, 8 Dec 2020 14:37:12 +0000 (14:37 +0000)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 9 Dec 2020 07:39:31 +0000 (08:39 +0100)
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.

contrib/spoa_server/ps_python.c

index 12953f38045804cc5c60b14fb263eae565bdae4e..f2ddc165fd8ffa035ea9253e2e9bbeb1925f6805 100644 (file)
@@ -410,18 +410,24 @@ static int ps_python_start_worker(struct worker *w)
 
        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;
        }
 
        PY_INIT_MODULE(m, "spoa", spoa_methods, &spoa_module_definition);
        if (m == NULL) {
+               Py_DECREF(ipv4_address);
+               Py_DECREF(ipv6_address);
+               Py_DECREF(module_ipaddress);
                PyErr_Print();
                return 0;
        }