On 07/03/14 22:55, John Ferlan wrote:
This resolves a Coverity RESOURCE_LEAK issue introduced by commit
id 'de6fa535' where the virSCSIDeviceSetUsedBy() didn't VIR_FREE
the 'copy' or possibly VIR_STRDUP()'d values.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/util/virscsi.c | 26 +++++++++++++++-----------
1 file changed, 15 insertions(+), 11 deletions(-)
diff --git a/src/util/virscsi.c b/src/util/virscsi.c
index 69eae24..66e3161 100644
--- a/src/util/virscsi.c
+++ b/src/util/virscsi.c
@@ -268,6 +268,14 @@ cleanup:
return ret;
}
+static void
+virSCSIDeviceUsedByInfoFree(virUsedByInfoPtr used_by)
+{
+ VIR_FREE(used_by->drvname);
+ VIR_FREE(used_by->domname);
+ VIR_FREE(used_by);
+}
+
void
virSCSIDeviceFree(virSCSIDevicePtr dev)
{
@@ -279,11 +287,8 @@ virSCSIDeviceFree(virSCSIDevicePtr dev)
VIR_FREE(dev->id);
VIR_FREE(dev->name);
VIR_FREE(dev->sg_path);
- for (i = 0; i < dev->n_used_by; i++) {
- VIR_FREE(dev->used_by[i]->drvname);
- VIR_FREE(dev->used_by[i]->domname);
- VIR_FREE(dev->used_by[i]);
- }
+ for (i = 0; i < dev->n_used_by; i++)
+ virSCSIDeviceUsedByInfoFree(dev->used_by[i]);
VIR_FREE(dev->used_by);
VIR_FREE(dev);
}
@@ -296,10 +301,11 @@ virSCSIDeviceSetUsedBy(virSCSIDevicePtr dev,
virUsedByInfoPtr copy;
if (VIR_ALLOC(copy) < 0)
return -1;
- if (VIR_STRDUP(copy->drvname, drvname) < 0)
- return -1;
- if (VIR_STRDUP(copy->domname, domname) < 0)
+ if (VIR_STRDUP(copy->drvname, drvname) < 0 ||
+ VIR_STRDUP(copy->domname, domname) < 0) {
+ virSCSIDeviceUsedByInfoFree(copy);
return -1;
+ }
return VIR_APPEND_ELEMENT(dev->used_by, dev->n_used_by, copy);
}
@@ -449,9 +455,7 @@ virSCSIDeviceListDel(virSCSIDeviceListPtr list,
if (STREQ_NULLABLE(dev->used_by[i]->drvname, drvname) &&
STREQ_NULLABLE(dev->used_by[i]->domname, domname)) {
if (dev->n_used_by > 1) {
- VIR_FREE(dev->used_by[i]->drvname);
- VIR_FREE(dev->used_by[i]->domname);
- VIR_FREE(dev->used_by[i]);
+ virSCSIDeviceUsedByInfoFree(dev->used_by[i]);
VIR_DELETE_ELEMENT(dev->used_by, i, dev->n_used_by);
} else {
tmp = virSCSIDeviceListSteal(list, dev);
ACK