[libvirt] [PATCH] virsh.c: avoid leak on OOM error path

Jim Meyering jim at meyering.net
Fri Feb 19 17:09:13 UTC 2010


No one really cares if we leak memory while dying, but who knows...
freeing that buffer may let us go down more gracefully.

FYI, the leak is triggered when virFileReadAll succeeds
(it allocates "buffer"), yet xmlNewDoc fails:

    if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0)
        return FALSE;

    doc = xmlNewDoc(NULL);
    if (doc == NULL)
        goto no_memory;


>From 03c7a44e3d5b2e7c992bebc98fc8c6a7bf63881e Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering at redhat.com>
Date: Fri, 19 Feb 2010 18:03:41 +0100
Subject: [PATCH] virsh.c: avoid leak on OOM error path

* tools/virsh.c (cmdCPUBaseline): Also free "buffer" upon OOM.
---
 tools/virsh.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index dd916f3..8756a7a 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -7139,6 +7139,7 @@ cleanup:
     return ret;

 no_memory:
+    VIR_FREE(buffer);
     vshError(ctl, "%s", _("Out of memory"));
     ret = FALSE;
     return ret;
--
1.7.0.233.g05e1a




More information about the libvir-list mailing list