From 341cfd90b6cbc102280cd6f2dd71117125e89f0b Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Sat, 9 Mar 2013 16:17:18 +0100 Subject: [PATCH] plugin/python: fix a leak in symimporter_load_module Reported by Coverity as CID #971058. --- plugins/python/symimporter.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/plugins/python/symimporter.c b/plugins/python/symimporter.c index d24c7122..9f845f8c 100644 --- a/plugins/python/symimporter.c +++ b/plugins/python/symimporter.c @@ -335,28 +335,31 @@ shit: if (code_start) { code_end = name_to_symbol_pkg(fullname2, "end"); if (code_end) { + char *symbolized; PyObject *mod = PyImport_AddModule(fullname); if (!mod) goto clear; PyObject *dict = PyModule_GetDict(mod); if (!dict) goto clear; source = uwsgi_concat2n(code_start, code_end-code_start, "", 0); - modname = uwsgi_concat3("sym://", symbolize(fullname), "___init___py"); + symbolized = symbolize(fullname); + modname = uwsgi_concat3("sym://", symbolized, "___init___py"); PyObject *pkgpath = Py_BuildValue("[O]", PyString_FromString(modname)); PyDict_SetItemString(dict, "__path__", pkgpath); PyDict_SetItemString(dict, "__loader__", self); - code = Py_CompileString(source, modname, Py_file_input); - if (!code) { - PyErr_Print(); - goto shit2; - } + code = Py_CompileString(source, modname, Py_file_input); + if (!code) { + PyErr_Print(); + goto shit2; + } mod = PyImport_ExecCodeModuleEx(fullname, code, modname); Py_DECREF(code); shit2: + free(symbolized); free(source); free(modname); free(fullname2);