[libvirt] [PATCH] free memory properly in cleanup patch

virsh schedinfo inactive-domain will trigger the problem. --- daemon/remote.c | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-) diff --git a/daemon/remote.c b/daemon/remote.c index 1c98bba..eedbc77 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -945,8 +945,11 @@ remoteDispatchDomainGetSchedulerParameters(struct qemud_server *server ATTRIBUTE cleanup: if (rv < 0) { remoteDispatchError(rerr); - for (i = 0 ; i < nparams ; i++) - VIR_FREE(ret->params.params_val[i].field); + if (ret->params.params_val) { + for (i = 0 ; i < nparams ; i++) + VIR_FREE(ret->params.params_val[i].field); + VIR_FREE(ret->params.params_val); + } } if (dom) virDomainFree(dom); -- 1.7.3.1

On Tue, Apr 26, 2011 at 09:20:31AM +0800, Hu Tao wrote:
virsh schedinfo inactive-domain will trigger the problem. --- daemon/remote.c | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/daemon/remote.c b/daemon/remote.c index 1c98bba..eedbc77 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -945,8 +945,11 @@ remoteDispatchDomainGetSchedulerParameters(struct qemud_server *server ATTRIBUTE cleanup: if (rv < 0) { remoteDispatchError(rerr); - for (i = 0 ; i < nparams ; i++) - VIR_FREE(ret->params.params_val[i].field); + if (ret->params.params_val) { + for (i = 0 ; i < nparams ; i++) + VIR_FREE(ret->params.params_val[i].field); + VIR_FREE(ret->params.params_val); + } } if (dom) virDomainFree(dom);
ACK, a daemon leak, good fix ! Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/

At 2011-4-27 14:40, Daniel Veillard write:
On Tue, Apr 26, 2011 at 09:20:31AM +0800, Hu Tao wrote:
virsh schedinfo inactive-domain will trigger the problem.
I can reproduce this problem, and it will cause libvirtd crashed. I use gdb to analyze the core file, and see ret->params.params_val is NULL. So this patch is good fix.
--- daemon/remote.c | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/daemon/remote.c b/daemon/remote.c index 1c98bba..eedbc77 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -945,8 +945,11 @@ remoteDispatchDomainGetSchedulerParameters(struct qemud_server *server ATTRIBUTE cleanup: if (rv< 0) { remoteDispatchError(rerr); - for (i = 0 ; i< nparams ; i++) - VIR_FREE(ret->params.params_val[i].field); + if (ret->params.params_val) { + for (i = 0 ; i< nparams ; i++) + VIR_FREE(ret->params.params_val[i].field); + VIR_FREE(ret->params.params_val); + } } if (dom) virDomainFree(dom);
ACK, a daemon leak, good fix !
Thanks, applied.
Daniel
participants (3)
-
Daniel Veillard
-
Hu Tao
-
Wen Congyang