mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 14:15:28 +00:00
Fix multiple memory leaks in virsh
* virsh.c: fix a number of leaks of virDomain, virStoragePool, virNodeDevice, etc.
This commit is contained in:
parent
2cc33bfe20
commit
d26d18a1a6
32
src/virsh.c
32
src/virsh.c
@ -784,8 +784,10 @@ cmdDomblkstat (vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (!(dom = vshCommandOptDomain (ctl, cmd, &name)))
|
if (!(dom = vshCommandOptDomain (ctl, cmd, &name)))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (!(device = vshCommandOptString (cmd, "device", NULL)))
|
if (!(device = vshCommandOptString (cmd, "device", NULL))) {
|
||||||
|
virDomainFree(dom);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if (virDomainBlockStats (dom, device, &stats, sizeof stats) == -1) {
|
if (virDomainBlockStats (dom, device, &stats, sizeof stats) == -1) {
|
||||||
vshError (ctl, FALSE, _("Failed to get block stats %s %s"),
|
vshError (ctl, FALSE, _("Failed to get block stats %s %s"),
|
||||||
@ -840,8 +842,10 @@ cmdDomIfstat (vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (!(dom = vshCommandOptDomain (ctl, cmd, &name)))
|
if (!(dom = vshCommandOptDomain (ctl, cmd, &name)))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (!(device = vshCommandOptString (cmd, "interface", NULL)))
|
if (!(device = vshCommandOptString (cmd, "interface", NULL))) {
|
||||||
|
virDomainFree(dom);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if (virDomainInterfaceStats (dom, device, &stats, sizeof stats) == -1) {
|
if (virDomainInterfaceStats (dom, device, &stats, sizeof stats) == -1) {
|
||||||
vshError (ctl, FALSE, _("Failed to get interface stats %s %s"),
|
vshError (ctl, FALSE, _("Failed to get interface stats %s %s"),
|
||||||
@ -2528,6 +2532,7 @@ cmdNetworkAutostart(vshControl *ctl, const vshCmd *cmd)
|
|||||||
else
|
else
|
||||||
vshPrint(ctl, _("Network %s unmarked as autostarted\n"), name);
|
vshPrint(ctl, _("Network %s unmarked as autostarted\n"), name);
|
||||||
|
|
||||||
|
virNetworkFree(network);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2570,6 +2575,7 @@ cmdNetworkCreate(vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (network != NULL) {
|
if (network != NULL) {
|
||||||
vshPrint(ctl, _("Network %s created from %s\n"),
|
vshPrint(ctl, _("Network %s created from %s\n"),
|
||||||
virNetworkGetName(network), from);
|
virNetworkGetName(network), from);
|
||||||
|
virNetworkFree(network);
|
||||||
} else {
|
} else {
|
||||||
vshError(ctl, FALSE, _("Failed to create network from %s"), from);
|
vshError(ctl, FALSE, _("Failed to create network from %s"), from);
|
||||||
ret = FALSE;
|
ret = FALSE;
|
||||||
@ -2617,6 +2623,7 @@ cmdNetworkDefine(vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (network != NULL) {
|
if (network != NULL) {
|
||||||
vshPrint(ctl, _("Network %s defined from %s\n"),
|
vshPrint(ctl, _("Network %s defined from %s\n"),
|
||||||
virNetworkGetName(network), from);
|
virNetworkGetName(network), from);
|
||||||
|
virNetworkFree(network);
|
||||||
} else {
|
} else {
|
||||||
vshError(ctl, FALSE, _("Failed to define network from %s"), from);
|
vshError(ctl, FALSE, _("Failed to define network from %s"), from);
|
||||||
ret = FALSE;
|
ret = FALSE;
|
||||||
@ -2997,6 +3004,7 @@ cmdNetworkStart(vshControl *ctl, const vshCmd *cmd)
|
|||||||
virNetworkGetName(network));
|
virNetworkGetName(network));
|
||||||
ret = FALSE;
|
ret = FALSE;
|
||||||
}
|
}
|
||||||
|
virNetworkFree(network);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3035,6 +3043,7 @@ cmdNetworkUndefine(vshControl *ctl, const vshCmd *cmd)
|
|||||||
ret = FALSE;
|
ret = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virNetworkFree(network);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3071,6 +3080,7 @@ cmdNetworkUuid(vshControl *ctl, const vshCmd *cmd)
|
|||||||
else
|
else
|
||||||
vshError(ctl, FALSE, "%s", _("failed to get network UUID"));
|
vshError(ctl, FALSE, "%s", _("failed to get network UUID"));
|
||||||
|
|
||||||
|
virNetworkFree(network);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3329,6 +3339,7 @@ cmdInterfaceDefine(vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (iface != NULL) {
|
if (iface != NULL) {
|
||||||
vshPrint(ctl, _("Interface %s defined from %s\n"),
|
vshPrint(ctl, _("Interface %s defined from %s\n"),
|
||||||
virInterfaceGetName(iface), from);
|
virInterfaceGetName(iface), from);
|
||||||
|
virInterfaceFree (iface);
|
||||||
} else {
|
} else {
|
||||||
vshError(ctl, FALSE, _("Failed to define interface from %s"), from);
|
vshError(ctl, FALSE, _("Failed to define interface from %s"), from);
|
||||||
ret = FALSE;
|
ret = FALSE;
|
||||||
@ -3498,6 +3509,7 @@ cmdPoolAutostart(vshControl *ctl, const vshCmd *cmd)
|
|||||||
else
|
else
|
||||||
vshPrint(ctl, _("Pool %s unmarked as autostarted\n"), name);
|
vshPrint(ctl, _("Pool %s unmarked as autostarted\n"), name);
|
||||||
|
|
||||||
|
virStoragePoolFree(pool);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3541,6 +3553,7 @@ cmdPoolCreate(vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (pool != NULL) {
|
if (pool != NULL) {
|
||||||
vshPrint(ctl, _("Pool %s created from %s\n"),
|
vshPrint(ctl, _("Pool %s created from %s\n"),
|
||||||
virStoragePoolGetName(pool), from);
|
virStoragePoolGetName(pool), from);
|
||||||
|
virStoragePoolFree(pool);
|
||||||
} else {
|
} else {
|
||||||
vshError(ctl, FALSE, _("Failed to create pool from %s"), from);
|
vshError(ctl, FALSE, _("Failed to create pool from %s"), from);
|
||||||
ret = FALSE;
|
ret = FALSE;
|
||||||
@ -3594,6 +3607,7 @@ cmdNodeDeviceCreate(vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (dev != NULL) {
|
if (dev != NULL) {
|
||||||
vshPrint(ctl, _("Node device %s created from %s\n"),
|
vshPrint(ctl, _("Node device %s created from %s\n"),
|
||||||
virNodeDeviceGetName(dev), from);
|
virNodeDeviceGetName(dev), from);
|
||||||
|
virNodeDeviceFree(dev);
|
||||||
} else {
|
} else {
|
||||||
vshError(ctl, FALSE, _("Failed to create node device from %s"), from);
|
vshError(ctl, FALSE, _("Failed to create node device from %s"), from);
|
||||||
ret = FALSE;
|
ret = FALSE;
|
||||||
@ -3801,6 +3815,7 @@ cmdPoolDefine(vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (pool != NULL) {
|
if (pool != NULL) {
|
||||||
vshPrint(ctl, _("Pool %s defined from %s\n"),
|
vshPrint(ctl, _("Pool %s defined from %s\n"),
|
||||||
virStoragePoolGetName(pool), from);
|
virStoragePoolGetName(pool), from);
|
||||||
|
virStoragePoolFree(pool);
|
||||||
} else {
|
} else {
|
||||||
vshError(ctl, FALSE, _("Failed to define pool from %s"), from);
|
vshError(ctl, FALSE, _("Failed to define pool from %s"), from);
|
||||||
ret = FALSE;
|
ret = FALSE;
|
||||||
@ -3960,9 +3975,9 @@ cmdPoolDelete(vshControl *ctl, const vshCmd *cmd)
|
|||||||
} else {
|
} else {
|
||||||
vshError(ctl, FALSE, _("Failed to delete pool %s"), name);
|
vshError(ctl, FALSE, _("Failed to delete pool %s"), name);
|
||||||
ret = FALSE;
|
ret = FALSE;
|
||||||
virStoragePoolFree(pool);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virStoragePoolFree(pool);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4460,6 +4475,8 @@ cmdPoolStart(vshControl *ctl, const vshCmd *cmd)
|
|||||||
virStoragePoolGetName(pool));
|
virStoragePoolGetName(pool));
|
||||||
ret = FALSE;
|
ret = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virStoragePoolFree(pool);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4619,6 +4636,7 @@ cmdPoolUndefine(vshControl *ctl, const vshCmd *cmd)
|
|||||||
ret = FALSE;
|
ret = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virStoragePoolFree(pool);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4655,6 +4673,7 @@ cmdPoolUuid(vshControl *ctl, const vshCmd *cmd)
|
|||||||
else
|
else
|
||||||
vshError(ctl, FALSE, "%s", _("failed to get pool UUID"));
|
vshError(ctl, FALSE, "%s", _("failed to get pool UUID"));
|
||||||
|
|
||||||
|
virStoragePoolFree(pool);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4779,6 +4798,8 @@ cleanup:
|
|||||||
virStoragePoolFree(pool);
|
virStoragePoolFree(pool);
|
||||||
if (inputvol)
|
if (inputvol)
|
||||||
virStorageVolFree(inputvol);
|
virStorageVolFree(inputvol);
|
||||||
|
if (newvol)
|
||||||
|
virStorageVolFree(newvol);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4871,7 +4892,6 @@ cmdVolClone(vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (newvol != NULL) {
|
if (newvol != NULL) {
|
||||||
vshPrint(ctl, _("Vol %s cloned from %s\n"),
|
vshPrint(ctl, _("Vol %s cloned from %s\n"),
|
||||||
virStorageVolGetName(newvol), virStorageVolGetName(origvol));
|
virStorageVolGetName(newvol), virStorageVolGetName(origvol));
|
||||||
virStorageVolFree(newvol);
|
|
||||||
} else {
|
} else {
|
||||||
vshError(ctl, FALSE, _("Failed to clone vol from %s"),
|
vshError(ctl, FALSE, _("Failed to clone vol from %s"),
|
||||||
virStorageVolGetName(origvol));
|
virStorageVolGetName(origvol));
|
||||||
@ -4885,6 +4905,8 @@ cleanup:
|
|||||||
xmlFree(newxml);
|
xmlFree(newxml);
|
||||||
if (origvol)
|
if (origvol)
|
||||||
virStorageVolFree(origvol);
|
virStorageVolFree(origvol);
|
||||||
|
if (newvol)
|
||||||
|
virStorageVolFree(newvol);
|
||||||
if (origpool)
|
if (origpool)
|
||||||
virStoragePoolFree(origpool);
|
virStoragePoolFree(origpool);
|
||||||
return ret;
|
return ret;
|
||||||
@ -4924,9 +4946,9 @@ cmdVolDelete(vshControl *ctl, const vshCmd *cmd)
|
|||||||
} else {
|
} else {
|
||||||
vshError(ctl, FALSE, _("Failed to delete vol %s"), name);
|
vshError(ctl, FALSE, _("Failed to delete vol %s"), name);
|
||||||
ret = FALSE;
|
ret = FALSE;
|
||||||
virStorageVolFree(vol);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virStorageVolFree(vol);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user