diff --git a/plugins/python/pyloader.c b/plugins/python/pyloader.c index 771ec8ab..45b93091 100644 --- a/plugins/python/pyloader.c +++ b/plugins/python/pyloader.c @@ -524,7 +524,10 @@ PyObject *uwsgi_file_loader(void *arg1) { if (!callable) callable = "application"; wsgi_file_module = uwsgi_pyimport_by_filename("uwsgi_wsgi_file", filename); - // no need to check here for module import as it is already done by uwsgi_pyimport_by_file + if (!wsgi_file_module) { + PyErr_Print(); + exit(1); + } wsgi_file_dict = PyModule_GetDict(wsgi_file_module); if (!wsgi_file_dict) { diff --git a/plugins/python/python_plugin.c b/plugins/python/python_plugin.c index b60b3174..e5c693c9 100644 --- a/plugins/python/python_plugin.c +++ b/plugins/python/python_plugin.c @@ -195,12 +195,12 @@ PyObject *uwsgi_pyimport_by_filename(char *name, char *filename) { pyfile = fopen(filename, "r"); if (!pyfile) { uwsgi_log("failed to open python file %s\n", filename); - exit(1); + return NULL; } if (fstat(fileno(pyfile), &pystat)) { uwsgi_error("fstat()"); - exit(1); + return NULL; } if (S_ISDIR(pystat.st_mode)) { @@ -210,7 +210,9 @@ PyObject *uwsgi_pyimport_by_filename(char *name, char *filename) { pyfile = fopen(real_filename, "r"); if (!pyfile) { uwsgi_error_open(real_filename); - exit(1); + free(real_filename); + fclose(pyfile); + return NULL; } } @@ -218,7 +220,9 @@ PyObject *uwsgi_pyimport_by_filename(char *name, char *filename) { if (!py_file_node) { PyErr_Print(); uwsgi_log("failed to parse file %s\n", real_filename); - exit(1); + free(real_filename); + fclose(pyfile); + return NULL; } fclose(pyfile); @@ -232,7 +236,7 @@ PyObject *uwsgi_pyimport_by_filename(char *name, char *filename) { if (!py_file_node) { PyErr_Print(); uwsgi_log("failed to parse url %s\n", real_filename); - exit(1); + return NULL; } } } @@ -242,13 +246,13 @@ PyObject *uwsgi_pyimport_by_filename(char *name, char *filename) { if (!py_compiled_node) { PyErr_Print(); uwsgi_log("failed to compile python file %s\n", real_filename); - exit(1); + return NULL; } py_file_module = PyImport_ExecCodeModule(name, py_compiled_node); if (!py_file_module) { PyErr_Print(); - exit(1); + return NULL; } Py_DECREF(py_compiled_node); @@ -371,6 +375,10 @@ void init_uwsgi_vars() { else { // this is a filepath that need to be mapped tmp_module = uwsgi_pyimport_by_filename(up.pymodule_alias[i], value + 1); + if (!tmp_module) { + PyErr_Print(); + exit(1); + } } uwsgi_log("mapped virtual pymodule \"%s\" to real pymodule \"%s\"\n", up.pymodule_alias[i], value + 1); // reset original value