On 03/07/2014 10:37 AM, Ján Tomko wrote: > On 03/07/2014 03:55 PM, 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@xxxxxxxxxx> >> --- >> src/util/virscsi.c | 26 +++++++++++++++----------- >> 1 file changed, 15 insertions(+), 11 deletions(-) >> > >> @@ -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; > > These two commands would look better in an error label > >> + } >> >> return VIR_APPEND_ELEMENT(dev->used_by, dev->n_used_by, copy); > > and copy should be freed even if VIR_APPEND_ELEMENT fails. > > ACK with that fixed. > > Jan > Ah - right... thanks. I had myopia of the first degree only :-) Consider the following squashed in: diff --git a/src/util/virscsi.c b/src/util/virscsi.c index 66e3161..802f515 100644 --- a/src/util/virscsi.c +++ b/src/util/virscsi.c @@ -302,12 +302,17 @@ virSCSIDeviceSetUsedBy(virSCSIDevicePtr dev, if (VIR_ALLOC(copy) < 0) return -1; if (VIR_STRDUP(copy->drvname, drvname) < 0 || - VIR_STRDUP(copy->domname, domname) < 0) { - virSCSIDeviceUsedByInfoFree(copy); - return -1; - } + VIR_STRDUP(copy->domname, domname) < 0) + goto cleanup; + + if (VIR_APPEND_ELEMENT(dev->used_by, dev->n_used_by, copy) < 0) + goto cleanup; - return VIR_APPEND_ELEMENT(dev->used_by, dev->n_used_by, copy); + return 0; + +cleanup: + virSCSIDeviceUsedByInfoFree(copy); + return -1; } bool John -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list