diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index b883b56434..dc2a95f9b3 100644 --- a/src/phyp/phyp_driver.c +++ b/src/phyp/phyp_driver.c @@ -491,7 +491,7 @@ phypUUIDTable_Push(virConnectPtr conn) struct stat local_fileinfo; char buffer[1024]; int rc = 0; - FILE *fd; + FILE *fd = NULL; size_t nread, sent; char *ptr; char local_file[] = "./uuid_table"; @@ -582,6 +582,7 @@ err: libssh2_channel_free(channel); channel = NULL; } + VIR_FORCE_FCLOSE(fd); return -1; } @@ -2039,6 +2040,7 @@ phypStorageVolCreateXML(virStoragePoolPtr pool, virStorageVolDefPtr voldef = NULL; virStoragePoolDefPtr spdef = NULL; virStorageVolPtr vol = NULL; + virStorageVolPtr dup_vol = NULL; char *key = NULL; if (VIR_ALLOC(spdef) < 0) { @@ -2085,8 +2087,9 @@ phypStorageVolCreateXML(virStoragePoolPtr pool, } /* checking if this name already exists on this system */ - if (phypVolumeLookupByName(pool, voldef->name) != NULL) { + if ((dup_vol = phypVolumeLookupByName(pool, voldef->name)) != NULL) { VIR_ERROR(_("StoragePool name already exists.")); + virUnrefStorageVol(dup_vol); goto err; } @@ -2260,7 +2263,7 @@ phypVolumeGetXMLDesc(virStorageVolPtr vol, unsigned int flags) virStorageVolDef voldef; virStoragePoolDef pool; virStoragePoolPtr sp; - char *xml; + char *xml = NULL; virCheckFlags(0, NULL); @@ -2270,23 +2273,23 @@ phypVolumeGetXMLDesc(virStorageVolPtr vol, unsigned int flags) sp = phypStoragePoolLookupByName(vol->conn, vol->pool); if (!sp) - goto err; + goto cleanup; if (sp->name != NULL) { pool.name = sp->name; } else { VIR_ERROR(_("Unable to determine storage sp's name.")); - goto err; + goto cleanup; } if (memcpy(pool.uuid, sp->uuid, VIR_UUID_BUFLEN) == NULL) { VIR_ERROR(_("Unable to determine storage sp's uuid.")); - goto err; + goto cleanup; } if ((pool.capacity = phypGetStoragePoolSize(sp->conn, sp->name)) == -1) { VIR_ERROR(_("Unable to determine storage sps's size.")); - goto err; + goto cleanup; } /* Information not avaliable */ @@ -2298,21 +2301,21 @@ phypVolumeGetXMLDesc(virStorageVolPtr vol, unsigned int flags) if ((pool.source.adapter = phypGetStoragePoolDevice(sp->conn, sp->name)) == NULL) { VIR_ERROR(_("Unable to determine storage sps's source adapter.")); - goto err; + goto cleanup; } if (vol->name != NULL) voldef.name = vol->name; else { VIR_ERROR(_("Unable to determine storage pool's name.")); - goto err; + goto cleanup; } voldef.key = strdup(vol->key); if (voldef.key == NULL) { virReportOOMError(); - goto err; + goto cleanup; } voldef.type = VIR_STORAGE_POOL_LOGICAL; @@ -2321,10 +2324,10 @@ phypVolumeGetXMLDesc(virStorageVolPtr vol, unsigned int flags) VIR_FREE(voldef.key); +cleanup: + if (sp) + virUnrefStoragePool(sp); return xml; - -err: - return NULL; } /* The Volume Group path here will be treated as suggested in the @@ -2710,20 +2713,23 @@ phypStoragePoolCreateXML(virConnectPtr conn, virCheckFlags(0, NULL); virStoragePoolDefPtr def = NULL; + virStoragePoolPtr dup_sp = NULL; virStoragePoolPtr sp = NULL; if (!(def = virStoragePoolDefParseString(xml))) goto err; /* checking if this name already exists on this system */ - if (phypStoragePoolLookupByName(conn, def->name) != NULL) { + if ((dup_sp = phypStoragePoolLookupByName(conn, def->name)) != NULL) { VIR_WARN("StoragePool name already exists."); + virUnrefStoragePool(dup_sp); goto err; } /* checking if ID or UUID already exists on this system */ - if (phypGetStoragePoolLookUpByUUID(conn, def->uuid) != NULL) { + if ((dup_sp = phypGetStoragePoolLookUpByUUID(conn, def->uuid)) != NULL) { VIR_WARN("StoragePool uuid already exists."); + virUnrefStoragePool(dup_sp); goto err; }