[libvirt] [PATCH] Fix a virsh edit memory leak

When running virsh edit, we are unlinking and setting the tmp variable to NULL before going to the end of the function, meaning that we never free tmp. Since the exit to the function will always unlink and free tmp, just remove this bit of code and let it get done at the end. Signed-off-by: Chris Lalancette <clalance@redhat.com> --- tools/virsh.c | 3 --- 1 files changed, 0 insertions(+), 3 deletions(-) diff --git a/tools/virsh.c b/tools/virsh.c index 04b47a1..ab099da 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -8066,9 +8066,6 @@ cmdEdit (vshControl *ctl, const vshCmd *cmd) doc_edited = editReadBackFile (ctl, tmp); if (!doc_edited) goto cleanup; - unlink (tmp); - tmp = NULL; - /* Compare original XML with edited. Has it changed at all? */ if (STREQ (doc, doc_edited)) { vshPrint (ctl, _("Domain %s XML configuration not changed.\n"), -- 1.6.6.1

On 04/28/2010 02:27 PM, Chris Lalancette wrote:
When running virsh edit, we are unlinking and setting the tmp variable to NULL before going to the end of the function, meaning that we never free tmp. Since the exit to the function will always unlink and free tmp, just remove this bit of code and let it get done at the end.
ACK. By the way, should we add another patch to warn if unlink() fails for any reason? -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

On 04/28/2010 04:27 PM, Chris Lalancette wrote:
When running virsh edit, we are unlinking and setting the tmp variable to NULL before going to the end of the function, meaning that we never free tmp. Since the exit to the function will always unlink and free tmp, just remove this bit of code and let it get done at the end.
Note that the same change is required for cmdInterfaceEdit and cmdNWFilterEdit (which were both cut-paste from cmdEdit). I just sent a patch. (Sorry I didn't notice it earlier and thus missed the release - I've been away from mail and was just catching up.)
participants (3)
-
Chris Lalancette
-
Eric Blake
-
Laine Stump