summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGraham Dumpleton <Graham.Dumpleton@gmail.com>2021-06-18 13:29:00 +1000
committerGraham Dumpleton <Graham.Dumpleton@gmail.com>2021-06-18 13:29:00 +1000
commitc6ffc0bcd7df5ed6bf3e670714bb244e62c3214e (patch)
treea7e529864344eafb74ce921710f5cb50b8a925ee
parent6edae02752484b3b1dc1f603e1ba085ff258df9c (diff)
downloadmod_wsgi-c6ffc0bcd7df5ed6bf3e670714bb244e62c3214e.tar.gz
Ensure log Python errors before doing reference decrements so don't loose error.
-rw-r--r--src/server/mod_wsgi.c38
1 files changed, 22 insertions, 16 deletions
diff --git a/src/server/mod_wsgi.c b/src/server/mod_wsgi.c
index b0492cc..ffc9061 100644
--- a/src/server/mod_wsgi.c
+++ b/src/server/mod_wsgi.c
@@ -3684,37 +3684,33 @@ static PyObject *wsgi_load_source(apr_pool_t *pool, request_rec *r,
}
io_module = PyImport_ImportModule("io");
- if (!io_module) {
+
+ if (!io_module)
goto load_source_finally;
- }
fileobject = PyObject_CallMethod(io_module, "open", "ss", filename, "rb");
- if (!fileobject) {
+
+ if (!fileobject)
goto load_source_finally;
- }
source_bytes_object = PyObject_CallMethod(fileobject, "read", "");
- if (!source_bytes_object) {
+
+ if (!source_bytes_object)
goto load_source_finally;
- }
result = PyObject_CallMethod(fileobject, "close", "");
- if (!result) {
+
+ if (!result)
goto load_source_finally;
- }
source_buf = PyBytes_AsString(source_bytes_object);
- if (!source_buf) {
+
+ if (!source_buf)
goto load_source_finally;
- }
co = Py_CompileString(source_buf, filename, Py_file_input);
load_source_finally:
- Py_XDECREF(io_module);
- Py_XDECREF(fileobject);
- Py_XDECREF(source_bytes_object);
- Py_XDECREF(result);
if (!co) {
Py_BEGIN_ALLOW_THREADS
if (r) {
@@ -3733,12 +3729,20 @@ load_source_finally:
wsgi_log_python_error(r, NULL, filename, 0);
+ Py_XDECREF(io_module);
+ Py_XDECREF(fileobject);
+ Py_XDECREF(source_bytes_object);
+ Py_XDECREF(result);
+
return NULL;
}
- m = PyImport_ExecCodeModuleEx((char *)name, co, (char *)filename);
+ Py_XDECREF(io_module);
+ Py_XDECREF(fileobject);
+ Py_XDECREF(source_bytes_object);
+ Py_XDECREF(result);
- Py_XDECREF(co);
+ m = PyImport_ExecCodeModuleEx((char *)name, co, (char *)filename);
if (m) {
PyObject *object = NULL;
@@ -3798,6 +3802,8 @@ load_source_finally:
}
}
+ Py_XDECREF(co);
+
return m;
}