[libvirt] [PATCH] cpu: Fix memory leaks in x86FeatureLoad and x86ModelLoad

Also backup and restore the original ctxt->node value in x86FeatureLoad. --- src/cpu/cpu_x86.c | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-) diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c index af0a65b..7c50261 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -274,6 +274,7 @@ x86FeatureLoad(xmlXPathContextPtr ctxt, { struct x86_map *map = data; xmlNodePtr *nodes = NULL; + xmlNodePtr ctxt_node = ctxt->node; struct x86_feature *feature = NULL; int ret = 0; int i; @@ -340,6 +341,9 @@ x86FeatureLoad(xmlXPathContextPtr ctxt, } out: + ctxt->node = ctxt_node; + VIR_FREE(nodes); + return ret; no_memory: @@ -664,6 +668,7 @@ x86ModelLoad(xmlXPathContextPtr ctxt, } out: + VIR_FREE(nodes); return ret; no_memory: -- 1.6.0.4

On Tue, Dec 22, 2009 at 02:14:21AM +0100, Matthias Bolte wrote:
Also backup and restore the original ctxt->node value in x86FeatureLoad. --- src/cpu/cpu_x86.c | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c index af0a65b..7c50261 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -274,6 +274,7 @@ x86FeatureLoad(xmlXPathContextPtr ctxt, { struct x86_map *map = data; xmlNodePtr *nodes = NULL; + xmlNodePtr ctxt_node = ctxt->node; struct x86_feature *feature = NULL; int ret = 0; int i; @@ -340,6 +341,9 @@ x86FeatureLoad(xmlXPathContextPtr ctxt, }
out: + ctxt->node = ctxt_node; + VIR_FREE(nodes); + return ret;
ah, right we are changing ctxt->node there, good catch !
no_memory: @@ -664,6 +668,7 @@ x86ModelLoad(xmlXPathContextPtr ctxt, }
out: + VIR_FREE(nodes); return ret;
no_memory:
Yup, ACK thanks ! 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/

diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c index af0a65b..7c50261 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -274,6 +274,7 @@ x86FeatureLoad(xmlXPathContextPtr ctxt, { struct x86_map *map = data; xmlNodePtr *nodes = NULL; + xmlNodePtr ctxt_node = ctxt->node; struct x86_feature *feature = NULL; int ret = 0; int i; @@ -340,6 +341,9 @@ x86FeatureLoad(xmlXPathContextPtr ctxt, }
out: + ctxt->node = ctxt_node; + VIR_FREE(nodes); + return ret;
ah, right we are changing ctxt->node there, good catch !
Although this function is expected to change ctxt->node so the caller sets it to its original value after x86FeatureLoad returns. But this can't hurt. Good catch with VIR_FREE(nodes), I forgot to do so. Jirka

On Tue, Dec 22, 2009 at 12:08:43PM +0100, Jiri Denemark wrote:
diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c index af0a65b..7c50261 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -274,6 +274,7 @@ x86FeatureLoad(xmlXPathContextPtr ctxt, { struct x86_map *map = data; xmlNodePtr *nodes = NULL; + xmlNodePtr ctxt_node = ctxt->node; struct x86_feature *feature = NULL; int ret = 0; int i; @@ -340,6 +341,9 @@ x86FeatureLoad(xmlXPathContextPtr ctxt, }
out: + ctxt->node = ctxt_node; + VIR_FREE(nodes); + return ret;
ah, right we are changing ctxt->node there, good catch !
Although this function is expected to change ctxt->node so the caller sets it to its original value after x86FeatureLoad returns. But this can't hurt.
So far we are trying to keep this preserved by function calls, this is way easier to track. 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/

On Tue, Dec 22, 2009 at 02:14:21AM +0100, Matthias Bolte wrote:
Also backup and restore the original ctxt->node value in x86FeatureLoad. --- src/cpu/cpu_x86.c | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c index af0a65b..7c50261 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -274,6 +274,7 @@ x86FeatureLoad(xmlXPathContextPtr ctxt, { struct x86_map *map = data; xmlNodePtr *nodes = NULL; + xmlNodePtr ctxt_node = ctxt->node; struct x86_feature *feature = NULL; int ret = 0; int i; @@ -340,6 +341,9 @@ x86FeatureLoad(xmlXPathContextPtr ctxt, }
out: + ctxt->node = ctxt_node; + VIR_FREE(nodes); + return ret;
no_memory: @@ -664,6 +668,7 @@ x86ModelLoad(xmlXPathContextPtr ctxt, }
out: + VIR_FREE(nodes); return ret;
no_memory:
ACK Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
participants (4)
-
Daniel P. Berrange
-
Daniel Veillard
-
Jiri Denemark
-
Matthias Bolte