[Libvir] [PATCH] Avoid two more leaks.

Here are two more: Avoid two more leaks. * src/capabilities.c (virCapabilitiesFree): Free host.migrateTrans. (virCapabilitiesFreeGuest): Free arch.name member. Signed-off-by: Jim Meyering <meyering@redhat.com> --- src/capabilities.c | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-) diff --git a/src/capabilities.c b/src/capabilities.c index 2544bd3..bedd445 100644 --- a/src/capabilities.c +++ b/src/capabilities.c @@ -91,6 +91,7 @@ virCapabilitiesFreeGuest(virCapsGuestPtr guest) int i; free(guest->ostype); + free(guest->arch.name); free(guest->arch.defaultInfo.emulator); free(guest->arch.defaultInfo.loader); for (i = 0 ; i < guest->arch.defaultInfo.nmachines ; i++) @@ -130,6 +131,10 @@ virCapabilitiesFree(virCapsPtr caps) { virCapabilitiesFreeHostNUMACell(caps->host.numaCell[i]); free(caps->host.numaCell); + for (i = 0 ; i < caps->host.nmigrateTrans ; i++) + free(caps->host.migrateTrans[i]); + free(caps->host.migrateTrans); + free(caps->host.arch); free(caps); } -- 1.5.4.3.366.g55277

On Mon, Mar 03, 2008 at 11:40:35AM +0100, Jim Meyering wrote:
Here are two more:
Avoid two more leaks. * src/capabilities.c (virCapabilitiesFree): Free host.migrateTrans. (virCapabilitiesFreeGuest): Free arch.name member.
Signed-off-by: Jim Meyering <meyering@redhat.com> --- src/capabilities.c | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/src/capabilities.c b/src/capabilities.c index 2544bd3..bedd445 100644 --- a/src/capabilities.c +++ b/src/capabilities.c @@ -91,6 +91,7 @@ virCapabilitiesFreeGuest(virCapsGuestPtr guest) int i; free(guest->ostype);
+ free(guest->arch.name); free(guest->arch.defaultInfo.emulator); free(guest->arch.defaultInfo.loader); for (i = 0 ; i < guest->arch.defaultInfo.nmachines ; i++) @@ -130,6 +131,10 @@ virCapabilitiesFree(virCapsPtr caps) { virCapabilitiesFreeHostNUMACell(caps->host.numaCell[i]); free(caps->host.numaCell);
+ for (i = 0 ; i < caps->host.nmigrateTrans ; i++) + free(caps->host.migrateTrans[i]); + free(caps->host.migrateTrans);
Okay, i would have checked caps->host.nmigrateTrans against NULL first but it seems other code in that routine do similar things with sub arrays, i assume it's fine then, +1 Daniel -- Red Hat Virtualization group http://redhat.com/virtualization/ Daniel Veillard | virtualization library http://libvirt.org/ veillard@redhat.com | libxml GNOME XML XSLT toolkit http://xmlsoft.org/ http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/

Daniel Veillard <veillard@redhat.com> wrote: ... Thanks for the quick feedback.
Okay, i would have checked caps->host.nmigrateTrans against NULL first
If I were to do that, "make distcheck" would detect the redundant if-before-free and make the build fail.
but it seems other code in that routine do similar things with sub arrays, i assume it's fine then,
+1

On Mon, Mar 03, 2008 at 11:50:30AM +0100, Jim Meyering wrote:
Daniel Veillard <veillard@redhat.com> wrote: ... Thanks for the quick feedback.
Okay, i would have checked caps->host.nmigrateTrans against NULL first
If I were to do that, "make distcheck" would detect the redundant if-before-free and make the build fail.
My point is that if you access caps->host.migrateTrans[i] then you should make sure caps->host.migrateTrans is not NULL, whether it's freed or not later is orthogonal. Daniel -- Red Hat Virtualization group http://redhat.com/virtualization/ Daniel Veillard | virtualization library http://libvirt.org/ veillard@redhat.com | libxml GNOME XML XSLT toolkit http://xmlsoft.org/ http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/

Daniel Veillard <veillard@redhat.com> wrote:
On Mon, Mar 03, 2008 at 11:50:30AM +0100, Jim Meyering wrote:
Daniel Veillard <veillard@redhat.com> wrote: ... Thanks for the quick feedback.
Okay, i would have checked caps->host.nmigrateTrans against NULL first
If I were to do that, "make distcheck" would detect the redundant if-before-free and make the build fail.
My point is that if you access caps->host.migrateTrans[i] then you should make sure caps->host.migrateTrans is not NULL,
That's ok because it's guarded by nmigrateTrans > 0, which is true IFF migrateTrans is non-NULL -- see virCapabilitiesAddHostMigrateTransport.
participants (2)
-
Daniel Veillard
-
Jim Meyering