Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx> --- src/parallels/parallels_driver.c | 15 ++++----------- src/parallels/parallels_storage.c | 32 ++++++++------------------------ 2 files changed, 12 insertions(+), 35 deletions(-) diff --git a/src/parallels/parallels_driver.c b/src/parallels/parallels_driver.c index 33260ef..2cba3ca 100644 --- a/src/parallels/parallels_driver.c +++ b/src/parallels/parallels_driver.c @@ -231,11 +231,9 @@ parallelsAddSerialInfo(virDomainChrDefPtr **serials, size_t *nserials, if (parallelsGetSerialInfo(chr, key, value)) goto cleanup; - if (VIR_REALLOC_N(*serials, *nserials + 1) < 0) + if (VIR_APPEND_ELEMENT(*serials, *nserials, chr) < 0) goto cleanup; - (*serials)[(*nserials)++] = chr; - return 0; cleanup: @@ -273,11 +271,9 @@ parallelsAddVideoInfo(virDomainDefPtr def, virJSONValuePtr value) if (VIR_ALLOC(accel) < 0) goto error; - if (VIR_REALLOC_N(def->videos, def->nvideos + 1) < 0) + if (VIR_APPEND_ELEMENT_COPY(def->videos, def->nvideos, video) < 0) goto error; - def->videos[def->nvideos++] = video; - video->type = VIR_DOMAIN_VIDEO_TYPE_VGA; video->vram = mem << 20; video->heads = 1; @@ -386,11 +382,9 @@ parallelsAddHddInfo(virDomainDefPtr def, const char *key, virJSONValuePtr value) if (parallelsGetHddInfo(def, disk, key, value)) goto error; - if (VIR_REALLOC_N(def->disks, def->ndisks + 1) < 0) + if (VIR_APPEND_ELEMENT(def->disks, def->ndisks, disk) < 0) goto error; - def->disks[def->ndisks++] = disk; - return 0; error: @@ -625,10 +619,9 @@ parallelsAddVNCInfo(virDomainDefPtr def, virJSONValuePtr jobj_root) gr->listens[0].type = VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS; - if (VIR_REALLOC_N(def->graphics, def->ngraphics + 1) < 0) + if (VIR_APPEND_ELEMENT(def->graphics, def->ngraphics, gr) < 0) goto cleanup; - def->graphics[def->ngraphics++] = gr; return 0; cleanup: diff --git a/src/parallels/parallels_storage.c b/src/parallels/parallels_storage.c index bb5066f..b5a1a4c 100644 --- a/src/parallels/parallels_storage.c +++ b/src/parallels/parallels_storage.c @@ -311,11 +311,9 @@ static int parallelsAddDiskVolume(virStoragePoolObjPtr pool, if (VIR_STRDUP(def->key, def->target.path) < 0) goto error; - if (VIR_REALLOC_N(pool->volumes.objs, pool->volumes.count + 1) < 0) + if (VIR_APPEND_ELEMENT(pool->volumes.objs, pool->volumes.count, def) < 0) goto error; - pool->volumes.objs[pool->volumes.count++] = def; - return 0; no_memory: virReportOOMError(); @@ -1229,9 +1227,6 @@ parallelsStorageVolDefineXML(virStoragePoolObjPtr pool, } } - if (VIR_REALLOC_N(pool->volumes.objs, pool->volumes.count + 1) < 0) - goto cleanup; - if (virAsprintf(&privvol->target.path, "%s/%s", pool->def->target.path, privvol->name) < 0) goto cleanup; @@ -1255,7 +1250,9 @@ parallelsStorageVolDefineXML(virStoragePoolObjPtr pool, pool->def->allocation); } - pool->volumes.objs[pool->volumes.count++] = privvol; + if (VIR_APPEND_ELEMENT_COPY(pool->volumes.objs, + pool->volumes.count, privvol) < 0) + goto cleanup; ret = privvol; privvol = NULL; @@ -1362,10 +1359,6 @@ parallelsStorageVolCreateXMLFrom(virStoragePoolPtr pool, privpool->def->available = (privpool->def->capacity - privpool->def->allocation); - if (VIR_REALLOC_N(privpool->volumes.objs, - privpool->volumes.count + 1) < 0) - goto cleanup; - if (virAsprintf(&privvol->target.path, "%s/%s", privpool->def->target.path, privvol->name) == -1) goto cleanup; @@ -1377,7 +1370,9 @@ parallelsStorageVolCreateXMLFrom(virStoragePoolPtr pool, privpool->def->available = (privpool->def->capacity - privpool->def->allocation); - privpool->volumes.objs[privpool->volumes.count++] = privvol; + if (VIR_APPEND_ELEMENT_COPY(privpool->volumes.objs, + privpool->volumes.count, privvol) < 0) + goto cleanup; ret = virGetStorageVol(pool->conn, privpool->def->name, privvol->name, privvol->key, @@ -1416,18 +1411,7 @@ int parallelsStorageVolDefRemove(virStoragePoolObjPtr privpool, virStorageVolDefFree(privvol); - if (i < (privpool->volumes.count - 1)) - memmove(privpool->volumes.objs + i, - privpool->volumes.objs + i + 1, - sizeof(*(privpool->volumes.objs)) * - (privpool->volumes.count - (i + 1))); - - if (VIR_REALLOC_N(privpool->volumes.objs, - privpool->volumes.count - 1) < 0) { - ; /* Failure to reduce memory allocation isn't fatal */ - } - privpool->volumes.count--; - + VIR_DELETE_ELEMENT(privpool->volumes.objs, i, privpool->volumes.count); break; } } -- 1.9.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list