[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH] qemuMonitorTextAddUSBDisk: avoid unconditional leak



First the patch, then the (fixed) function:

>From d3f0ee1ee11ca5f3709168fdc4e6eb1c56fdfbc0 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering redhat com>
Date: Tue, 16 Feb 2010 13:51:38 +0100
Subject: [PATCH] qemuMonitorTextAddUSBDisk: avoid unconditional leak

* src/qemu/qemu_monitor_text.c (qemuMonitorTextAddUSBDisk): Free
command output buffer.
---
 src/qemu/qemu_monitor_text.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c
index c71bf1d..62ffcc6 100644
--- a/src/qemu/qemu_monitor_text.c
+++ b/src/qemu/qemu_monitor_text.c
@@ -1229,6 +1229,7 @@ int qemuMonitorTextAddUSBDisk(qemuMonitorPtr mon,
 cleanup:
     VIR_FREE(cmd);
     VIR_FREE(safepath);
+    VIR_FREE(info);
     return ret;
 }

--
1.7.0.181.g41533



int qemuMonitorTextAddUSBDisk(qemuMonitorPtr mon,
                              const char *path)
{
    char *cmd = NULL;
    char *safepath;
    int ret = -1;
    char *info = NULL;

    safepath = qemuMonitorEscapeArg(path);
    if (!safepath) {
        virReportOOMError();
        return -1;
    }

    if (virAsprintf(&cmd, "usb_add disk:%s", safepath) < 0) {
        virReportOOMError();
        goto cleanup;
    }

    if (qemuMonitorCommand(mon, cmd, &info) < 0) {
        qemuReportError(VIR_ERR_INTERNAL_ERROR,
                        "%s", _("cannot run monitor command to add usb disk"));
        goto cleanup;
    }

    /* If the command failed qemu prints:
     * Could not add ... */
    if (strstr(info, "Could not add ")) {
        qemuReportError(VIR_ERR_OPERATION_FAILED,
                        _("unable to add USB disk %s: %s"), path, info);
        goto cleanup;
    }

    ret = 0;

cleanup:
    VIR_FREE(cmd);
    VIR_FREE(safepath);
    VIR_FREE(info);
    return ret;
}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]