]> git.proxmox.com Git - mirror_qemu.git/commitdiff
scsi: fix memory leak
authorPaolo Bonzini <pbonzini@redhat.com>
Fri, 6 Apr 2012 12:12:42 +0000 (14:12 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Thu, 19 Apr 2012 08:31:05 +0000 (10:31 +0200)
scsibus_get_dev_path is leaking id if it is not NULL.  Fix it.

Reported-by: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
hw/scsi-bus.c

index 8e76c5d32c99af013d9a5db265629b2090ed873a..d847396c531bd634167a0cad53602d18a4576eff 100644 (file)
@@ -1430,15 +1430,18 @@ static char *scsibus_get_dev_path(DeviceState *dev)
     SCSIDevice *d = DO_UPCAST(SCSIDevice, qdev, dev);
     DeviceState *hba = dev->parent_bus->parent;
     char *id = NULL;
+    char *path;
 
     if (hba && hba->parent_bus && hba->parent_bus->info->get_dev_path) {
         id = hba->parent_bus->info->get_dev_path(hba);
     }
     if (id) {
-        return g_strdup_printf("%s/%d:%d:%d", id, d->channel, d->id, d->lun);
+        path = g_strdup_printf("%s/%d:%d:%d", id, d->channel, d->id, d->lun);
     } else {
-        return g_strdup_printf("%d:%d:%d", d->channel, d->id, d->lun);
+        path = g_strdup_printf("%d:%d:%d", d->channel, d->id, d->lun);
     }
+    g_free(id);
+    return path;
 }
 
 static char *scsibus_get_fw_dev_path(DeviceState *dev)