From: Zhigang Wang <zhigang.x.wang@oracle.com>
To: xen-devel@lists.xenproject.org
Cc: Zhigang Wang <zhigang.x.wang@oracle.com>
Subject: [PATCH] python/xc: add missing Py_DECREF() to fix a memory leak
Date: Fri, 28 Aug 2015 17:35:18 -0400 [thread overview]
Message-ID: <1440797718-28045-1-git-send-email-zhigang.x.wang@oracle.com> (raw)
Python PyList_Append() will increase reference count of the item. We have to
decrease its reference count to let it garbage collected.
We missed the Py_DECREF() for 'cpuinfo_obj' here, thus we have a memory leak.
The memory leak could be easily confirmed by:
# python
>>> import xen.lowlevel.xc
>>> xc = xen.lowlevel.xc.xc()
>>> for i in range(1000): xc.getcpuinfo(1)
And check the python process memory usage before and after:
# ps f -o vsize,rss,%mem,size,cmd -p <pid>
Signed-off-by: Zhigang Wang <zhigang.x.wang@oracle.com>
---
tools/python/xen/lowlevel/xc/xc.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/tools/python/xen/lowlevel/xc/xc.c b/tools/python/xen/lowlevel/xc/xc.c
index 2c36eb2..9a161d3 100644
--- a/tools/python/xen/lowlevel/xc/xc.c
+++ b/tools/python/xen/lowlevel/xc/xc.c
@@ -1210,6 +1210,7 @@ static PyObject *pyxc_getcpuinfo(XcObject *self, PyObject *args, PyObject *kwds)
for (i = 0; i < nr_cpus; i++) {
cpuinfo_obj = Py_BuildValue("{s:k}", "idletime", cpuinfo_ptr->idletime);
PyList_Append(cpuinfo_list_obj, cpuinfo_obj);
+ Py_DECREF(cpuinfo_obj);
cpuinfo_ptr++;
}
--
2.1.0
next reply other threads:[~2015-08-28 21:35 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-28 21:35 Zhigang Wang [this message]
2015-08-31 12:04 ` [PATCH] python/xc: add missing Py_DECREF() to fix a memory leak Wei Liu
2015-08-31 12:27 ` Andrew Cooper
2015-08-31 12:32 ` Wei Liu
2015-09-01 11:07 ` Ian Campbell
2015-09-01 11:37 ` Ian Campbell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1440797718-28045-1-git-send-email-zhigang.x.wang@oracle.com \
--to=zhigang.x.wang@oracle.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).