Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plugins/python: Fix a memory leak coming from PyBytes_FromString #2697

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions plugins/python/uwsgi_pymodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2141,6 +2141,24 @@ PyObject *py_uwsgi_spooler_jobs(PyObject * self, PyObject * args) {
}


#ifdef PYTHREE
static PyObject *uwsgi_py_dict_get(PyObject *a, const char *key) {
PyObject *key_bytes = PyBytes_FromString(key);
PyObject *result = PyDict_GetItem(a, key_bytes);
Py_DECREF(key_bytes);
return result;
}

static void uwsgi_py_dict_del(PyObject *a, const char *key) {
PyObject *key_bytes = PyBytes_FromString(key);
PyDict_DelItem(a, key_bytes);
Py_DECREF(key_bytes);
}
#else
#define uwsgi_py_dict_get(a, b) PyDict_GetItemString(a, b)
#define uwsgi_py_dict_del(a, b) PyDict_DelItemString(a, b)
#endif

PyObject *py_uwsgi_send_spool(PyObject * self, PyObject * args, PyObject *kw) {
PyObject *spool_dict, *spool_vars;
PyObject *zero, *key, *val;
Expand Down
4 changes: 0 additions & 4 deletions plugins/python/uwsgi_python.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,10 @@ PyAPI_FUNC(PyObject *) PyMarshal_ReadObjectFromString(char *, Py_ssize_t);
#define PyString_Concat PyBytes_Concat
#define PyString_AsString (char *) PyBytes_AsString
#define PyFile_FromFile(A,B,C,D) PyFile_FromFd(fileno((A)), (B), (C), -1, NULL, NULL, NULL, 0)
#define uwsgi_py_dict_get(a, b) PyDict_GetItem(a, PyBytes_FromString(b));
#define uwsgi_py_dict_del(a, b) PyDict_DelItem(a, PyBytes_FromString(b));

#else
#define UWSGI_PYFROMSTRING(x) PyString_FromString(x)
#define UWSGI_PYFROMSTRINGSIZE(x, y) PyString_FromStringAndSize(x, y)
#define uwsgi_py_dict_get(a, b) PyDict_GetItemString(a, b)
#define uwsgi_py_dict_del(a, b) PyDict_DelItemString(a, b)
#endif

#define LOADER_DYN 0
Expand Down