BUG/MINOR: contrib/spoa-server: Updating references to free in case of failure
authorGilchrist Dadaglo <dadaglo@amazon.com>
Mon, 24 Aug 2020 19:21:34 +0000 (19:21 +0000)
committerChristopher Faulet <cfaulet@haproxy.com>
Mon, 7 Sep 2020 07:31:30 +0000 (09:31 +0200)
When we encounter a failure, all previously borrowed references should
be freed. Especially if the program is not failing immediately

This patch must be backported as far as 2.0.

(cherry picked from commit 2417ebcc013b23ac961afb436b9b2dead32c28b0)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 9fe95de0df2748362fddc4acf84dd19c40de6a9f)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>

contrib/spoa_server/ps_python.c

index dd4e63d..3ad9323 100644 (file)
@@ -458,6 +458,7 @@ static int ps_python_exec_message(struct worker *w, void *ref, int nargs, struct
                key = PyString_FromString("name");
                if (key == NULL) {
                        Py_DECREF(kw_args);
+                       Py_DECREF(ent);
                        PyErr_Print();
                        return 0;
                }
@@ -523,6 +524,7 @@ static int ps_python_exec_message(struct worker *w, void *ref, int nargs, struct
                        if (func == NULL) {
                                Py_DECREF(kw_args);
                                Py_DECREF(ent);
+                               Py_DECREF(key);
                                PyErr_Print();
                                return 0;
                        }
@@ -530,6 +532,7 @@ static int ps_python_exec_message(struct worker *w, void *ref, int nargs, struct
                        if (ip_dict == NULL) {
                                Py_DECREF(kw_args);
                                Py_DECREF(ent);
+                               Py_DECREF(key);
                                Py_DECREF(func);
                                PyErr_Print();
                                return 0;
@@ -538,6 +541,7 @@ static int ps_python_exec_message(struct worker *w, void *ref, int nargs, struct
                        if (ip_name == NULL) {
                                Py_DECREF(kw_args);
                                Py_DECREF(ent);
+                               Py_DECREF(key);
                                Py_DECREF(func);
                                Py_DECREF(ip_dict);
                                PyErr_Print();
@@ -547,6 +551,7 @@ static int ps_python_exec_message(struct worker *w, void *ref, int nargs, struct
                        if (ip_value == NULL) {
                                Py_DECREF(kw_args);
                                Py_DECREF(ent);
+                               Py_DECREF(key);
                                Py_DECREF(func);
                                Py_DECREF(ip_dict);
                                Py_DECREF(ip_name);
@@ -557,6 +562,10 @@ static int ps_python_exec_message(struct worker *w, void *ref, int nargs, struct
                        Py_DECREF(ip_name);
                        Py_DECREF(ip_value);
                        if (ret == -1) {
+                               Py_DECREF(kw_args);
+                               Py_DECREF(ent);
+                               Py_DECREF(key);
+                               Py_DECREF(func);
                                Py_DECREF(ip_dict);
                                PyErr_Print();
                                return 0;