[libvirt] [PATCH] virsh-domain: Fix memleak in cmdUndefine with storage

When undefining a domain with storage when the volume isn't managed by libvirt the name and path strings weren't freed properly. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=996050 --- tools/virsh-domain.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 8cafce4..57065e4 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -3048,6 +3048,8 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd) for (i = 0; i < nvolumes; i++) { ctxt->node = vol_nodes[i]; + VIR_FREE(source); + VIR_FREE(target); /* get volume source and target paths */ if (!(target = virXPathString("string(./target/@dev)", ctxt))) @@ -3090,6 +3092,8 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd) } vlist[nvols].source = source; vlist[nvols].target = target; + source = NULL; + target = NULL; nvols++; } @@ -3189,6 +3193,8 @@ out: } cleanup: + VIR_FREE(source); + VIR_FREE(target); for (i = 0; i < nvols; i++) { VIR_FREE(vlist[i].source); VIR_FREE(vlist[i].target); -- 1.8.3.2

On 08/12/2013 08:13 AM, Peter Krempa wrote:
When undefining a domain with storage when the volume isn't managed by libvirt the name and path strings weren't freed properly.
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=996050 --- tools/virsh-domain.c | 6 ++++++ 1 file changed, 6 insertions(+)
ACK. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On 08/12/2013 04:13 PM, Peter Krempa wrote:
When undefining a domain with storage when the volume isn't managed by libvirt the name and path strings weren't freed properly.
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=996050 --- tools/virsh-domain.c | 6 ++++++ 1 file changed, 6 insertions(+)
@@ -3090,6 +3092,8 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd) } vlist[nvols].source = source; vlist[nvols].target = target; + source = NULL; + target = NULL; nvols++; }
Using VIR_APPEND_ELEMENT here might look nicer, but that's just cosmetic. However this patch is incomplete - there's also a leak of volume_tokens mentioned in the bug that you didn't address: ==19011== 10 bytes in 1 blocks are definitely lost in loss record 14 of 82 ==19011== at 0x4A069EE: malloc (vg_replace_malloc.c:270) ==19011== by 0x38F0881041: strdup (in /lib64/libc-2.12.so) ==19011== by 0x40EB00: _vshStrdup (virsh.c:129) ==19011== by 0x40FC28: vshStringToArray (virsh.c:182) ==19011== by 0x414A66: cmdUndefine (virsh-domain.c:2609) ==19011== by 0x40D200: vshCommandRun (virsh.c:1652) ==19011== by 0x410964: main (virsh.c:3073) Maybe virStringSplit would give us an array that's easier to steal from? Jan

On 08/12/13 17:25, Ján Tomko wrote:
On 08/12/2013 04:13 PM, Peter Krempa wrote:
When undefining a domain with storage when the volume isn't managed by libvirt the name and path strings weren't freed properly.
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=996050 --- tools/virsh-domain.c | 6 ++++++ 1 file changed, 6 insertions(+)
@@ -3090,6 +3092,8 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd) } vlist[nvols].source = source; vlist[nvols].target = target; + source = NULL; + target = NULL; nvols++; }
Using VIR_APPEND_ELEMENT here might look nicer, but that's just cosmetic.
However this patch is incomplete - there's also a leak of volume_tokens mentioned in the bug that you didn't address:
==19011== 10 bytes in 1 blocks are definitely lost in loss record 14 of 82 ==19011== at 0x4A069EE: malloc (vg_replace_malloc.c:270) ==19011== by 0x38F0881041: strdup (in /lib64/libc-2.12.so) ==19011== by 0x40EB00: _vshStrdup (virsh.c:129) ==19011== by 0x40FC28: vshStringToArray (virsh.c:182) ==19011== by 0x414A66: cmdUndefine (virsh-domain.c:2609) ==19011== by 0x40D200: vshCommandRun (virsh.c:1652) ==19011== by 0x410964: main (virsh.c:3073)
Maybe virStringSplit would give us an array that's easier to steal from?
I'll be addressing that issue in a separate refactor
Jan
I pushed this patch according to Eric's ACK. Thanks for the review. Peter
participants (3)
-
Eric Blake
-
Ján Tomko
-
Peter Krempa