Use virAppendElement instead of virInsertElementsN to implement
VIR_APPEND_ELEMENT_COPY which allows us to remove error handling as the
only relevant errors were removed when switching to aborting memory
allocation functions.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/conf/domain_conf.c | 29 +++++------------------------
src/conf/nwfilter_conf.c | 12 +++---------
src/conf/virnwfilterobj.c | 8 ++------
src/cpu/cpu_x86.c | 12 ++++--------
src/logging/log_handler.c | 6 ++----
src/openvz/openvz_conf.c | 5 ++---
src/qemu/qemu_domain.c | 6 +-----
src/qemu/qemu_hotplug.c | 6 ++----
src/util/viralloc.h | 4 ++--
src/util/virfirewall.c | 8 ++------
tests/nwfilterxml2firewalltest.c | 7 +------
11 files changed, 26 insertions(+), 77 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 09da4ab952..8d13e2de8e 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -16573,8 +16573,7 @@ virDomainMemoryInsert(virDomainDef *def,
return -1;
}
- if (VIR_APPEND_ELEMENT_COPY(def->mems, def->nmems, mem) < 0)
- return -1;
+ VIR_APPEND_ELEMENT_COPY(def->mems, def->nmems, mem);
virDomainDefSetMemoryTotal(def, memory + mem->size);
@@ -17141,10 +17140,7 @@ virDomainDefAddController(virDomainDef *def, int type, int idx,
int model)
cont->idx = idx;
cont->model = model;
- if (VIR_APPEND_ELEMENT_COPY(def->controllers, def->ncontrollers, cont) < 0)
{
- VIR_FREE(cont);
- return NULL;
- }
+ VIR_APPEND_ELEMENT_COPY(def->controllers, def->ncontrollers, cont);
return cont;
}
@@ -22780,15 +22776,9 @@ virDomainIOThreadIDAdd(virDomainDef *def,
iothrid->iothread_id = iothread_id;
- if (VIR_APPEND_ELEMENT_COPY(def->iothreadids, def->niothreadids,
- iothrid) < 0)
- goto error;
+ VIR_APPEND_ELEMENT_COPY(def->iothreadids, def->niothreadids, iothrid);
return iothrid;
-
- error:
- virDomainIOThreadIDDefFree(iothrid);
- return NULL;
}
@@ -29304,13 +29294,9 @@ virDomainGraphicsListenAppendAddress(virDomainGraphicsDef *def,
glisten.address = g_strdup(address);
- if (VIR_APPEND_ELEMENT_COPY(def->listens, def->nListens, glisten) < 0)
- goto error;
+ VIR_APPEND_ELEMENT_COPY(def->listens, def->nListens, glisten);
return 0;
- error:
- VIR_FREE(glisten.address);
- return -1;
}
@@ -29326,14 +29312,9 @@ virDomainGraphicsListenAppendSocket(virDomainGraphicsDef *def,
glisten.socket = g_strdup(socketPath);
- if (VIR_APPEND_ELEMENT_COPY(def->listens, def->nListens, glisten) < 0)
- goto error;
+ VIR_APPEND_ELEMENT_COPY(def->listens, def->nListens, glisten);
return 0;
-
- error:
- VIR_FREE(glisten.socket);
- return -1;
}
diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c
index 6fced96865..fc81fd97ea 100644
--- a/src/conf/nwfilter_conf.c
+++ b/src/conf/nwfilter_conf.c
@@ -394,11 +394,9 @@ virNWFilterRuleDefAddString(virNWFilterRuleDef *nwf,
const char *string,
size_t maxstrlen)
{
- char *tmp;
+ char *tmp = g_strndup(string, maxstrlen);
- tmp = g_strndup(string, maxstrlen);
- if (VIR_APPEND_ELEMENT_COPY(nwf->strings, nwf->nstrings, tmp) < 0)
- VIR_FREE(tmp);
+ VIR_APPEND_ELEMENT_COPY(nwf->strings, nwf->nstrings, tmp);
return tmp;
}
@@ -2696,11 +2694,7 @@ virNWFilterDefParseXML(xmlXPathContextPtr ctxt)
}
if (entry->rule || entry->include) {
- if (VIR_APPEND_ELEMENT_COPY(ret->filterEntries,
- ret->nentries, entry) < 0) {
- virNWFilterEntryFree(entry);
- goto cleanup;
- }
+ VIR_APPEND_ELEMENT_COPY(ret->filterEntries, ret->nentries, entry);
} else {
virNWFilterEntryFree(entry);
}
diff --git a/src/conf/virnwfilterobj.c b/src/conf/virnwfilterobj.c
index b64fdb9670..c3b2eb048c 100644
--- a/src/conf/virnwfilterobj.c
+++ b/src/conf/virnwfilterobj.c
@@ -371,12 +371,8 @@ virNWFilterObjListAssignDef(virNWFilterObjList *nwfilters,
if (!(obj = virNWFilterObjNew()))
return NULL;
- if (VIR_APPEND_ELEMENT_COPY(nwfilters->objs,
- nwfilters->count, obj) < 0) {
- virNWFilterObjUnlock(obj);
- virNWFilterObjFree(obj);
- return NULL;
- }
+ VIR_APPEND_ELEMENT_COPY(nwfilters->objs, nwfilters->count, obj);
+
obj->def = def;
return obj;
diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
index a4792c21da..0238cef8a3 100644
--- a/src/cpu/cpu_x86.c
+++ b/src/cpu/cpu_x86.c
@@ -514,9 +514,8 @@ virCPUx86DataAddItem(virCPUx86Data *data,
if ((existing = virCPUx86DataGet(data, item))) {
virCPUx86DataItemSetBits(existing, item);
} else {
- if (VIR_APPEND_ELEMENT_COPY(data->items, data->len,
- *((virCPUx86DataItem *)item)) < 0)
- return -1;
+ VIR_APPEND_ELEMENT_COPY(data->items, data->len,
+ *((virCPUx86DataItem *)item));
qsort(data->items, data->len,
sizeof(virCPUx86DataItem), virCPUx86DataSorter);
@@ -1143,11 +1142,8 @@ x86FeatureParse(xmlXPathContextPtr ctxt,
return -1;
}
- if (!feature->migratable &&
- VIR_APPEND_ELEMENT_COPY(map->migrate_blockers,
- map->nblockers,
- feature) < 0)
- return -1;
+ if (!feature->migratable)
+ VIR_APPEND_ELEMENT_COPY(map->migrate_blockers, map->nblockers, feature);
if (VIR_APPEND_ELEMENT(map->features, map->nfeatures, feature) < 0)
return -1;
diff --git a/src/logging/log_handler.c b/src/logging/log_handler.c
index dde3506fe9..5c3df37415 100644
--- a/src/logging/log_handler.c
+++ b/src/logging/log_handler.c
@@ -318,8 +318,7 @@ virLogHandlerNewPostExecRestart(virJSONValue *object,
if (!(file = virLogHandlerLogFilePostExecRestart(handler, child)))
goto error;
- if (VIR_APPEND_ELEMENT_COPY(handler->files, handler->nfiles, file) < 0)
- goto error;
+ VIR_APPEND_ELEMENT_COPY(handler->files, handler->nfiles, file);
if ((file->watch = virEventAddHandle(file->pipefd,
VIR_EVENT_HANDLE_READABLE,
@@ -401,8 +400,7 @@ virLogHandlerDomainOpenLogFile(virLogHandler *handler,
DEFAULT_MODE)) == NULL)
goto error;
- if (VIR_APPEND_ELEMENT_COPY(handler->files, handler->nfiles, file) < 0)
- goto error;
+ VIR_APPEND_ELEMENT_COPY(handler->files, handler->nfiles, file);
if ((file->watch = virEventAddHandle(file->pipefd,
VIR_EVENT_HANDLE_READABLE,
diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c
index 2a794801ae..07c2cddd92 100644
--- a/src/openvz/openvz_conf.c
+++ b/src/openvz/openvz_conf.c
@@ -206,8 +206,7 @@ openvzReadNetworkConf(virDomainDef *def,
if (virDomainNetAppendIPAddress(net, token, AF_UNSPEC, 0) < 0)
goto error;
- if (VIR_APPEND_ELEMENT_COPY(def->nets, def->nnets, net) < 0)
- goto error;
+ VIR_APPEND_ELEMENT_COPY(def->nets, def->nnets, net);
token = strtok_r(NULL, " ", &saveptr);
}
@@ -275,7 +274,7 @@ openvzReadNetworkConf(virDomainDef *def,
}
}
- ignore_value(VIR_APPEND_ELEMENT_COPY(def->nets, def->nnets, net));
+ VIR_APPEND_ELEMENT_COPY(def->nets, def->nnets, net);
}
}
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 7e2efc8168..004bfb5d83 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -4001,11 +4001,7 @@ qemuDomainDefAddDefaultDevices(virQEMUDriver *driver,
if (j == def->npanics) {
virDomainPanicDef *panic = g_new0(virDomainPanicDef, 1);
- if (VIR_APPEND_ELEMENT_COPY(def->panics,
- def->npanics, panic) < 0) {
- VIR_FREE(panic);
- return -1;
- }
+ VIR_APPEND_ELEMENT_COPY(def->panics, def->npanics, panic);
}
}
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 6743a8a742..c00e8a7852 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -1236,8 +1236,7 @@ qemuDomainAttachNetDevice(virQEMUDriver *driver,
virDomainNetGetActualHostdev(net)) < 0) {
goto cleanup;
}
- if (VIR_APPEND_ELEMENT_COPY(vm->def->nets, vm->def->nnets, net) <
0)
- goto cleanup;
+ VIR_APPEND_ELEMENT_COPY(vm->def->nets, vm->def->nnets, net);
/* the rest of the setup doesn't apply to hostdev interfaces, so
* we can skip straight to the cleanup (nothing there applies to
@@ -1272,8 +1271,7 @@ qemuDomainAttachNetDevice(virQEMUDriver *driver,
* locked memory limit). This means we will need to remove it if
* there is a failure.
*/
- if (VIR_APPEND_ELEMENT_COPY(vm->def->nets, vm->def->nnets, net) < 0)
- goto cleanup;
+ VIR_APPEND_ELEMENT_COPY(vm->def->nets, vm->def->nnets, net);
switch (actualType) {
case VIR_DOMAIN_NET_TYPE_BRIDGE:
diff --git a/src/util/viralloc.h b/src/util/viralloc.h
index 7397ee3771..70cd721bc7 100644
--- a/src/util/viralloc.h
+++ b/src/util/viralloc.h
@@ -234,8 +234,8 @@ int virDeleteElementsN(void *ptrptr, size_t size, size_t at, size_t
*countptr,
virInsertElementsN(&(ptr), sizeof(*(ptr)), -1, &(count), \
VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), true, false)
#define VIR_APPEND_ELEMENT_COPY(ptr, count, newelem) \
- virInsertElementsN(&(ptr), sizeof(*(ptr)), -1, &(count), \
- VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), false, false)
+ virAppendElement(&(ptr), sizeof(*(ptr)), &(count), \
+ VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), false, false)
#define VIR_APPEND_ELEMENT_INPLACE(ptr, count, newelem) \
virAppendElement(&(ptr), sizeof(*(ptr)), &(count), \
VIR_TYPEMATCH(ptr, &(newelem)), \
diff --git a/src/util/virfirewall.c b/src/util/virfirewall.c
index e79fe52ac8..9594192a7b 100644
--- a/src/util/virfirewall.c
+++ b/src/util/virfirewall.c
@@ -313,13 +313,9 @@ virFirewallAddRuleFullV(virFirewall *firewall,
ADD_ARG(rule, str);
if (group->addingRollback) {
- ignore_value(VIR_APPEND_ELEMENT_COPY(group->rollback,
- group->nrollback,
- rule));
+ VIR_APPEND_ELEMENT_COPY(group->rollback, group->nrollback, rule);
} else {
- ignore_value(VIR_APPEND_ELEMENT_COPY(group->action,
- group->naction,
- rule));
+ VIR_APPEND_ELEMENT_COPY(group->action, group->naction, rule);
}
diff --git a/tests/nwfilterxml2firewalltest.c b/tests/nwfilterxml2firewalltest.c
index 33ba8b9932..8c82efa060 100644
--- a/tests/nwfilterxml2firewalltest.c
+++ b/tests/nwfilterxml2firewalltest.c
@@ -269,12 +269,7 @@ virNWFilterDefToInst(const char *xml,
if (!def)
return -1;
- if (VIR_APPEND_ELEMENT_COPY(inst->filters,
- inst->nfilters,
- def) < 0) {
- virNWFilterDefFree(def);
- goto cleanup;
- }
+ VIR_APPEND_ELEMENT_COPY(inst->filters, inst->nfilters, def);
for (i = 0; i < def->nentries; i++) {
if (def->filterEntries[i]->rule) {
--
2.31.1