Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx> --- src/test/test_driver.c | 41 +++++++++-------------------------------- 1 file changed, 9 insertions(+), 32 deletions(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 6806ffd..986f215 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -1243,10 +1243,6 @@ testOpenVolumesForPool(const char *file, if (!def) goto error; - if (VIR_REALLOC_N(pool->volumes.objs, - pool->volumes.count+1) < 0) - goto error; - if (def->target.path == NULL) { if (virAsprintf(&def->target.path, "%s/%s", pool->def->target.path, @@ -1256,12 +1252,12 @@ testOpenVolumesForPool(const char *file, if (!def->key && VIR_STRDUP(def->key, def->target.path) < 0) goto error; + if (VIR_APPEND_ELEMENT_COPY(pool->volumes.objs, pool->volumes.count, def) < 0) + goto error; pool->def->allocation += def->allocation; pool->def->available = (pool->def->capacity - pool->def->allocation); - - pool->volumes.objs[pool->volumes.count++] = def; def = NULL; } @@ -5459,24 +5455,20 @@ testStorageVolCreateXML(virStoragePoolPtr pool, goto cleanup; } - 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; - if (VIR_STRDUP(privvol->key, privvol->target.path) < 0) + if (VIR_STRDUP(privvol->key, privvol->target.path) < 0 || + VIR_APPEND_ELEMENT_COPY(privpool->volumes.objs, + privpool->volumes.count, privvol) < 0) goto cleanup; privpool->def->allocation += privvol->allocation; privpool->def->available = (privpool->def->capacity - privpool->def->allocation); - privpool->volumes.objs[privpool->volumes.count++] = privvol; - ret = virGetStorageVol(pool->conn, privpool->def->name, privvol->name, privvol->key, NULL, NULL); @@ -5547,24 +5539,20 @@ testStorageVolCreateXMLFrom(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; - if (VIR_STRDUP(privvol->key, privvol->target.path) < 0) + if (VIR_STRDUP(privvol->key, privvol->target.path) < 0 || + VIR_APPEND_ELEMENT_COPY(privpool->volumes.objs, + privpool->volumes.count, privvol) < 0) goto cleanup; privpool->def->allocation += privvol->allocation; privpool->def->available = (privpool->def->capacity - privpool->def->allocation); - privpool->volumes.objs[privpool->volumes.count++] = privvol; - ret = virGetStorageVol(pool->conn, privpool->def->name, privvol->name, privvol->key, NULL, NULL); @@ -5624,18 +5612,7 @@ testStorageVolDelete(virStorageVolPtr vol, if (privpool->volumes.objs[i] == privvol) { 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