Eric, thanks for your review and comment, I will change patch with your advice then directly push. Alex ----- Original Message ----- From: "Eric Blake" <eblake@xxxxxxxxxx> To: "Alex Jia" <ajia@xxxxxxxxxx> Cc: libvir-list@xxxxxxxxxx Sent: Tuesday, March 20, 2012 11:46:51 PM Subject: Re: [PATCHv4] python: Avoid memory leaks on libvirt_virNodeGetMemoryStats On 03/20/2012 01:14 AM, Alex Jia wrote: > Detected by valgrind. Leaks are introduced in commit 17c7795. > > * python/libvirt-override.c (libvirt_virNodeGetMemoryStats): fix memory leaks > and improve codes return value. > > For details, please see the following link: > RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=770944 > > > Signed-off-by: Alex Jia <ajia@xxxxxxxxxx> > --- > python/libvirt-override.c | 41 +++++++++++++++++++++++++++++++---------- > 1 files changed, 31 insertions(+), 10 deletions(-) > for (i = 0; i < nparams; i++) { > - PyDict_SetItem(ret, > - libvirt_constcharPtrWrap(stats[i].field), > - libvirt_ulonglongWrap(stats[i].value)); > + key = libvirt_constcharPtrWrap(stats[i].field); > + val = libvirt_ulonglongWrap(stats[i].value); > + > + if (!key || !val) { > + ret = NULL; > + goto error; Memory leak of ret. > + } > + > + if (PyDict_SetItem(ret, key, val) < 0) { > + Py_DECREF(ret); > + ret = NULL; > + goto error; > + } Fix it by doing: if (!key || !val || PyDict_SetItem(ret, key, val) < 0) { Py_DECREF(ret); ret = NULL; goto error; } ACK with that fix. -- Eric Blake eblake@xxxxxxxxxx +1-919-301-3266 Libvirt virtualization library http://libvirt.org -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list