[libvirt] [PATCH v1 00/37] Remove virReportOOMError from almost everywhere

Make VIR_ALLOC, virAsprintf and friend to report OOM error and subsequently adapt the code. Patches available at: git://gitorious.org/~zippy2/libvirt/michal-staging.git branch oom1 Michal Privoznik (37): viralloc: Report OOM error on failure Introduce OOM reporting to virAsprintf Adapt to VIR_ALLOC and virAsprintf in docs/ Adapt to VIR_ALLOC and virAsprintf in daemon/* Adapt to VIR_ALLOC and virAsprintf in src/access/* Adapt to VIR_ALLOC and virAsprintf in src/conf/* Adapt to VIR_ALLOC and virAsprintf in src/cpu/* Adapt to VIR_ALLOC and virAsprintf in src/esx/* Adapt to VIR_ALLOC and virAsprintf in src/hyperv/* Adapt to VIR_ALLOC and virAsprintf in src/interface/* Adapt to VIR_ALLOC and virAsprintf in src/libxl/* Adapt to VIR_ALLOC and virAsprintf in src/locking/* Adapt to VIR_ALLOC and virAsprintf in src/lxc/* Adapt to VIR_ALLOC and virAsprintf in src/node_device/* Adapt to VIR_ALLOC and virAsprintf in src/network/* Adapt to VIR_ALLOC and virAsprintf in src/nwfilter/* Adapt to VIR_ALLOC and virAsprintf in src/openvz/* Adapt to VIR_ALLOC and virAsprintf in src/parallels/* Adapt to VIR_ALLOC and virAsprintf in src/phyp/* Adapt to VIR_ALLOC and virAsprintf in src/qemu/* Adapt to VIR_ALLOC and virAsprintf in src/remote/* Adapt to VIR_ALLOC and virAsprintf in src/rpc/* Adapt to VIR_ALLOC and virAsprintf in src/secret/* Adapt to VIR_ALLOC and virAsprintf in src/security/* Adapt to VIR_ALLOC and virAsprintf in src/storage/* Adapt to VIR_ALLOC and virAsprintf in src/test/* Adapt to VIR_ALLOC and virAsprintf in src/uml/* Adapt to VIR_ALLOC and virAsprintf in src/util/* Adapt to VIR_ALLOC and virAsprintf in src/vbox/* Adapt to VIR_ALLOC and virAsprintf in src/vmware/* Adapt to VIR_ALLOC and virAsprintf in src/vmx/* Adapt to VIR_ALLOC and virAsprintf in src/xen/* Adapt to VIR_ALLOC and virAsprintf in src/xenapi/* Adapt to VIR_ALLOC and virAsprintf in src/xenxs/* Adapt to VIR_ALLOC and virAsprintf in src/* Adapt to VIR_ALLOC and virAsprintf in tests/* Adapt to VIR_ALLOC and virAsprintf in tools/* HACKING | 20 +- cfg.mk | 2 +- daemon/libvirtd-config.c | 12 +- daemon/libvirtd.c | 24 +- daemon/remote.c | 234 +++++--------------- daemon/stream.c | 4 +- docs/hacking.html.in | 20 +- po/POTFILES.in | 1 + python/libvirt-override.c | 102 ++++----- src/access/viraccessdriverpolkit.c | 4 +- src/access/viraccessdriverstack.c | 4 +- src/access/viraccessmanager.c | 4 +- src/conf/cpu_conf.c | 34 +-- src/conf/domain_audit.c | 36 +-- src/conf/domain_conf.c | 337 +++++++++------------------- src/conf/domain_event.c | 30 +-- src/conf/interface_conf.c | 35 +-- src/conf/netdev_bandwidth_conf.c | 12 +- src/conf/netdev_vlan_conf.c | 4 +- src/conf/netdev_vport_profile_conf.c | 4 +- src/conf/network_conf.c | 120 +++------- src/conf/node_device_conf.c | 29 +-- src/conf/nwfilter_conf.c | 33 +-- src/conf/nwfilter_ipaddrmap.c | 8 +- src/conf/nwfilter_params.c | 35 +-- src/conf/secret_conf.c | 4 +- src/conf/snapshot_conf.c | 47 ++-- src/conf/storage_conf.c | 38 +--- src/conf/storage_encryption_conf.c | 12 +- src/conf/virchrdev.c | 12 +- src/cpu/cpu.c | 4 +- src/cpu/cpu_arm.c | 6 +- src/cpu/cpu_generic.c | 12 +- src/cpu/cpu_powerpc.c | 20 +- src/cpu/cpu_s390.c | 4 +- src/cpu/cpu_x86.c | 86 +++----- src/driver.c | 4 +- src/esx/esx_driver.c | 62 ++---- src/esx/esx_network_driver.c | 16 +- src/esx/esx_storage_backend_iscsi.c | 4 +- src/esx/esx_storage_backend_vmfs.c | 78 ++----- src/esx/esx_util.c | 4 +- src/esx/esx_vi.c | 50 ++--- src/esx/esx_vi.h | 3 +- src/esx/esx_vi_types.c | 3 +- src/fdstream.c | 4 +- src/hyperv/hyperv_driver.c | 21 +- src/hyperv/hyperv_util.c | 4 +- src/hyperv/hyperv_wmi.c | 8 +- src/interface/interface_backend_netcf.c | 19 +- src/interface/interface_backend_udev.c | 33 +-- src/libvirt.c | 21 +- src/libvirt_private.syms | 4 +- src/libxl/libxl_conf.c | 18 +- src/libxl/libxl_driver.c | 46 +--- src/locking/lock_daemon.c | 33 +-- src/locking/lock_daemon_config.c | 8 +- src/locking/lock_driver_lockd.c | 23 +- src/locking/lock_driver_sanlock.c | 28 +-- src/locking/lock_manager.c | 16 +- src/lxc/lxc_cgroup.c | 4 +- src/lxc/lxc_conf.c | 5 +- src/lxc/lxc_container.c | 77 ++----- src/lxc/lxc_controller.c | 50 +---- src/lxc/lxc_driver.c | 92 ++------ src/lxc/lxc_fuse.c | 12 +- src/lxc/lxc_monitor.c | 4 +- src/lxc/lxc_process.c | 32 +-- src/network/bridge_driver.c | 138 ++++-------- src/node_device/node_device_driver.c | 4 +- src/node_device/node_device_udev.c | 18 +- src/nodeinfo.c | 58 ++--- src/nwfilter/nwfilter_dhcpsnoop.c | 29 +-- src/nwfilter/nwfilter_driver.c | 13 +- src/nwfilter/nwfilter_ebiptables_driver.c | 46 ++-- src/nwfilter/nwfilter_gentech_driver.c | 24 +- src/nwfilter/nwfilter_learnipaddr.c | 12 +- src/openvz/openvz_conf.c | 42 ++-- src/openvz/openvz_driver.c | 10 +- src/parallels/parallels_driver.c | 65 ++---- src/parallels/parallels_network.c | 24 +- src/parallels/parallels_storage.c | 50 ++--- src/parallels/parallels_utils.c | 4 +- src/phyp/phyp_driver.c | 95 ++------ src/qemu/qemu_agent.c | 42 ++-- src/qemu/qemu_capabilities.c | 69 ++---- src/qemu/qemu_cgroup.c | 4 +- src/qemu/qemu_command.c | 355 ++++++++++-------------------- src/qemu/qemu_conf.c | 88 +++----- src/qemu/qemu_domain.c | 50 ++--- src/qemu/qemu_driver.c | 124 +++-------- src/qemu/qemu_hotplug.c | 84 ++----- src/qemu/qemu_migration.c | 94 +++----- src/qemu/qemu_monitor.c | 33 +-- src/qemu/qemu_monitor_json.c | 118 +++------- src/qemu/qemu_monitor_text.c | 233 +++++--------------- src/qemu/qemu_process.c | 70 ++---- src/remote/remote_driver.c | 107 +++------ src/rpc/gendispatch.pl | 8 +- src/rpc/virnetclient.c | 26 +-- src/rpc/virnetclientprogram.c | 12 +- src/rpc/virnetclientstream.c | 4 +- src/rpc/virnetmessage.c | 24 +- src/rpc/virnetserver.c | 23 +- src/rpc/virnetserverclient.c | 19 +- src/rpc/virnetservermdns.c | 20 +- src/rpc/virnetserverprogram.c | 8 +- src/rpc/virnetserverservice.c | 12 +- src/rpc/virnetsocket.c | 8 +- src/rpc/virnetsshsession.c | 21 +- src/rpc/virnettlscontext.c | 26 +-- src/secret/secret_driver.c | 49 +---- src/security/security_apparmor.c | 25 +-- src/security/security_dac.c | 12 +- src/security/security_manager.c | 12 +- src/security/security_selinux.c | 45 ++-- src/security/security_stack.c | 8 +- src/storage/storage_backend.c | 35 +-- src/storage/storage_backend_disk.c | 17 +- src/storage/storage_backend_fs.c | 31 +-- src/storage/storage_backend_iscsi.c | 27 +-- src/storage/storage_backend_logical.c | 48 +--- src/storage/storage_backend_mpath.c | 20 +- src/storage/storage_backend_rbd.c | 18 +- src/storage/storage_backend_scsi.c | 21 +- src/storage/storage_backend_sheepdog.c | 4 +- src/storage/storage_driver.c | 23 +- src/test/test_driver.c | 91 +++----- src/uml/uml_conf.c | 28 +-- src/uml/uml_driver.c | 36 +-- src/util/iohelper.c | 4 +- src/util/viralloc.c | 165 ++++++++++++-- src/util/viralloc.h | 213 ++++++++++++++---- src/util/virauth.c | 6 +- src/util/virauthconfig.c | 16 +- src/util/virbuffer.c | 8 +- src/util/vircgroup.c | 13 +- src/util/vircommand.c | 13 +- src/util/virconf.c | 10 +- src/util/virdnsmasq.c | 53 ++--- src/util/virerror.c | 6 +- src/util/vireventpoll.c | 4 +- src/util/virfile.c | 34 +-- src/util/virhash.c | 11 +- src/util/viridentity.c | 4 +- src/util/virinitctl.c | 4 +- src/util/viriptables.c | 11 +- src/util/virkeyfile.c | 4 +- src/util/virlockspace.c | 37 +--- src/util/virlog.c | 2 +- src/util/virnetdev.c | 45 +--- src/util/virnetdevbandwidth.c | 21 +- src/util/virnetdevbridge.c | 8 +- src/util/virnetdevmacvlan.c | 6 +- src/util/virnetdevopenvswitch.c | 18 +- src/util/virnetdevtap.c | 8 +- src/util/virnetdevveth.c | 8 +- src/util/virnetdevvlan.c | 4 +- src/util/virnetdevvportprofile.c | 4 +- src/util/virnetlink.c | 8 +- src/util/virobject.c | 8 +- src/util/virpci.c | 96 ++------ src/util/virportallocator.c | 1 - src/util/virprocess.c | 17 +- src/util/virrandom.c | 9 +- src/util/virscsi.c | 28 +-- src/util/virsexpr.c | 4 +- src/util/virsocketaddr.c | 6 +- src/util/virstoragefile.c | 32 +-- src/util/virstring.c | 44 ++-- src/util/virstring.h | 67 +++++- src/util/virsysinfo.c | 22 +- src/util/virthreadpool.c | 21 +- src/util/virthreadpthread.c | 2 +- src/util/virtime.c | 8 +- src/util/virtpm.c | 4 +- src/util/virtypedparam.c | 68 ++---- src/util/viruri.c | 12 +- src/util/virusb.c | 13 +- src/util/virutil.c | 107 +++------ src/util/virxml.c | 1 - src/vbox/vbox_MSCOMGlue.c | 8 +- src/vbox/vbox_XPCOMCGlue.c | 4 +- src/vbox/vbox_tmpl.c | 126 +++-------- src/vmware/vmware_conf.c | 33 +-- src/vmware/vmware_driver.c | 4 +- src/vmx/vmx.c | 92 ++------ src/xen/block_stats.c | 8 +- src/xen/xen_driver.c | 42 +--- src/xen/xen_hypervisor.c | 17 +- src/xen/xen_inotify.c | 4 +- src/xen/xend_internal.c | 38 +--- src/xen/xm_internal.c | 24 +- src/xen/xs_internal.c | 24 +- src/xenapi/xenapi_driver.c | 29 +-- src/xenapi/xenapi_utils.c | 11 +- src/xenxs/xen_sxpr.c | 112 ++++------ src/xenxs/xen_xm.c | 204 ++++++++--------- tests/commandhelper.c | 1 + tests/commandtest.c | 8 +- tests/domainsnapshotxml2xmltest.c | 2 + tests/fchosttest.c | 2 + tests/interfacexml2xmltest.c | 2 + tests/libvirtdconftest.c | 4 +- tests/lxcxml2xmltest.c | 2 + tests/networkxml2conftest.c | 2 + tests/networkxml2xmltest.c | 2 + tests/nodedevxml2xmltest.c | 2 + tests/nodeinfotest.c | 2 + tests/nwfilterxml2xmltest.c | 2 + tests/qemuargv2xmltest.c | 2 + tests/qemuhelptest.c | 2 + tests/qemumonitortestutils.c | 17 +- tests/qemuxml2xmltest.c | 2 + tests/securityselinuxlabeltest.c | 21 +- tests/securityselinuxtest.c | 8 +- tests/sexpr2xmltest.c | 2 + tests/storagepoolxml2xmltest.c | 2 + tests/storagevolxml2argvtest.c | 2 + tests/storagevolxml2xmltest.c | 2 + tests/sysinfotest.c | 2 + tests/test_conf.c | 2 +- tests/virbuftest.c | 2 + tests/virhashtest.c | 2 + tests/virnetmessagetest.c | 20 +- tests/virshtest.c | 2 + tests/virstoragetest.c | 5 +- tests/xencapstest.c | 2 + tests/xmconfigtest.c | 2 + tests/xml2sexprtest.c | 2 + tools/console.c | 6 +- tools/virsh-domain-monitor.c | 4 +- tools/virsh-domain.c | 28 +-- tools/virsh.c | 1 - tools/virt-host-validate-common.c | 2 + 235 files changed, 2373 insertions(+), 4941 deletions(-) -- 1.8.1.5

Similarly to VIR_STRDUP, we want the OOM error to be reported in VIR_ALLOC and friends. --- po/POTFILES.in | 1 + python/libvirt-override.c | 102 +++++++++---------- src/conf/domain_conf.c | 9 +- src/conf/network_conf.c | 34 ++----- src/conf/node_device_conf.c | 2 +- src/esx/esx_vi.c | 2 +- src/lxc/lxc_process.c | 4 +- src/security/security_manager.c | 4 +- src/security/security_selinux.c | 4 +- src/util/viralloc.c | 165 ++++++++++++++++++++++++++----- src/util/viralloc.h | 213 ++++++++++++++++++++++++++++++++-------- src/util/virbuffer.c | 8 +- src/util/vircgroup.c | 2 +- src/util/virerror.c | 4 +- src/util/virpci.c | 2 +- src/util/virthreadpthread.c | 2 +- tests/commandhelper.c | 1 + tests/networkxml2conftest.c | 2 + tests/test_conf.c | 2 +- tests/xmconfigtest.c | 2 + 20 files changed, 401 insertions(+), 164 deletions(-) diff --git a/po/POTFILES.in b/po/POTFILES.in index af7fd7f..0b65765 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -141,6 +141,7 @@ src/test/test_driver.c src/uml/uml_conf.c src/uml/uml_driver.c src/util/iohelper.c +src/util/viralloc.c src/util/viraudit.c src/util/virauth.c src/util/virauthconfig.c diff --git a/python/libvirt-override.c b/python/libvirt-override.c index 5c5586d..6b6e77b 100644 --- a/python/libvirt-override.c +++ b/python/libvirt-override.c @@ -171,7 +171,7 @@ setPyVirTypedParameter(PyObject *info, return NULL; } - if (VIR_ALLOC_N(ret, size) < 0) { + if (VIR_ALLOC_N_QUIET(ret, size) < 0) { PyErr_NoMemory(); return NULL; } @@ -511,7 +511,7 @@ libvirt_virDomainBlockStatsFlags(PyObject *self ATTRIBUTE_UNUSED, if (!nparams) return PyDict_New(); - if (VIR_ALLOC_N(params, nparams) < 0) + if (VIR_ALLOC_N_QUIET(params, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -577,7 +577,7 @@ libvirt_virDomainGetCPUStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) sumparams = nparams * MIN(ncpus, 128); - if (VIR_ALLOC_N(params, sumparams) < 0) { + if (VIR_ALLOC_N_QUIET(params, sumparams) < 0) { error = PyErr_NoMemory(); goto error; } @@ -629,7 +629,7 @@ libvirt_virDomainGetCPUStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) if (nparams) { sumparams = nparams; - if (VIR_ALLOC_N(params, nparams) < 0) { + if (VIR_ALLOC_N_QUIET(params, nparams) < 0) { error = PyErr_NoMemory(); goto error; } @@ -809,7 +809,7 @@ libvirt_virDomainGetSchedulerParameters(PyObject *self ATTRIBUTE_UNUSED, if (!nparams) return PyDict_New(); - if (VIR_ALLOC_N(params, nparams) < 0) + if (VIR_ALLOC_N_QUIET(params, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -857,7 +857,7 @@ libvirt_virDomainGetSchedulerParametersFlags(PyObject *self ATTRIBUTE_UNUSED, if (!nparams) return PyDict_New(); - if (VIR_ALLOC_N(params, nparams) < 0) + if (VIR_ALLOC_N_QUIET(params, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -917,7 +917,7 @@ libvirt_virDomainSetSchedulerParameters(PyObject *self ATTRIBUTE_UNUSED, return NULL; } - if (VIR_ALLOC_N(params, nparams) < 0) + if (VIR_ALLOC_N_QUIET(params, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -993,7 +993,7 @@ libvirt_virDomainSetSchedulerParametersFlags(PyObject *self ATTRIBUTE_UNUSED, return NULL; } - if (VIR_ALLOC_N(params, nparams) < 0) + if (VIR_ALLOC_N_QUIET(params, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -1067,7 +1067,7 @@ libvirt_virDomainSetBlkioParameters(PyObject *self ATTRIBUTE_UNUSED, return NULL; } - if (VIR_ALLOC_N(params, nparams) < 0) + if (VIR_ALLOC_N_QUIET(params, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -1127,7 +1127,7 @@ libvirt_virDomainGetBlkioParameters(PyObject *self ATTRIBUTE_UNUSED, if (!nparams) return PyDict_New(); - if (VIR_ALLOC_N(params, nparams) < 0) + if (VIR_ALLOC_N_QUIET(params, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -1187,7 +1187,7 @@ libvirt_virDomainSetMemoryParameters(PyObject *self ATTRIBUTE_UNUSED, return NULL; } - if (VIR_ALLOC_N(params, nparams) < 0) + if (VIR_ALLOC_N_QUIET(params, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -1247,7 +1247,7 @@ libvirt_virDomainGetMemoryParameters(PyObject *self ATTRIBUTE_UNUSED, if (!nparams) return PyDict_New(); - if (VIR_ALLOC_N(params, nparams) < 0) + if (VIR_ALLOC_N_QUIET(params, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -1307,7 +1307,7 @@ libvirt_virDomainSetNumaParameters(PyObject *self ATTRIBUTE_UNUSED, return NULL; } - if (VIR_ALLOC_N(params, nparams) < 0) + if (VIR_ALLOC_N_QUIET(params, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -1367,7 +1367,7 @@ libvirt_virDomainGetNumaParameters(PyObject *self ATTRIBUTE_UNUSED, if (!nparams) return PyDict_New(); - if (VIR_ALLOC_N(params, nparams) < 0) + if (VIR_ALLOC_N_QUIET(params, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -1428,7 +1428,7 @@ libvirt_virDomainSetInterfaceParameters(PyObject *self ATTRIBUTE_UNUSED, return NULL; } - if (VIR_ALLOC_N(params, nparams) < 0) + if (VIR_ALLOC_N_QUIET(params, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -1489,7 +1489,7 @@ libvirt_virDomainGetInterfaceParameters(PyObject *self ATTRIBUTE_UNUSED, if (!nparams) return PyDict_New(); - if (VIR_ALLOC_N(params, nparams) < 0) + if (VIR_ALLOC_N_QUIET(params, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -1535,12 +1535,12 @@ libvirt_virDomainGetVcpus(PyObject *self ATTRIBUTE_UNUSED, if (i_retval < 0) return VIR_PY_INT_FAIL; - if (VIR_ALLOC_N(cpuinfo, dominfo.nrVirtCpu) < 0) + if (VIR_ALLOC_N_QUIET(cpuinfo, dominfo.nrVirtCpu) < 0) return PyErr_NoMemory(); cpumaplen = VIR_CPU_MAPLEN(cpunum); if (xalloc_oversized(dominfo.nrVirtCpu, cpumaplen) || - VIR_ALLOC_N(cpumap, dominfo.nrVirtCpu * cpumaplen) < 0) { + VIR_ALLOC_N_QUIET(cpumap, dominfo.nrVirtCpu * cpumaplen) < 0) { error = PyErr_NoMemory(); goto cleanup; } @@ -1662,7 +1662,7 @@ libvirt_virDomainPinVcpu(PyObject *self ATTRIBUTE_UNUSED, } cpumaplen = VIR_CPU_MAPLEN(cpunum); - if (VIR_ALLOC_N(cpumap, cpumaplen) < 0) + if (VIR_ALLOC_N_QUIET(cpumap, cpumaplen) < 0) return PyErr_NoMemory(); for (i = 0; i < tuple_size; i++) { @@ -1726,7 +1726,7 @@ libvirt_virDomainPinVcpuFlags(PyObject *self ATTRIBUTE_UNUSED, } cpumaplen = VIR_CPU_MAPLEN(cpunum); - if (VIR_ALLOC_N(cpumap, cpumaplen) < 0) + if (VIR_ALLOC_N_QUIET(cpumap, cpumaplen) < 0) return PyErr_NoMemory(); for (i = 0; i < tuple_size; i++) { @@ -1786,7 +1786,7 @@ libvirt_virDomainGetVcpuPinInfo(PyObject *self ATTRIBUTE_UNUSED, cpumaplen = VIR_CPU_MAPLEN(cpunum); if (xalloc_oversized(dominfo.nrVirtCpu, cpumaplen) || - VIR_ALLOC_N(cpumaps, dominfo.nrVirtCpu * cpumaplen) < 0) + VIR_ALLOC_N_QUIET(cpumaps, dominfo.nrVirtCpu * cpumaplen) < 0) goto cleanup; LIBVIRT_BEGIN_ALLOW_THREADS; @@ -1854,7 +1854,7 @@ libvirt_virDomainPinEmulator(PyObject *self ATTRIBUTE_UNUSED, if ((tuple_size = PyTuple_Size(pycpumap)) == -1) return NULL; - if (VIR_ALLOC_N(cpumap, cpumaplen) < 0) + if (VIR_ALLOC_N_QUIET(cpumap, cpumaplen) < 0) return PyErr_NoMemory(); for (i = 0; i < tuple_size; i++) { @@ -1913,7 +1913,7 @@ libvirt_virDomainGetEmulatorPinInfo(PyObject *self ATTRIBUTE_UNUSED, cpumaplen = VIR_CPU_MAPLEN(cpunum); - if (VIR_ALLOC_N(cpumap, cpumaplen) < 0) + if (VIR_ALLOC_N_QUIET(cpumap, cpumaplen) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -2188,7 +2188,7 @@ libvirt_virConnectOpenAuth(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { auth.ncredtype = PyList_Size(pycredtype); if (auth.ncredtype) { int i; - if (VIR_ALLOC_N(auth.credtype, auth.ncredtype) < 0) + if (VIR_ALLOC_N_QUIET(auth.credtype, auth.ncredtype) < 0) return VIR_PY_NONE; for (i = 0; i < auth.ncredtype; i++) { PyObject *val; @@ -2316,7 +2316,7 @@ libvirt_virConnectListDomainsID(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - if (VIR_ALLOC_N(ids, c_retval) < 0) + if (VIR_ALLOC_N_QUIET(ids, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; @@ -2407,7 +2407,7 @@ libvirt_virConnectListDefinedDomains(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - if (VIR_ALLOC_N(names, c_retval) < 0) + if (VIR_ALLOC_N_QUIET(names, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virConnectListDefinedDomains(conn, names, c_retval); @@ -2454,7 +2454,7 @@ libvirt_virDomainSnapshotListNames(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - if (VIR_ALLOC_N(names, c_retval) < 0) + if (VIR_ALLOC_N_QUIET(names, c_retval) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virDomainSnapshotListNames(dom, names, c_retval, flags); @@ -2554,7 +2554,7 @@ libvirt_virDomainSnapshotListChildrenNames(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - if (VIR_ALLOC_N(names, c_retval) < 0) + if (VIR_ALLOC_N_QUIET(names, c_retval) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virDomainSnapshotListChildrenNames(snap, names, c_retval, @@ -2886,7 +2886,7 @@ libvirt_virConnectListNetworks(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - if (VIR_ALLOC_N(names, c_retval) < 0) + if (VIR_ALLOC_N_QUIET(names, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virConnectListNetworks(conn, names, c_retval); @@ -2931,7 +2931,7 @@ libvirt_virConnectListDefinedNetworks(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - if (VIR_ALLOC_N(names, c_retval) < 0) + if (VIR_ALLOC_N_QUIET(names, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virConnectListDefinedNetworks(conn, names, c_retval); @@ -3139,7 +3139,7 @@ libvirt_virNodeGetCellsFreeMemory(PyObject *self ATTRIBUTE_UNUSED, PyObject *arg return VIR_PY_NONE; conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn); - if (VIR_ALLOC_N(freeMems, maxCells) < 0) + if (VIR_ALLOC_N_QUIET(freeMems, maxCells) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; @@ -3183,7 +3183,7 @@ libvirt_virNodeGetCPUStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) return VIR_PY_NONE; if (nparams) { - if (VIR_ALLOC_N(stats, nparams) < 0) + if (VIR_ALLOC_N_QUIET(stats, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -3246,7 +3246,7 @@ libvirt_virNodeGetMemoryStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) return VIR_PY_NONE; if (nparams) { - if (VIR_ALLOC_N(stats, nparams) < 0) + if (VIR_ALLOC_N_QUIET(stats, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -3306,7 +3306,7 @@ libvirt_virConnectListStoragePools(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - if (VIR_ALLOC_N(names, c_retval) < 0) + if (VIR_ALLOC_N_QUIET(names, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virConnectListStoragePools(conn, names, c_retval); @@ -3359,7 +3359,7 @@ libvirt_virConnectListDefinedStoragePools(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - if (VIR_ALLOC_N(names, c_retval) < 0) + if (VIR_ALLOC_N_QUIET(names, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virConnectListDefinedStoragePools(conn, names, c_retval); @@ -3458,7 +3458,7 @@ libvirt_virStoragePoolListVolumes(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - if (VIR_ALLOC_N(names, c_retval) < 0) + if (VIR_ALLOC_N_QUIET(names, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virStoragePoolListVolumes(pool, names, c_retval); @@ -3719,7 +3719,7 @@ libvirt_virNodeListDevices(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - if (VIR_ALLOC_N(names, c_retval) < 0) + if (VIR_ALLOC_N_QUIET(names, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virNodeListDevices(conn, cap, names, c_retval, flags); @@ -3809,7 +3809,7 @@ libvirt_virNodeDeviceListCaps(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - if (VIR_ALLOC_N(names, c_retval) < 0) + if (VIR_ALLOC_N_QUIET(names, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virNodeDeviceListCaps(dev, names, c_retval); @@ -3928,7 +3928,7 @@ libvirt_virConnectListSecrets(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - if (VIR_ALLOC_N(uuids, c_retval) < 0) + if (VIR_ALLOC_N_QUIET(uuids, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virConnectListSecrets(conn, uuids, c_retval); @@ -4147,7 +4147,7 @@ libvirt_virConnectListNWFilters(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - if (VIR_ALLOC_N(uuids, c_retval) < 0) + if (VIR_ALLOC_N_QUIET(uuids, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virConnectListNWFilters(conn, uuids, c_retval); @@ -4238,7 +4238,7 @@ libvirt_virConnectListInterfaces(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - if (VIR_ALLOC_N(names, c_retval) < 0) + if (VIR_ALLOC_N_QUIET(names, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virConnectListInterfaces(conn, names, c_retval); @@ -4292,7 +4292,7 @@ libvirt_virConnectListDefinedInterfaces(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - if (VIR_ALLOC_N(names, c_retval) < 0) + if (VIR_ALLOC_N_QUIET(names, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virConnectListDefinedInterfaces(conn, names, c_retval); @@ -4392,7 +4392,7 @@ libvirt_virConnectBaselineCPU(PyObject *self ATTRIBUTE_UNUSED, int i; ncpus = PyList_Size(list); - if (VIR_ALLOC_N(xmlcpus, ncpus) < 0) + if (VIR_ALLOC_N_QUIET(xmlcpus, ncpus) < 0) return VIR_PY_INT_FAIL; for (i = 0; i < ncpus; i++) { @@ -4578,7 +4578,7 @@ libvirt_virDomainSetBlockIoTune(PyObject *self ATTRIBUTE_UNUSED, return NULL; } - if (VIR_ALLOC_N(params, nparams) < 0) + if (VIR_ALLOC_N_QUIET(params, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -4639,7 +4639,7 @@ libvirt_virDomainGetBlockIoTune(PyObject *self ATTRIBUTE_UNUSED, if (!nparams) return PyDict_New(); - if (VIR_ALLOC_N(params, nparams) < 0) + if (VIR_ALLOC_N_QUIET(params, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -4682,7 +4682,7 @@ libvirt_virDomainGetDiskErrors(PyObject *self ATTRIBUTE_UNUSED, ndisks = count; if (ndisks) { - if (VIR_ALLOC_N(disks, ndisks) < 0) + if (VIR_ALLOC_N_QUIET(disks, ndisks) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; @@ -6503,7 +6503,7 @@ libvirt_virStreamRecv(PyObject *self ATTRIBUTE_UNUSED, } stream = PyvirStream_Get(pyobj_stream); - if (VIR_ALLOC_N(buf, nbytes+1 > 0 ? nbytes+1 : 1) < 0) + if (VIR_ALLOC_N_QUIET(buf, nbytes+1 > 0 ? nbytes+1 : 1) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; @@ -6729,7 +6729,7 @@ libvirt_virDomainBlockPeek(PyObject *self ATTRIBUTE_UNUSED, domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain); - if (VIR_ALLOC_N(buf, size) < 0) + if (VIR_ALLOC_N_QUIET(buf, size) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; @@ -6766,7 +6766,7 @@ libvirt_virDomainMemoryPeek(PyObject *self ATTRIBUTE_UNUSED, domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain); - if (VIR_ALLOC_N(buf, size) < 0) + if (VIR_ALLOC_N_QUIET(buf, size) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; @@ -6826,7 +6826,7 @@ libvirt_virNodeSetMemoryParameters(PyObject *self ATTRIBUTE_UNUSED, return NULL; } - if (VIR_ALLOC_N(params, nparams) < 0) + if (VIR_ALLOC_N_QUIET(params, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -6886,7 +6886,7 @@ libvirt_virNodeGetMemoryParameters(PyObject *self ATTRIBUTE_UNUSED, if (!nparams) return PyDict_New(); - if (VIR_ALLOC_N(params, nparams) < 0) + if (VIR_ALLOC_N_QUIET(params, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index f80b690..921a4f6 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2750,8 +2750,8 @@ virDomainDefPostParseInternal(virDomainDefPtr def, /* create the serial port definition from the console definition */ if (def->nserials == 0) { if (VIR_APPEND_ELEMENT(def->serials, def->nserials, - def->consoles[0]) < 0) - goto no_memory; + def->consoles[0], true) < 0) + return -1; /* modify it to be a serial port */ def->serials[0]->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL; @@ -10435,9 +10435,8 @@ virDomainDefMaybeAddController(virDomainDefPtr def, cont->opts.vioserial.vectors = -1; } - if (VIR_APPEND_ELEMENT(def->controllers, def->ncontrollers, cont) < 0) { + if (VIR_APPEND_ELEMENT(def->controllers, def->ncontrollers, cont, true) < 0) { VIR_FREE(cont); - virReportOOMError(); return -1; } @@ -11907,7 +11906,7 @@ virDomainDefParseXML(xmlDocPtr xml, if (VIR_INSERT_ELEMENT_INPLACE(def->videos, ii, def->nvideos, - video) < 0) { + video, false) < 0) { virDomainVideoDefFree(video); goto error; } diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 64fd581..d6799d2 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -3414,10 +3414,8 @@ virNetworkDefUpdateIPDHCPHost(virNetworkDefPtr def, if (VIR_INSERT_ELEMENT(ipdef->hosts, command == VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST ? 0 : ipdef->nhosts, - ipdef->nhosts, host) < 0) { - virReportOOMError(); + ipdef->nhosts, host, true) < 0) goto cleanup; - } } else if (command == VIR_NETWORK_UPDATE_COMMAND_DELETE) { if (virNetworkDHCPHostDefParseXML(def->name, ipdef, @@ -3520,11 +3518,8 @@ virNetworkDefUpdateIPDHCPRange(virNetworkDefPtr def, if (VIR_INSERT_ELEMENT(ipdef->ranges, command == VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST ? 0 : ipdef->nranges, - ipdef->nranges, range) < 0) { - virReportOOMError(); + ipdef->nranges, range, true) < 0) goto cleanup; - } - } else if (command == VIR_NETWORK_UPDATE_COMMAND_DELETE) { if (ii == ipdef->nranges) { @@ -3615,11 +3610,8 @@ virNetworkDefUpdateForwardInterface(virNetworkDefPtr def, if (VIR_INSERT_ELEMENT(def->forward.ifs, command == VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST ? 0 : def->forward.nifs, - def->forward.nifs, iface) < 0) { - virReportOOMError(); + def->forward.nifs, iface, true) < 0) goto cleanup; - } - } else if (command == VIR_NETWORK_UPDATE_COMMAND_DELETE) { if (ii == def->forward.nifs) { @@ -3742,11 +3734,8 @@ virNetworkDefUpdatePortGroup(virNetworkDefPtr def, if (VIR_INSERT_ELEMENT(def->portGroups, command == VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST ? 0 : def->nPortGroups, - def->nPortGroups, portgroup) < 0) { - virReportOOMError(); + def->nPortGroups, portgroup, true) < 0) goto cleanup; - } - } else if (command == VIR_NETWORK_UPDATE_COMMAND_DELETE) { /* remove it */ @@ -3825,11 +3814,8 @@ virNetworkDefUpdateDNSHost(virNetworkDefPtr def, /* add to beginning/end of list */ if (VIR_INSERT_ELEMENT(dns->hosts, command == VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST - ? 0 : dns->nhosts, dns->nhosts, host) < 0) { - virReportOOMError(); + ? 0 : dns->nhosts, dns->nhosts, host, true) < 0) goto cleanup; - } - } else if (command == VIR_NETWORK_UPDATE_COMMAND_DELETE) { if (foundCt == 0) { @@ -3913,11 +3899,8 @@ virNetworkDefUpdateDNSSrv(virNetworkDefPtr def, /* add to beginning/end of list */ if (VIR_INSERT_ELEMENT(dns->srvs, command == VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST - ? 0 : dns->nsrvs, dns->nsrvs, srv) < 0) { - virReportOOMError(); + ? 0 : dns->nsrvs, dns->nsrvs, srv, true) < 0) goto cleanup; - } - } else if (command == VIR_NETWORK_UPDATE_COMMAND_DELETE) { if (foundCt == 0) { @@ -3995,11 +3978,8 @@ virNetworkDefUpdateDNSTxt(virNetworkDefPtr def, /* add to beginning/end of list */ if (VIR_INSERT_ELEMENT(dns->txts, command == VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST - ? 0 : dns->ntxts, dns->ntxts, txt) < 0) { - virReportOOMError(); + ? 0 : dns->ntxts, dns->ntxts, txt, true) < 0) goto cleanup; - } - } else if (command == VIR_NETWORK_UPDATE_COMMAND_DELETE) { if (foundIdx == dns->ntxts) { diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 3209604..7406652 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -1025,7 +1025,7 @@ virNodeDevCapPciDevIommuGroupParseXML(xmlXPathContextPtr ctxt, pciAddr->function = addr.function; if (VIR_APPEND_ELEMENT(data->pci_dev.iommuGroupDevices, data->pci_dev.nIommuGroupDevices, - pciAddr) < 0) { + pciAddr, false) < 0) { virReportOOMError(); goto cleanup; } diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c index 8dc2592..39420b6 100644 --- a/src/esx/esx_vi.c +++ b/src/esx/esx_vi.c @@ -1750,7 +1750,7 @@ esxVI_Alloc(void **ptrptr, size_t size) return -1; } - if (virAllocN(ptrptr, size, 1) < 0) { + if (virAllocN(ptrptr, size, 1, false, 0, NULL, NULL, 0) < 0) { virReportOOMError(); return -1; } diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index 990decb..01e35c4 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -1003,8 +1003,8 @@ virLXCProcessEnsureRootFS(virDomainObjPtr vm) if (VIR_INSERT_ELEMENT(vm->def->fss, 0, vm->def->nfss, - root) < 0) - goto no_memory; + root, true) < 0) + goto error; return 0; diff --git a/src/security/security_manager.c b/src/security/security_manager.c index f7c5c2e..f5ea73a 100644 --- a/src/security/security_manager.c +++ b/src/security/security_manager.c @@ -487,10 +487,8 @@ int virSecurityManagerGenLabel(virSecurityManagerPtr mgr, /* The seclabel must be added to @vm prior calling domainGenSecurityLabel * which may require seclabel to be presented already */ if (generated && - VIR_APPEND_ELEMENT(vm->seclabels, vm->nseclabels, seclabel) < 0) { - virReportOOMError(); + VIR_APPEND_ELEMENT(vm->seclabels, vm->nseclabels, seclabel, true) < 0) goto cleanup; - } if (sec_managers[i]->drv->domainGenSecurityLabel(sec_managers[i], vm) < 0) { if (VIR_DELETE_ELEMENT(vm->seclabels, diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c index 7802dda..8842d85 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -1227,8 +1227,8 @@ virSecuritySELinuxSetSecurityFileLabel(virDomainDiskDefPtr disk, if (!disk_seclabel) return -1; disk_seclabel->norelabel = true; - if (VIR_APPEND_ELEMENT(disk->seclabels, disk->nseclabels, disk_seclabel) < 0) { - virReportOOMError(); + if (VIR_APPEND_ELEMENT(disk->seclabels, disk->nseclabels, + disk_seclabel, true) < 0) { virSecurityDeviceLabelDefFree(disk_seclabel); return -1; } diff --git a/src/util/viralloc.c b/src/util/viralloc.c index 8d6a7e6..16afac7 100644 --- a/src/util/viralloc.c +++ b/src/util/viralloc.c @@ -25,6 +25,9 @@ #include "viralloc.h" #include "virlog.h" +#include "virerror.h" + +#define VIR_FROM_THIS VIR_FROM_NONE #if TEST_OOM static int testMallocNext = 0; @@ -105,14 +108,26 @@ void virAllocTestHook(void (*func)(int, void*) ATTRIBUTE_UNUSED, * virAlloc: * @ptrptr: pointer to pointer for address of allocated memory * @size: number of bytes to allocate + * @report: whether to report OOM error, if there is one + * @domcode: error domain code + * @filename: caller's filename + * @funcname: caller's funcname + * @linenr: caller's line number * * Allocate 'size' bytes of memory. Return the address of the * allocated memory in 'ptrptr'. The newly allocated memory is - * filled with zeros. + * filled with zeros. In case of OOM error and @report is true, + * the error is reported. * * Returns -1 on failure to allocate, zero on success */ -int virAlloc(void *ptrptr, size_t size) +int virAlloc(void *ptrptr, + size_t size, + bool report, + int domcode, + const char *filename, + const char *funcname, + size_t linenr) { #if TEST_OOM if (virAllocTestFail()) { @@ -122,8 +137,11 @@ int virAlloc(void *ptrptr, size_t size) #endif *(void **)ptrptr = calloc(1, size); - if (*(void **)ptrptr == NULL) + if (*(void **)ptrptr == NULL) { + if (report) + virReportOOMErrorFull(domcode, filename, funcname, linenr); return -1; + } return 0; } @@ -132,15 +150,28 @@ int virAlloc(void *ptrptr, size_t size) * @ptrptr: pointer to pointer for address of allocated memory * @size: number of bytes to allocate * @count: number of elements to allocate + * @report: whether to report OOM error, if there is one + * @domcode: error domain code + * @filename: caller's filename + * @funcname: caller's funcname + * @linenr: caller's line number * * Allocate an array of memory 'count' elements long, * each with 'size' bytes. Return the address of the * allocated memory in 'ptrptr'. The newly allocated - * memory is filled with zeros. + * memory is filled with zeros. In case of OOM error + * and @report is true, the error is reported. * * Returns -1 on failure to allocate, zero on success */ -int virAllocN(void *ptrptr, size_t size, size_t count) +int virAllocN(void *ptrptr, + size_t size, + size_t count, + bool report, + int domcode, + const char *filename, + const char *funcname, + size_t linenr) { #if TEST_OOM if (virAllocTestFail()) { @@ -150,8 +181,11 @@ int virAllocN(void *ptrptr, size_t size, size_t count) #endif *(void**)ptrptr = calloc(count, size); - if (*(void**)ptrptr == NULL) + if (*(void**)ptrptr == NULL) { + if (report) + virReportOOMErrorFull(domcode, filename, funcname, linenr); return -1; + } return 0; } @@ -160,16 +194,29 @@ int virAllocN(void *ptrptr, size_t size, size_t count) * @ptrptr: pointer to pointer for address of allocated memory * @size: number of bytes to allocate * @count: number of elements in array + * @report: whether to report OOM error, if there is one + * @domcode: error domain code + * @filename: caller's filename + * @funcname: caller's funcname + * @linenr: caller's line number * * Resize the block of memory in 'ptrptr' to be an array of * 'count' elements, each 'size' bytes in length. Update 'ptrptr' * with the address of the newly allocated memory. On failure, * 'ptrptr' is not changed and still points to the original memory * block. Any newly allocated memory in 'ptrptr' is uninitialized. + * In case of OOM error and @report is true, the error is reported. * * Returns -1 on failure to allocate, zero on success */ -int virReallocN(void *ptrptr, size_t size, size_t count) +int virReallocN(void *ptrptr, + size_t size, + size_t count, + bool report, + int domcode, + const char *filename, + const char *funcname, + size_t linenr) { void *tmp; #if TEST_OOM @@ -178,12 +225,17 @@ int virReallocN(void *ptrptr, size_t size, size_t count) #endif if (xalloc_oversized(count, size)) { + if (report) + virReportOOMErrorFull(domcode, filename, funcname, linenr); errno = ENOMEM; return -1; } tmp = realloc(*(void**)ptrptr, size * count); - if (!tmp && (size * count)) + if (!tmp && (size * count)) { + if (report) + virReportOOMErrorFull(domcode, filename, funcname, linenr); return -1; + } *(void**)ptrptr = tmp; return 0; } @@ -194,24 +246,41 @@ int virReallocN(void *ptrptr, size_t size, size_t count) * @size: number of bytes per element * @countptr: pointer to number of elements in array * @add: number of elements to add + * @report: whether to report OOM error, if there is one + * @domcode: error domain code + * @filename: caller's filename + * @funcname: caller's funcname + * @linenr: caller's line number * * Resize the block of memory in 'ptrptr' to be an array of * '*countptr' + 'add' elements, each 'size' bytes in length. * Update 'ptrptr' and 'countptr' with the details of the newly * allocated memory. On failure, 'ptrptr' and 'countptr' are not * changed. Any newly allocated memory in 'ptrptr' is zero-filled. + * In case of OOM error and @report is true, the error is reported. * * Returns -1 on failure to allocate, zero on success */ -int virExpandN(void *ptrptr, size_t size, size_t *countptr, size_t add) +int virExpandN(void *ptrptr, + size_t size, + size_t *countptr, + size_t add, + bool report, + int domcode, + const char *filename, + const char *funcname, + size_t linenr) { int ret; if (*countptr + add < *countptr) { + if (report) + virReportOOMErrorFull(domcode, filename, funcname, linenr); errno = ENOMEM; return -1; } - ret = virReallocN(ptrptr, size, *countptr + add); + ret = virReallocN(ptrptr, size, *countptr + add, report, + domcode, filename, funcname, linenr); if (ret == 0) { memset(*(char **)ptrptr + (size * *countptr), 0, size * add); *countptr += add; @@ -226,22 +295,38 @@ int virExpandN(void *ptrptr, size_t size, size_t *countptr, size_t add) * @allocptr: pointer to number of elements allocated in array * @count: number of elements currently used in array * @add: minimum number of additional elements to support in array + * @report: whether to report OOM error, if there is one + * @domcode: error domain code + * @filename: caller's filename + * @funcname: caller's funcname + * @linenr: caller's line number * * If 'count' + 'add' is larger than '*allocptr', then resize the * block of memory in 'ptrptr' to be an array of at least 'count' + * 'add' elements, each 'size' bytes in length. Update 'ptrptr' and * 'allocptr' with the details of the newly allocated memory. On * failure, 'ptrptr' and 'allocptr' are not changed. Any newly - * allocated memory in 'ptrptr' is zero-filled. + * allocated memory in 'ptrptr' is zero-filled. In case of OOM error + * and @report is true, the error is reported. * * Returns -1 on failure to allocate, zero on success */ -int virResizeN(void *ptrptr, size_t size, size_t *allocptr, size_t count, - size_t add) +int virResizeN(void *ptrptr, + size_t size, + size_t *allocptr, + size_t count, + size_t add, + bool report, + int domcode, + const char *filename, + const char *funcname, + size_t linenr) { size_t delta; if (count + add < count) { + if (report) + virReportOOMErrorFull(domcode, filename, funcname, linenr); errno = ENOMEM; return -1; } @@ -251,7 +336,8 @@ int virResizeN(void *ptrptr, size_t size, size_t *allocptr, size_t count, delta = count + add - *allocptr; if (delta < *allocptr / 2) delta = *allocptr / 2; - return virExpandN(ptrptr, size, allocptr, delta); + return virExpandN(ptrptr, size, allocptr, delta, report, + domcode, filename, funcname, linenr); } /** @@ -270,7 +356,8 @@ int virResizeN(void *ptrptr, size_t size, size_t *allocptr, size_t count, void virShrinkN(void *ptrptr, size_t size, size_t *countptr, size_t toremove) { if (toremove < *countptr) - ignore_value(virReallocN(ptrptr, size, *countptr -= toremove)); + ignore_value(virReallocN(ptrptr, size, *countptr -= toremove, + false, 0, NULL, NULL, 0)); else { virFree(ptrptr); *countptr = 0; @@ -293,6 +380,11 @@ void virShrinkN(void *ptrptr, size_t size, size_t *countptr, size_t toremove) * @inPlace: false if we should expand the allocated memory before * moving, true if we should assume someone else *has * already* done that. + * @report: whether to report OOM error, if there is one + * @domcode: error domain code + * @filename: caller's filename + * @funcname: caller's funcname + * @linenr: caller's line number * * Re-allocate an array of *countptr elements, each sizeof(*ptrptr) bytes * long, to be *countptr+add elements long, then appropriately move @@ -301,7 +393,8 @@ void virShrinkN(void *ptrptr, size_t size, size_t *countptr, size_t toremove) * allocated memory in *ptrptr and the new size in *countptr. If * newelems is NULL, the new elements at ptrptr[at] are instead filled * with zero. at must be between [0,*countptr], except that -1 is - * treated the same as *countptr for convenience. + * treated the same as *countptr for convenience. In case of OOM error + * and @report is true, the error is reported. * * Returns -1 on failure, 0 on success */ @@ -309,19 +402,26 @@ int virInsertElementsN(void *ptrptr, size_t size, size_t at, size_t *countptr, size_t add, void *newelems, - bool clearOriginal, bool inPlace) + bool clearOriginal, bool inPlace, + bool report, + int domcode, + const char *filename, + const char *funcname, + size_t linenr) { if (at == -1) { at = *countptr; } else if (at > *countptr) { - VIR_WARN("out of bounds index - count %zu at %zu add %zu", - *countptr, at, add); + virReportError(VIR_ERR_INTERNAL_ERROR, + _("out of bounds index - count %zu at %zu add %zu"), + *countptr, at, add); return -1; } if (inPlace) { *countptr += add; - } else if (virExpandN(ptrptr, size, countptr, add) < 0) { + } else if (virExpandN(ptrptr, size, countptr, add, report, + domcode, filename, funcname, linenr) < 0) { return -1; } @@ -397,6 +497,11 @@ virDeleteElementsN(void *ptrptr, size_t size, size_t at, * @struct_size: size of initial struct * @element_size: size of array elements * @count: number of array elements to allocate + * @report: whether to report OOM error, if there is one + * @domcode: error domain code + * @filename: caller's filename + * @funcname: caller's funcname + * @linenr: caller's line number * * Allocate struct_size bytes plus an array of 'count' elements, each * of size element_size. This sort of allocation is useful for @@ -405,11 +510,20 @@ virDeleteElementsN(void *ptrptr, size_t size, size_t at, * The caller of this type of API is expected to know the length of * the array that will be returned and allocate a suitable buffer to * contain the returned data. C99 refers to these variable length - * objects as structs containing flexible array members. + * objects as structs containing flexible array members. In case of + * OOM error and @report is true, the error is reported. * * Returns -1 on failure, 0 on success */ -int virAllocVar(void *ptrptr, size_t struct_size, size_t element_size, size_t count) +int virAllocVar(void *ptrptr, + size_t struct_size, + size_t element_size, + size_t count, + bool report, + int domcode, + const char *filename, + const char *funcname, + size_t linenr) { size_t alloc_size = 0; @@ -419,14 +533,19 @@ int virAllocVar(void *ptrptr, size_t struct_size, size_t element_size, size_t co #endif if (VIR_ALLOC_VAR_OVERSIZED(struct_size, count, element_size)) { + if (report) + virReportOOMErrorFull(domcode, filename, funcname, linenr); errno = ENOMEM; return -1; } alloc_size = struct_size + (element_size * count); *(void **)ptrptr = calloc(1, alloc_size); - if (*(void **)ptrptr == NULL) + if (*(void **)ptrptr == NULL) { + if (report) + virReportOOMErrorFull(domcode, filename, funcname, linenr); return -1; + } return 0; } diff --git a/src/util/viralloc.h b/src/util/viralloc.h index 35d3a37..f0dba49 100644 --- a/src/util/viralloc.h +++ b/src/util/viralloc.h @@ -46,30 +46,36 @@ /* Don't call these directly - use the macros below */ -int virAlloc(void *ptrptr, size_t size) ATTRIBUTE_RETURN_CHECK - ATTRIBUTE_NONNULL(1); -int virAllocN(void *ptrptr, size_t size, size_t count) ATTRIBUTE_RETURN_CHECK - ATTRIBUTE_NONNULL(1); -int virReallocN(void *ptrptr, size_t size, size_t count) ATTRIBUTE_RETURN_CHECK - ATTRIBUTE_NONNULL(1); -int virExpandN(void *ptrptr, size_t size, size_t *count, size_t add) +int virAlloc(void *ptrptr, size_t size, bool report, int domcode, + const char *filename, const char *funcname, size_t linenr) + ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NONNULL(1); +int virAllocN(void *ptrptr, size_t size, size_t count, bool report, int domcode, + const char *filename, const char *funcname, size_t linenr) + ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NONNULL(1); +int virReallocN(void *ptrptr, size_t size, size_t count, bool report, int domcode, + const char *filename, const char *funcname, size_t linenr) + ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NONNULL(1); +int virExpandN(void *ptrptr, size_t size, size_t *count, size_t add, bool report, + int domcode, const char *filename, const char *funcname, size_t linenr) ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3); -int virResizeN(void *ptrptr, size_t size, size_t *alloc, size_t count, - size_t desired) +int virResizeN(void *ptrptr, size_t size, size_t *alloc, size_t count, size_t desired, + bool report, int domcode, const char *filename, + const char *funcname, size_t linenr) ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3); void virShrinkN(void *ptrptr, size_t size, size_t *count, size_t toremove) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3); int virInsertElementsN(void *ptrptr, size_t size, size_t at, size_t *countptr, size_t add, void *newelem, - bool clearOriginal, bool inPlace) + bool clearOriginal, bool inPlace, bool report, int domcode, + const char *filename, const char *funcname, size_t linenr) ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4); int virDeleteElementsN(void *ptrptr, size_t size, size_t at, size_t *countptr, size_t toremove, bool inPlace) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4); -int virAllocVar(void *ptrptr, - size_t struct_size, - size_t element_size, - size_t count) ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NONNULL(1); +int virAllocVar(void *ptrptr, size_t struct_size, size_t element_size, size_t count, + bool report, int domcode, const char *filename, + const char *funcname, size_t linenr) + ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NONNULL(1); void virFree(void *ptrptr) ATTRIBUTE_NONNULL(1); /** @@ -82,9 +88,24 @@ void virFree(void *ptrptr) ATTRIBUTE_NONNULL(1); * * This macro is safe to use on arguments with side effects. * + * Returns -1 on failure (with OOM error reported), 0 on success + */ +# define VIR_ALLOC(ptr) virAlloc(&(ptr), sizeof(*(ptr)), true, VIR_FROM_THIS, \ + __FILE__, __FUNCTION__, __LINE__) + +/** + * VIR_ALLOC_QUIET: + * @ptr: pointer to hold address of allocated memory + * + * Allocate sizeof(*ptr) bytes of memory and store + * the address of allocated memory in 'ptr'. Fill the + * newly allocated memory with zeros. + * + * This macro is safe to use on arguments with side effects. + * * Returns -1 on failure, 0 on success */ -# define VIR_ALLOC(ptr) virAlloc(&(ptr), sizeof(*(ptr))) +# define VIR_ALLOC_QUIET(ptr) virAlloc(&(ptr), sizeof(*(ptr)), false, 0, NULL, NULL, 0) /** * VIR_ALLOC_N: @@ -97,9 +118,26 @@ void virFree(void *ptrptr) ATTRIBUTE_NONNULL(1); * * This macro is safe to use on arguments with side effects. * + * Returns -1 on failure (with OOM error reported), 0 on success + */ +# define VIR_ALLOC_N(ptr, count) virAllocN(&(ptr), sizeof(*(ptr)), (count), true, \ + VIR_FROM_THIS, __FILE__, __FUNCTION__, __LINE__) + +/** + * VIR_ALLOC_N_QUIET: + * @ptr: pointer to hold address of allocated memory + * @count: number of elements to allocate + * + * Allocate an array of 'count' elements, each sizeof(*ptr) + * bytes long and store the address of allocated memory in + * 'ptr'. Fill the newly allocated memory with zeros. + * + * This macro is safe to use on arguments with side effects. + * * Returns -1 on failure, 0 on success */ -# define VIR_ALLOC_N(ptr, count) virAllocN(&(ptr), sizeof(*(ptr)), (count)) +# define VIR_ALLOC_N_QUIET(ptr, count) virAllocN(&(ptr), sizeof(*(ptr)), (count), \ + false, 0, NULL, NULL, 0) /** * VIR_REALLOC_N: @@ -112,9 +150,27 @@ void virFree(void *ptrptr) ATTRIBUTE_NONNULL(1); * * This macro is safe to use on arguments with side effects. * + * Returns -1 on failure (with OOM error reported), 0 on success + */ +# define VIR_REALLOC_N(ptr, count) virReallocN(&(ptr), sizeof(*(ptr)), (count), \ + true, VIR_FROM_THIS, __FILE__, \ + __FUNCTION__, __LINE__) + +/** + * VIR_REALLOC_N_QUIET: + * @ptr: pointer to hold address of allocated memory + * @count: number of elements to allocate + * + * Re-allocate an array of 'count' elements, each sizeof(*ptr) + * bytes long and store the address of allocated memory in + * 'ptr'. If 'ptr' grew, the added memory is uninitialized. + * + * This macro is safe to use on arguments with side effects. + * * Returns -1 on failure, 0 on success */ -# define VIR_REALLOC_N(ptr, count) virReallocN(&(ptr), sizeof(*(ptr)), (count)) +# define VIR_REALLOC_N_QUIET(ptr, count) virReallocN(&(ptr), sizeof(*(ptr)), (count), \ + false, 0, NULL, NULL, 0) /** * VIR_EXPAND_N: @@ -129,10 +185,29 @@ void virFree(void *ptrptr) ATTRIBUTE_NONNULL(1); * * This macro is safe to use on arguments with side effects. * - * Returns -1 on failure, 0 on success + * Returns -1 on failure (with OOM error reported), 0 on success */ # define VIR_EXPAND_N(ptr, count, add) \ - virExpandN(&(ptr), sizeof(*(ptr)), &(count), add) + virExpandN(&(ptr), sizeof(*(ptr)), &(count), add, true, VIR_FROM_THIS, \ + __FILE__, __FUNCTION__, __LINE__) + +/** + * VIR_EXPAND_N_QUIET: + * @ptr: pointer to hold address of allocated memory + * @count: variable tracking number of elements currently allocated + * @add: number of elements to add + * + * Re-allocate an array of 'count' elements, each sizeof(*ptr) + * bytes long, to be 'count' + 'add' elements long, then store the + * address of allocated memory in 'ptr' and the new size in 'count'. + * The new elements are filled with zero. + * + * This macro is safe to use on arguments with side effects. + * + * Returns -1 on failure, 0 on success + */ +# define VIR_EXPAND_N_QUIET(ptr, count, add) \ + virExpandN(&(ptr), sizeof(*(ptr)), &(count), add, false, 0, NULL, NULL, 0) /** * VIR_RESIZE_N: @@ -154,10 +229,37 @@ void virFree(void *ptrptr) ATTRIBUTE_NONNULL(1); * * This macro is safe to use on arguments with side effects. * - * Returns -1 on failure, 0 on success + * Returns -1 on failure (with OOM error reported), 0 on success */ # define VIR_RESIZE_N(ptr, alloc, count, add) \ - virResizeN(&(ptr), sizeof(*(ptr)), &(alloc), count, add) + virResizeN(&(ptr), sizeof(*(ptr)), &(alloc), count, add, true, \ + VIR_FROM_THIS, __FILE__, __FUNCTION__, __LINE__) + +/** + * VIR_RESIZE_N_QUIET: + * @ptr: pointer to hold address of allocated memory + * @alloc: variable tracking number of elements currently allocated + * @count: number of elements currently in use + * @add: minimum number of elements to additionally support + * + * Blindly using VIR_EXPAND_N(array, alloc, 1) in a loop scales + * quadratically, because every iteration must copy contents from + * all prior iterations. But amortized linear scaling can be achieved + * by tracking allocation size separately from the number of used + * elements, and growing geometrically only as needed. + * + * If 'count' + 'add' is larger than 'alloc', then geometrically reallocate + * the array of 'alloc' elements, each sizeof(*ptr) bytes long, and store + * the address of allocated memory in 'ptr' and the new size in 'alloc'. + * The new elements are filled with zero. + * + * This macro is safe to use on arguments with side effects. + * + * Returns -1 on failure, 0 on success + */ +# define VIR_RESIZE_N_QUIET(ptr, alloc, count, add) \ + virResizeN(&(ptr), sizeof(*(ptr)), &(alloc), count, add, \ + false, 0, NULL, NULL, 0) /** * VIR_SHRINK_N: @@ -224,6 +326,7 @@ void virFree(void *ptrptr) ATTRIBUTE_NONNULL(1); * @newelem: the new element to move into place (*not* a pointer to * the element, but the element itself). * (the original will be zeroed out if successful) + * @report: whether report OOM error on failure * * Re-allocate an array of 'count' elements, each sizeof(*ptr) bytes * long, to be 'count' + 1 elements long, then appropriately move @@ -252,18 +355,22 @@ void virFree(void *ptrptr) ATTRIBUTE_NONNULL(1); * * Returns -1 on failure, 0 on success */ -# define VIR_INSERT_ELEMENT(ptr, at, count, newelem) \ +# define VIR_INSERT_ELEMENT(ptr, at, count, newelem, report) \ virInsertElementsN(&(ptr), sizeof(*(ptr)), at, &(count), \ - VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), true, false) -# define VIR_INSERT_ELEMENT_COPY(ptr, at, count, newelem) \ + VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), true, false, \ + report, VIR_FROM_THIS, __FILE__, __FUNCTION__, __LINE__) +# define VIR_INSERT_ELEMENT_COPY(ptr, at, count, newelem, report) \ virInsertElementsN(&(ptr), sizeof(*(ptr)), at, &(count), \ - VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), false, false) -# define VIR_INSERT_ELEMENT_INPLACE(ptr, at, count, newelem) \ + VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), false, false, \ + report, VIR_FROM_THIS, __FILE__, __FUNCTION__, __LINE__) +# define VIR_INSERT_ELEMENT_INPLACE(ptr, at, count, newelem, report) \ virInsertElementsN(&(ptr), sizeof(*(ptr)), at, &(count), \ - VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), true, true) -# define VIR_INSERT_ELEMENT_COPY_INPLACE(ptr, at, count, newelem) \ + VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), true, true, \ + report, VIR_FROM_THIS, __FILE__, __FUNCTION__, __LINE__) +# define VIR_INSERT_ELEMENT_COPY_INPLACE(ptr, at, count, newelem, report) \ virInsertElementsN(&(ptr), sizeof(*(ptr)), at, &(count), \ - VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), false, true) + VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), false, true, \ + report, VIR_FROM_THIS, __FILE__, __FUNCTION__, __LINE__) /** * VIR_APPEND_ELEMENT: @@ -272,6 +379,7 @@ void virFree(void *ptrptr) ATTRIBUTE_NONNULL(1); * @newelem: the new element to move into place (*not* a pointer to * the element, but the element itself). * (the original will be zeroed out if successful) + * @report: whether report OOM error on failure * * Re-allocate an array of 'count' elements, each sizeof(*ptr) bytes * long, to be 'count' + 1 elements long, then copy the item from @@ -300,18 +408,22 @@ void virFree(void *ptrptr) ATTRIBUTE_NONNULL(1); * * Returns -1 on failure, 0 on success */ -# define VIR_APPEND_ELEMENT(ptr, count, newelem) \ +# define VIR_APPEND_ELEMENT(ptr, count, newelem, report) \ virInsertElementsN(&(ptr), sizeof(*(ptr)), -1, &(count), \ - VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), true, false) -# define VIR_APPEND_ELEMENT_COPY(ptr, count, newelem) \ + VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), true, false, \ + report, VIR_FROM_THIS, __FILE__, __FUNCTION__, __LINE__) +# define VIR_APPEND_ELEMENT_COPY(ptr, count, newelem, report) \ virInsertElementsN(&(ptr), sizeof(*(ptr)), -1, &(count), \ - VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), false, false) -# define VIR_APPEND_ELEMENT_INPLACE(ptr, count, newelem) \ + VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), false, false, \ + report, VIR_FROM_THIS, __FILE__, __FUNCTION__, __LINE__) +# define VIR_APPEND_ELEMENT_INPLACE(ptr, count, newelem, report) \ virInsertElementsN(&(ptr), sizeof(*(ptr)), -1, &(count), \ - VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), true, true) -# define VIR_APPEND_ELEMENT_COPY_INPLACE(ptr, count, newelem) \ + VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), true, true, \ + report, VIR_FROM_THIS, __FILE__, __FUNCTION__, __LINE__) +# define VIR_APPEND_ELEMENT_COPY_INPLACE(ptr, count, newelem, report) \ virInsertElementsN(&(ptr), sizeof(*(ptr)), -1, &(count), \ - VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), false, true) + VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), false, true, \ + report, VIR_FROM_THIS, __FILE__, __FUNCTION__, __LINE__) /** * VIR_DELETE_ELEMENT: @@ -365,10 +477,33 @@ void virFree(void *ptrptr) ATTRIBUTE_NONNULL(1); * * This macro is safe to use on arguments with side effects. * - * Returns -1 on failure, 0 on success + * Returns -1 on failure (with OOM error reported), 0 on success */ # define VIR_ALLOC_VAR(ptr, type, count) \ - virAllocVar(&(ptr), sizeof(*(ptr)), sizeof(type), (count)) + virAllocVar(&(ptr), sizeof(*(ptr)), sizeof(type), (count), true, \ + VIR_FROM_THIS, __FILE__, __FUNCTION__, __LINE__) + +/** + * VIR_ALLOC_VAR_QUIET: + * @ptr: pointer to hold address of allocated memory + * @type: element type of trailing array + * @count: number of array elements to allocate + * + * Allocate sizeof(*ptr) bytes plus an array of 'count' elements, each + * sizeof('type'). This sort of allocation is useful for receiving + * the data of certain ioctls and other APIs which return a struct in + * which the last element is an array of undefined length. The caller + * of this type of API is expected to know the length of the array + * that will be returned and allocate a suitable buffer to contain the + * returned data. C99 refers to these variable length objects as + * structs containing flexible array members. + * + * This macro is safe to use on arguments with side effects. + * + * Returns -1 on failure, 0 on success + */ +# define VIR_ALLOC_VAR_QUIET(ptr, type, count) \ + virAllocVar(&(ptr), sizeof(*(ptr)), sizeof(type), (count), false, 0, NULL, NULL, 0) /** * VIR_FREE: diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c index 4969497..ee0be6c 100644 --- a/src/util/virbuffer.c +++ b/src/util/virbuffer.c @@ -126,7 +126,7 @@ virBufferGrow(virBufferPtr buf, unsigned int len) size = buf->use + len + 1000; - if (VIR_REALLOC_N(buf->content, size) < 0) { + if (VIR_REALLOC_N_QUIET(buf->content, size) < 0) { virBufferSetError(buf, errno); return -1; } @@ -382,7 +382,7 @@ virBufferEscapeString(virBufferPtr buf, const char *format, const char *str) } if (xalloc_oversized(6, len) || - VIR_ALLOC_N(escaped, 6 * len + 1) < 0) { + VIR_ALLOC_N_QUIET(escaped, 6 * len + 1) < 0) { virBufferSetError(buf, errno); return; } @@ -499,7 +499,7 @@ virBufferEscape(virBufferPtr buf, char escape, const char *toescape, } if (xalloc_oversized(2, len) || - VIR_ALLOC_N(escaped, 2 * len + 1) < 0) { + VIR_ALLOC_N_QUIET(escaped, 2 * len + 1) < 0) { virBufferSetError(buf, errno); return; } @@ -597,7 +597,7 @@ virBufferEscapeShell(virBufferPtr buf, const char *str) if (*str) { len = strlen(str); if (xalloc_oversized(4, len) || - VIR_ALLOC_N(escaped, 4 * len + 3) < 0) { + VIR_ALLOC_N_QUIET(escaped, 4 * len + 3) < 0) { virBufferSetError(buf, errno); return; } diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index e0b25ed..13fd162 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -1171,7 +1171,7 @@ static int virCgroupPartitionEscape(char **path) if ((rc = virCgroupPartitionNeedsEscaping(*path)) <= 0) return rc; - if (VIR_INSERT_ELEMENT(*path, 0, len, escape) < 0) + if (VIR_INSERT_ELEMENT(*path, 0, len, escape, false) < 0) return -ENOMEM; return 0; diff --git a/src/util/virerror.c b/src/util/virerror.c index 4789bae..e238dce 100644 --- a/src/util/virerror.c +++ b/src/util/virerror.c @@ -209,7 +209,7 @@ virLastErrorObject(void) virErrorPtr err; err = virThreadLocalGet(&virLastErr); if (!err) { - if (VIR_ALLOC(err) < 0) + if (VIR_ALLOC_QUIET(err) < 0) return NULL; if (virThreadLocalSet(&virLastErr, err) < 0) VIR_FREE(err); @@ -330,7 +330,7 @@ virSaveLastError(void) virErrorPtr to; int saved_errno = errno; - if (VIR_ALLOC(to) < 0) + if (VIR_ALLOC_QUIET(to) < 0) return NULL; virCopyLastError(to); diff --git a/src/util/virpci.c b/src/util/virpci.c index 54f7715..9ed257e 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -2009,7 +2009,7 @@ virPCIGetIOMMUGroupAddressesAddOne(virPCIDeviceAddressPtr newDevAddr, void *opaq *copyAddr = *newDevAddr; if (VIR_APPEND_ELEMENT(*addrList->iommuGroupDevices, - *addrList->nIommuGroupDevices, copyAddr) < 0) { + *addrList->nIommuGroupDevices, copyAddr, false) < 0) { virReportOOMError(); goto cleanup; } diff --git a/src/util/virthreadpthread.c b/src/util/virthreadpthread.c index 75b5fd6..ca841e4 100644 --- a/src/util/virthreadpthread.c +++ b/src/util/virthreadpthread.c @@ -174,7 +174,7 @@ int virThreadCreate(virThreadPtr thread, if ((err = pthread_attr_init(&attr)) != 0) goto cleanup; - if (VIR_ALLOC(args) < 0) { + if (VIR_ALLOC_QUIET(args) < 0) { err = ENOMEM; goto cleanup; } diff --git a/tests/commandhelper.c b/tests/commandhelper.c index e4cc5d2..d492c70 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -35,6 +35,7 @@ #ifndef WIN32 +# define VIR_FROM_THIS VIR_FROM_NONE static int envsort(const void *a, const void *b) { const char *const*astrptr = a; diff --git a/tests/networkxml2conftest.c b/tests/networkxml2conftest.c index 520feba..b234b30 100644 --- a/tests/networkxml2conftest.c +++ b/tests/networkxml2conftest.c @@ -16,6 +16,8 @@ #include "network/bridge_driver.h" #include "virstring.h" +#define VIR_FROM_THIS VIR_FROM_NONE + static int testCompareXMLToConfFiles(const char *inxml, const char *outconf, dnsmasqCapsPtr caps) { diff --git a/tests/test_conf.c b/tests/test_conf.c index d5467e8..acf41c6 100644 --- a/tests/test_conf.c +++ b/tests/test_conf.c @@ -20,7 +20,7 @@ int main(int argc, char **argv) goto cleanup; } - if (VIR_ALLOC_N(buffer, len) < 0) { + if (VIR_ALLOC_N_QUIET(buffer, len) < 0) { fprintf(stderr, "out of memory\n"); goto cleanup; } diff --git a/tests/xmconfigtest.c b/tests/xmconfigtest.c index 8e0c59e..73e4a2d 100644 --- a/tests/xmconfigtest.c +++ b/tests/xmconfigtest.c @@ -37,6 +37,8 @@ #include "viralloc.h" #include "virstring.h" +#define VIR_FROM_THIS VIR_FROM_NONE + static virCapsPtr caps; static virDomainXMLOptionPtr xmlopt; -- 1.8.1.5

On 07/04/13 14:06, Michal Privoznik wrote:
Similarly to VIR_STRDUP, we want the OOM error to be reported in VIR_ALLOC and friends. --- po/POTFILES.in | 1 + python/libvirt-override.c | 102 +++++++++---------- src/conf/domain_conf.c | 9 +- src/conf/network_conf.c | 34 ++----- src/conf/node_device_conf.c | 2 +- src/esx/esx_vi.c | 2 +- src/lxc/lxc_process.c | 4 +- src/security/security_manager.c | 4 +- src/security/security_selinux.c | 4 +- src/util/viralloc.c | 165 ++++++++++++++++++++++++++----- src/util/viralloc.h | 213 ++++++++++++++++++++++++++++++++-------- src/util/virbuffer.c | 8 +- src/util/vircgroup.c | 2 +- src/util/virerror.c | 4 +- src/util/virpci.c | 2 +- src/util/virthreadpthread.c | 2 +- tests/commandhelper.c | 1 + tests/networkxml2conftest.c | 2 + tests/test_conf.c | 2 +- tests/xmconfigtest.c | 2 + 20 files changed, 401 insertions(+), 164 deletions(-)
diff --git a/python/libvirt-override.c b/python/libvirt-override.c index 5c5586d..6b6e77b 100644 --- a/python/libvirt-override.c +++ b/python/libvirt-override.c
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 64fd581..d6799d2 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c
@@ -3995,11 +3978,8 @@ virNetworkDefUpdateDNSTxt(virNetworkDefPtr def, /* add to beginning/end of list */ if (VIR_INSERT_ELEMENT(dns->txts, command == VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST - ? 0 : dns->ntxts, dns->ntxts, txt) < 0) { - virReportOOMError(); + ? 0 : dns->ntxts, dns->ntxts, txt, true) < 0)
Here and in multiple similar instances you remove the OOMError and set the autoreporting to true ...
goto cleanup; - } - } else if (command == VIR_NETWORK_UPDATE_COMMAND_DELETE) {
if (foundIdx == dns->ntxts) { diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 3209604..7406652 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -1025,7 +1025,7 @@ virNodeDevCapPciDevIommuGroupParseXML(xmlXPathContextPtr ctxt, pciAddr->function = addr.function; if (VIR_APPEND_ELEMENT(data->pci_dev.iommuGroupDevices, data->pci_dev.nIommuGroupDevices, - pciAddr) < 0) { + pciAddr, false) < 0) {
but here you don't. You probably are going to clean this up later but you could be consistent.
virReportOOMError(); goto cleanup; }
diff --git a/src/security/security_manager.c b/src/security/security_manager.c index f7c5c2e..f5ea73a 100644 --- a/src/security/security_manager.c +++ b/src/security/security_manager.c @@ -487,10 +487,8 @@ int virSecurityManagerGenLabel(virSecurityManagerPtr mgr, /* The seclabel must be added to @vm prior calling domainGenSecurityLabel * which may require seclabel to be presented already */ if (generated && - VIR_APPEND_ELEMENT(vm->seclabels, vm->nseclabels, seclabel) < 0) { - virReportOOMError(); + VIR_APPEND_ELEMENT(vm->seclabels, vm->nseclabels, seclabel, true) < 0)
and again using auto OOM error reporting
goto cleanup; - }
if (sec_managers[i]->drv->domainGenSecurityLabel(sec_managers[i], vm) < 0) { if (VIR_DELETE_ELEMENT(vm->seclabels,
diff --git a/src/util/viralloc.c b/src/util/viralloc.c index 8d6a7e6..16afac7 100644 --- a/src/util/viralloc.c +++ b/src/util/viralloc.c
...
@@ -132,15 +150,28 @@ int virAlloc(void *ptrptr, size_t size) * @ptrptr: pointer to pointer for address of allocated memory * @size: number of bytes to allocate * @count: number of elements to allocate + * @report: whether to report OOM error, if there is one + * @domcode: error domain code + * @filename: caller's filename + * @funcname: caller's funcname + * @linenr: caller's line number * * Allocate an array of memory 'count' elements long, * each with 'size' bytes. Return the address of the * allocated memory in 'ptrptr'. The newly allocated - * memory is filled with zeros. + * memory is filled with zeros. In case of OOM error + * and @report is true, the error is reported.
I'd write this as: "If @report is true, OOM errors are reported automatically." or something similar.
* * Returns -1 on failure to allocate, zero on success
...
@@ -160,16 +194,29 @@ int virAllocN(void *ptrptr, size_t size, size_t count) * @ptrptr: pointer to pointer for address of allocated memory * @size: number of bytes to allocate * @count: number of elements in array + * @report: whether to report OOM error, if there is one + * @domcode: error domain code + * @filename: caller's filename + * @funcname: caller's funcname + * @linenr: caller's line number * * Resize the block of memory in 'ptrptr' to be an array of * 'count' elements, each 'size' bytes in length. Update 'ptrptr' * with the address of the newly allocated memory. On failure, * 'ptrptr' is not changed and still points to the original memory * block. Any newly allocated memory in 'ptrptr' is uninitialized. + * In case of OOM error and @report is true, the error is reported.
here too
* * Returns -1 on failure to allocate, zero on success */
...
@@ -194,24 +246,41 @@ int virReallocN(void *ptrptr, size_t size, size_t count) * @size: number of bytes per element * @countptr: pointer to number of elements in array * @add: number of elements to add + * @report: whether to report OOM error, if there is one + * @domcode: error domain code + * @filename: caller's filename + * @funcname: caller's funcname + * @linenr: caller's line number * * Resize the block of memory in 'ptrptr' to be an array of * '*countptr' + 'add' elements, each 'size' bytes in length. * Update 'ptrptr' and 'countptr' with the details of the newly * allocated memory. On failure, 'ptrptr' and 'countptr' are not * changed. Any newly allocated memory in 'ptrptr' is zero-filled. + * In case of OOM error and @report is true, the error is reported.
again
* * Returns -1 on failure to allocate, zero on success */
...
@@ -226,22 +295,38 @@ int virExpandN(void *ptrptr, size_t size, size_t *countptr, size_t add) * @allocptr: pointer to number of elements allocated in array * @count: number of elements currently used in array * @add: minimum number of additional elements to support in array + * @report: whether to report OOM error, if there is one + * @domcode: error domain code + * @filename: caller's filename + * @funcname: caller's funcname + * @linenr: caller's line number * * If 'count' + 'add' is larger than '*allocptr', then resize the * block of memory in 'ptrptr' to be an array of at least 'count' + * 'add' elements, each 'size' bytes in length. Update 'ptrptr' and * 'allocptr' with the details of the newly allocated memory. On * failure, 'ptrptr' and 'allocptr' are not changed. Any newly - * allocated memory in 'ptrptr' is zero-filled. + * allocated memory in 'ptrptr' is zero-filled. In case of OOM error + * and @report is true, the error is reported.
...
@@ -301,7 +393,8 @@ void virShrinkN(void *ptrptr, size_t size, size_t *countptr, size_t toremove) * allocated memory in *ptrptr and the new size in *countptr. If * newelems is NULL, the new elements at ptrptr[at] are instead filled * with zero. at must be between [0,*countptr], except that -1 is - * treated the same as *countptr for convenience. + * treated the same as *countptr for convenience. In case of OOM error + * and @report is true, the error is reported.
...
@@ -405,11 +510,20 @@ virDeleteElementsN(void *ptrptr, size_t size, size_t at, * The caller of this type of API is expected to know the length of * the array that will be returned and allocate a suitable buffer to * contain the returned data. C99 refers to these variable length - * objects as structs containing flexible array members. + * objects as structs containing flexible array members. In case of + * OOM error and @report is true, the error is reported. *
...
diff --git a/src/util/viralloc.h b/src/util/viralloc.h index 35d3a37..f0dba49 100644 --- a/src/util/viralloc.h +++ b/src/util/viralloc.h
-# define VIR_INSERT_ELEMENT(ptr, at, count, newelem) \ +# define VIR_INSERT_ELEMENT(ptr, at, count, newelem, report) \ virInsertElementsN(&(ptr), sizeof(*(ptr)), at, &(count), \ - VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), true, false) -# define VIR_INSERT_ELEMENT_COPY(ptr, at, count, newelem) \ + VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), true, false, \ + report, VIR_FROM_THIS, __FILE__, __FUNCTION__, __LINE__) +# define VIR_INSERT_ELEMENT_COPY(ptr, at, count, newelem, report) \ virInsertElementsN(&(ptr), sizeof(*(ptr)), at, &(count), \ - VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), false, false) -# define VIR_INSERT_ELEMENT_INPLACE(ptr, at, count, newelem) \ + VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), false, false, \ + report, VIR_FROM_THIS, __FILE__, __FUNCTION__, __LINE__) +# define VIR_INSERT_ELEMENT_INPLACE(ptr, at, count, newelem, report) \ virInsertElementsN(&(ptr), sizeof(*(ptr)), at, &(count), \ - VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), true, true) -# define VIR_INSERT_ELEMENT_COPY_INPLACE(ptr, at, count, newelem) \ + VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), true, true, \ + report, VIR_FROM_THIS, __FILE__, __FUNCTION__, __LINE__) +# define VIR_INSERT_ELEMENT_COPY_INPLACE(ptr, at, count, newelem, report) \ virInsertElementsN(&(ptr), sizeof(*(ptr)), at, &(count), \ - VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), false, true) + VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), false, true, \ + report, VIR_FROM_THIS, __FILE__, __FUNCTION__, __LINE__)
/** * VIR_APPEND_ELEMENT: @@ -272,6 +379,7 @@ void virFree(void *ptrptr) ATTRIBUTE_NONNULL(1); * @newelem: the new element to move into place (*not* a pointer to * the element, but the element itself). * (the original will be zeroed out if successful) + * @report: whether report OOM error on failure
I don't particularly like having a separate argument to enable error reporting for these. On the other hand, these helpers aren't used widely so this can be changed without a major refactor. Also, is there a usage of these helpers, where it isn't desired to report a error?
* * Re-allocate an array of 'count' elements, each sizeof(*ptr) bytes * long, to be 'count' + 1 elements long, then copy the item from
....
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index e0b25ed..13fd162 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -1171,7 +1171,7 @@ static int virCgroupPartitionEscape(char **path) if ((rc = virCgroupPartitionNeedsEscaping(*path)) <= 0) return rc;
- if (VIR_INSERT_ELEMENT(*path, 0, len, escape) < 0) + if (VIR_INSERT_ELEMENT(*path, 0, len, escape, false) < 0)
Hmmm, right, there is a caller that doesn't want to report errors from the array element helpers...
return -ENOMEM;
return 0;
....
diff --git a/src/util/virpci.c b/src/util/virpci.c index 54f7715..9ed257e 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -2009,7 +2009,7 @@ virPCIGetIOMMUGroupAddressesAddOne(virPCIDeviceAddressPtr newDevAddr, void *opaq *copyAddr = *newDevAddr;
if (VIR_APPEND_ELEMENT(*addrList->iommuGroupDevices, - *addrList->nIommuGroupDevices, copyAddr) < 0) { + *addrList->nIommuGroupDevices, copyAddr, false) < 0) { virReportOOMError();
again, this could be cleaned up right away.
goto cleanup; }
Additionally, I think that you need to treat src/util/virlog.c with the non-error-reporting functions right here to avoid possible infinite loops that might happen only on OOM errors. The rest of the patch looks fine and apart from the virlog.c issue I'd ack this patch. Peter

On 07/04/2013 08:06 AM, Michal Privoznik wrote:
virInsertElementsN(void *ptrptr, size_t size, size_t at, size_t *countptr, size_t add, void *newelems, - bool clearOriginal, bool inPlace) + bool clearOriginal, bool inPlace, + bool report, + int domcode, + const char *filename, + const char *funcname, + size_t linenr) { if (at == -1) { at = *countptr; } else if (at > *countptr) { - VIR_WARN("out of bounds index - count %zu at %zu add %zu", - *countptr, at, add); + virReportError(VIR_ERR_INTERNAL_ERROR, + _("out of bounds index - count %zu at %zu add %zu"), + *countptr, at, add); return -1;
If this happens and "report" is set to True, the caller will also report the error (but as OOM), overwriting this one. I don't really have a suggestion for a better way to handle it, just thought I'd point it out (that's why it was a VIR_WARN, but in the end that's really no better, since again the error code in the API would come from the caller, and in both cases the system logs would contain both the "out of bounds" message and the "out of memory" message).

Actually, I'm turning this function into a macro as filename, function name and line number needs to be passed. The new function virAsprintfInternal is introduced with the extended set of arguments. --- cfg.mk | 2 +- src/conf/domain_audit.c | 36 ++++++++++----------- src/driver.c | 4 +-- src/libvirt_private.syms | 4 +-- src/util/virerror.c | 2 +- src/util/virstring.c | 36 ++++++++++++--------- src/util/virstring.h | 67 +++++++++++++++++++++++++++++++++++---- tests/domainsnapshotxml2xmltest.c | 2 ++ tests/fchosttest.c | 2 ++ tests/interfacexml2xmltest.c | 2 ++ tests/lxcxml2xmltest.c | 2 ++ tests/networkxml2xmltest.c | 2 ++ tests/nodedevxml2xmltest.c | 2 ++ tests/nodeinfotest.c | 2 ++ tests/nwfilterxml2xmltest.c | 2 ++ tests/qemuargv2xmltest.c | 2 ++ tests/qemuhelptest.c | 2 ++ tests/qemuxml2xmltest.c | 2 ++ tests/sexpr2xmltest.c | 2 ++ tests/storagepoolxml2xmltest.c | 2 ++ tests/storagevolxml2argvtest.c | 2 ++ tests/storagevolxml2xmltest.c | 2 ++ tests/sysinfotest.c | 2 ++ tests/virbuftest.c | 2 ++ tests/virhashtest.c | 2 ++ tests/virshtest.c | 2 ++ tests/xencapstest.c | 2 ++ tests/xml2sexprtest.c | 2 ++ tools/virt-host-validate-common.c | 2 ++ 29 files changed, 150 insertions(+), 45 deletions(-) diff --git a/cfg.mk b/cfg.mk index bbe84b3..1b118a9 100644 --- a/cfg.mk +++ b/cfg.mk @@ -899,7 +899,7 @@ exclude_file_name_regexp--sc_prohibit_always_true_header_tests = \ ^python/(libvirt-(lxc-|qemu-)?override|typewrappers)\.c$$ exclude_file_name_regexp--sc_prohibit_asprintf = \ - ^(bootstrap.conf$$|src/util/virstring\.c$$|examples/domain-events/events-c/event-test\.c$$|tests/vircgroupmock\.c$$) + ^(bootstrap.conf$$|src/util/virstring\.[ch]$$|examples/domain-events/events-c/event-test\.c$$|tests/vircgroupmock\.c$$) exclude_file_name_regexp--sc_prohibit_strdup = \ ^(docs/|examples/|python/|src/util/virstring\.c$$) diff --git a/src/conf/domain_audit.c b/src/conf/domain_audit.c index 97e71f7..e53daf8 100644 --- a/src/conf/domain_audit.c +++ b/src/conf/domain_audit.c @@ -46,7 +46,7 @@ virDomainAuditGetRdev(const char *path) (S_ISCHR(sb.st_mode) || S_ISBLK(sb.st_mode))) { int maj = major(sb.st_rdev); int min = minor(sb.st_rdev); - ignore_value(virAsprintf(&ret, "%02X:%02X", maj, min)); + ignore_value(virAsprintfQuiet(&ret, "%02X:%02X", maj, min)); } return ret; } @@ -382,29 +382,29 @@ virDomainAuditHostdev(virDomainObjPtr vm, virDomainHostdevDefPtr hostdev, case VIR_DOMAIN_HOSTDEV_MODE_SUBSYS: switch (hostdev->source.subsys.type) { case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: - if (virAsprintf(&address, "%.4x:%.2x:%.2x.%.1x", - hostdev->source.subsys.u.pci.addr.domain, - hostdev->source.subsys.u.pci.addr.bus, - hostdev->source.subsys.u.pci.addr.slot, - hostdev->source.subsys.u.pci.addr.function) < 0) { + if (virAsprintfQuiet(&address, "%.4x:%.2x:%.2x.%.1x", + hostdev->source.subsys.u.pci.addr.domain, + hostdev->source.subsys.u.pci.addr.bus, + hostdev->source.subsys.u.pci.addr.slot, + hostdev->source.subsys.u.pci.addr.function) < 0) { VIR_WARN("OOM while encoding audit message"); goto cleanup; } break; case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: - if (virAsprintf(&address, "%.3d.%.3d", - hostdev->source.subsys.u.usb.bus, - hostdev->source.subsys.u.usb.device) < 0) { + if (virAsprintfQuiet(&address, "%.3d.%.3d", + hostdev->source.subsys.u.usb.bus, + hostdev->source.subsys.u.usb.device) < 0) { VIR_WARN("OOM while encoding audit message"); goto cleanup; } break; case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: - if (virAsprintf(&address, "%s:%d:%d:%d", - hostdev->source.subsys.u.scsi.adapter, - hostdev->source.subsys.u.scsi.bus, - hostdev->source.subsys.u.scsi.target, - hostdev->source.subsys.u.scsi.unit) < 0) { + if (virAsprintfQuiet(&address, "%s:%d:%d:%d", + hostdev->source.subsys.u.scsi.adapter, + hostdev->source.subsys.u.scsi.bus, + hostdev->source.subsys.u.scsi.target, + hostdev->source.subsys.u.scsi.unit) < 0) { VIR_WARN("OOM while encoding audit message"); goto cleanup; } @@ -654,8 +654,8 @@ virDomainAuditCgroupMajor(virDomainObjPtr vm, virCgroupPtr cgroup, { char *extra; - if (virAsprintf(&extra, "major category=%s maj=%02X acl=%s", - name, maj, perms) < 0) { + if (virAsprintfQuiet(&extra, "major category=%s maj=%02X acl=%s", + name, maj, perms) < 0) { VIR_WARN("OOM while encoding audit message"); return; } @@ -693,8 +693,8 @@ virDomainAuditCgroupPath(virDomainObjPtr vm, virCgroupPtr cgroup, rdev = virDomainAuditGetRdev(path); if (!(detail = virAuditEncode("path", path)) || - virAsprintf(&extra, "path %s rdev=%s acl=%s", - detail, VIR_AUDIT_STR(rdev), perms) < 0) { + virAsprintfQuiet(&extra, "path %s rdev=%s acl=%s", + detail, VIR_AUDIT_STR(rdev), perms) < 0) { VIR_WARN("OOM while encoding audit message"); goto cleanup; } diff --git a/src/driver.c b/src/driver.c index c35fcd2..a08dd34 100644 --- a/src/driver.c +++ b/src/driver.c @@ -65,7 +65,7 @@ virDriverLoadModule(const char *name) VIR_DEBUG("Module load %s", name); - if (virAsprintf(&modfile, "%s/libvirt_driver_%s.so", moddir, name) < 0) + if (virAsprintfQuiet(&modfile, "%s/libvirt_driver_%s.so", moddir, name) < 0) return NULL; if (access(modfile, R_OK) < 0) { @@ -79,7 +79,7 @@ virDriverLoadModule(const char *name) goto cleanup; } - if (virAsprintf(®func, "%sRegister", name) < 0) { + if (virAsprintfQuiet(®func, "%sRegister", name) < 0) { goto cleanup; } diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 6df5500..59583ec 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1871,7 +1871,7 @@ virStorageFileResize; # util/virstring.h virArgvToString; -virAsprintf; +virAsprintfInternal; virSkipSpaces; virSkipSpacesAndBackslash; virSkipSpacesBackwards; @@ -1892,7 +1892,7 @@ virStrToLong_ui; virStrToLong_ul; virStrToLong_ull; virTrimSpaces; -virVasprintf; +virVasprintfInternal; # util/virsysinfo.h diff --git a/src/util/virerror.c b/src/util/virerror.c index e238dce..ce3ab85 100644 --- a/src/util/virerror.c +++ b/src/util/virerror.c @@ -674,7 +674,7 @@ virRaiseErrorFull(const char *filename ATTRIBUTE_UNUSED, } else { va_list ap; va_start(ap, fmt); - ignore_value(virVasprintf(&str, fmt, ap)); + ignore_value(virVasprintfQuiet(&str, fmt, ap)); va_end(ap); } diff --git a/src/util/virstring.c b/src/util/virstring.c index 1937f82..6fc015b 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -321,35 +321,41 @@ virStrToDouble(char const *s, return 0; } -/** - * virVasprintf - * - * like glibc's vasprintf but makes sure *strp == NULL on failure - */ int -virVasprintf(char **strp, const char *fmt, va_list list) +virVasprintfInternal(bool report, + int domcode, + const char *filename, + const char *funcname, + size_t linenr, + char **strp, + const char *fmt, + va_list list) { int ret; - if ((ret = vasprintf(strp, fmt, list)) == -1) + if ((ret = vasprintf(strp, fmt, list)) == -1) { + if (report) + virReportOOMErrorFull(domcode, filename, funcname, linenr); *strp = NULL; - + } return ret; } -/** - * virAsprintf - * - * like glibc's_asprintf but makes sure *strp == NULL on failure - */ int -virAsprintf(char **strp, const char *fmt, ...) +virAsprintfInternal(bool report, + int domcode, + const char *filename, + const char *funcname, + size_t linenr, + char **strp, + const char *fmt, ...) { va_list ap; int ret; va_start(ap, fmt); - ret = virVasprintf(strp, fmt, ap); + ret = virVasprintfInternal(report, domcode, filename, + funcname, linenr, strp, fmt, ap); va_end(ap); return ret; } diff --git a/src/util/virstring.h b/src/util/virstring.h index 34ffae1..8b66b23 100644 --- a/src/util/virstring.h +++ b/src/util/virstring.h @@ -76,12 +76,6 @@ void virTrimSpaces(char *str, char **endp) ATTRIBUTE_NONNULL(1); void virSkipSpacesBackwards(const char *str, char **endp) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); -int virAsprintf(char **strp, const char *fmt, ...) - ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_FMT_PRINTF(2, 3) - ATTRIBUTE_RETURN_CHECK; -int virVasprintf(char **strp, const char *fmt, va_list list) - ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_FMT_PRINTF(2, 0) - ATTRIBUTE_RETURN_CHECK; char *virStrncpy(char *dest, const char *src, size_t n, size_t destbytes) ATTRIBUTE_RETURN_CHECK; char *virStrcpy(char *dest, const char *src, size_t destbytes) @@ -96,6 +90,16 @@ int virStrdup(char **dest, const char *src, bool report, int domcode, int virStrndup(char **dest, const char *src, ssize_t n, bool report, int domcode, const char *filename, const char *funcname, size_t linenr) ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NONNULL(1); +int virAsprintfInternal(bool report, int domcode, const char *filename, + const char *funcname, size_t linenr, char **strp, + const char *fmt, ...) + ATTRIBUTE_NONNULL(6) ATTRIBUTE_NONNULL(7) ATTRIBUTE_FMT_PRINTF(7, 8) + ATTRIBUTE_RETURN_CHECK; +int virVasprintfInternal(bool report, int domcode, const char *filename, + const char *funcname, size_t linenr, char **strp, + const char *fmt, va_list list) + ATTRIBUTE_NONNULL(6) ATTRIBUTE_NONNULL(7) ATTRIBUTE_FMT_PRINTF(7, 0) + ATTRIBUTE_RETURN_CHECK; /** * VIR_STRDUP: @@ -166,4 +170,55 @@ int virStrndup(char **dest, const char *src, ssize_t n, bool report, int domcode size_t virStringListLength(char **strings); +/** + * virVasprintf + * + * Like glibc's vasprintf but makes sure *strp == NULL on failure, in which + * case the OOM error is reported too. + * + * Returns -1 on failure (with OOM error reported), 0 on success. + */ +# define virVasprintf(strp, fmt, list) \ + virVasprintfInternal(true, VIR_FROM_THIS, __FILE__, __FUNCTION__, \ + __LINE__, strp, fmt, list) + +/** + * virVasprintfQuiet + * + * Like glibc's vasprintf but makes sure *strp == NULL on failure. + * + * Returns -1 on failure, 0 on success. + */ +# define virVasprintfQuiet(strp, fmt, list) \ + virVasprintfInternal(false, 0, NULL, NULL, 0, strp, fmt, list) + +/** + * virAsprintf: + * @strp: variable to hold result (char **) + * @fmt: printf format + * + * Like glibc's_asprintf but makes sure *strp == NULL on failure, in which case + * the OOM error is reported too. + * + * Returns -1 on failure (with OOM error reported), 0 on success. + */ + +# define virAsprintf(strp, ...) \ + virAsprintfInternal(true, VIR_FROM_THIS, __FILE__, __FUNCTION__, __LINE__, \ + strp, __VA_ARGS__) + +/** + * virAsprintfQuiet: + * @strp: variable to hold result (char **) + * @fmt: printf format + * + * Like glibc's_asprintf but makes sure *strp == NULL on failure. + * + * Returns -1 on failure, 0 on success. + */ + +# define virAsprintfQuiet(strp, ...) \ + virAsprintfInternal(false, 0, NULL, NULL, 0, \ + strp, __VA_ARGS__) + #endif /* __VIR_STRING_H__ */ diff --git a/tests/domainsnapshotxml2xmltest.c b/tests/domainsnapshotxml2xmltest.c index 9eddf45..defa955 100644 --- a/tests/domainsnapshotxml2xmltest.c +++ b/tests/domainsnapshotxml2xmltest.c @@ -18,6 +18,8 @@ # include "testutilsqemu.h" # include "virstring.h" +# define VIR_FROM_THIS VIR_FROM_NONE + static virQEMUDriver driver; static int diff --git a/tests/fchosttest.c b/tests/fchosttest.c index 76d1795..05ff20b 100644 --- a/tests/fchosttest.c +++ b/tests/fchosttest.c @@ -23,6 +23,8 @@ #include "virutil.h" #include "testutils.h" +#define VIR_FROM_THIS VIR_FROM_NONE + static char *fchost_prefix; #define TEST_FC_HOST_PREFIX fchost_prefix diff --git a/tests/interfacexml2xmltest.c b/tests/interfacexml2xmltest.c index 9d86198..8092a59 100644 --- a/tests/interfacexml2xmltest.c +++ b/tests/interfacexml2xmltest.c @@ -14,6 +14,8 @@ #include "testutilsqemu.h" #include "virstring.h" +#define VIR_FROM_THIS VIR_FROM_NONE + static int testCompareXMLToXMLFiles(const char *xml) { diff --git a/tests/lxcxml2xmltest.c b/tests/lxcxml2xmltest.c index 97f792c..ca05d29 100644 --- a/tests/lxcxml2xmltest.c +++ b/tests/lxcxml2xmltest.c @@ -17,6 +17,8 @@ # include "testutilslxc.h" # include "virstring.h" +# define VIR_FROM_THIS VIR_FROM_NONE + static virCapsPtr caps; static virDomainXMLOptionPtr xmlopt; diff --git a/tests/networkxml2xmltest.c b/tests/networkxml2xmltest.c index 5eca143..0dfed16 100644 --- a/tests/networkxml2xmltest.c +++ b/tests/networkxml2xmltest.c @@ -14,6 +14,8 @@ #include "testutilsqemu.h" #include "virstring.h" +#define VIR_FROM_THIS VIR_FROM_NONE + static int testCompareXMLToXMLFiles(const char *inxml, const char *outxml, unsigned int flags) diff --git a/tests/nodedevxml2xmltest.c b/tests/nodedevxml2xmltest.c index ed49857..d4f7ee7 100644 --- a/tests/nodedevxml2xmltest.c +++ b/tests/nodedevxml2xmltest.c @@ -14,6 +14,8 @@ #include "testutilsqemu.h" #include "virstring.h" +#define VIR_FROM_THIS VIR_FROM_NONE + static int testCompareXMLToXMLFiles(const char *xml) { diff --git a/tests/nodeinfotest.c b/tests/nodeinfotest.c index bce56f3..def366c 100644 --- a/tests/nodeinfotest.c +++ b/tests/nodeinfotest.c @@ -11,6 +11,8 @@ #include "virfile.h" #include "virstring.h" +#define VIR_FROM_THIS VIR_FROM_NONE + #if ! (defined __linux__ && (defined(__x86_64__) || \ defined(__amd64__) || \ defined(__i386__) || \ diff --git a/tests/nwfilterxml2xmltest.c b/tests/nwfilterxml2xmltest.c index 158bc9f..5476284 100644 --- a/tests/nwfilterxml2xmltest.c +++ b/tests/nwfilterxml2xmltest.c @@ -17,6 +17,8 @@ #include "testutilsqemu.h" #include "virstring.h" +#define VIR_FROM_THIS VIR_FROM_NONE + static int testCompareXMLToXMLFiles(const char *inxml, const char *outxml, bool expect_error) diff --git a/tests/qemuargv2xmltest.c b/tests/qemuargv2xmltest.c index 652cd09..5cf7828 100644 --- a/tests/qemuargv2xmltest.c +++ b/tests/qemuargv2xmltest.c @@ -17,6 +17,8 @@ # include "testutilsqemu.h" # include "virstring.h" +# define VIR_FROM_THIS VIR_FROM_NONE + static virQEMUDriver driver; static int blankProblemElements(char *data) diff --git a/tests/qemuhelptest.c b/tests/qemuhelptest.c index 2a3b019..3826849 100644 --- a/tests/qemuhelptest.c +++ b/tests/qemuhelptest.c @@ -11,6 +11,8 @@ # include "viralloc.h" # include "virstring.h" +# define VIR_FROM_THIS VIR_FROM_NONE + struct testInfo { const char *name; virQEMUCapsPtr flags; diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index 65e9591..50eb318 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -18,6 +18,8 @@ # include "testutilsqemu.h" # include "virstring.h" +# define VIR_FROM_THIS VIR_FROM_NONE + static virQEMUDriver driver; static int diff --git a/tests/sexpr2xmltest.c b/tests/sexpr2xmltest.c index f4d119e..eafefda 100644 --- a/tests/sexpr2xmltest.c +++ b/tests/sexpr2xmltest.c @@ -14,6 +14,8 @@ #include "testutilsxen.h" #include "virstring.h" +#define VIR_FROM_THIS VIR_FROM_NONE + static virCapsPtr caps; static int diff --git a/tests/storagepoolxml2xmltest.c b/tests/storagepoolxml2xmltest.c index 0376e63..53a7f83 100644 --- a/tests/storagepoolxml2xmltest.c +++ b/tests/storagepoolxml2xmltest.c @@ -14,6 +14,8 @@ #include "testutilsqemu.h" #include "virstring.h" +#define VIR_FROM_THIS VIR_FROM_NONE + static int testCompareXMLToXMLFiles(const char *inxml, const char *outxml) { diff --git a/tests/storagevolxml2argvtest.c b/tests/storagevolxml2argvtest.c index 6a6c8e3..89c233f 100644 --- a/tests/storagevolxml2argvtest.c +++ b/tests/storagevolxml2argvtest.c @@ -7,6 +7,8 @@ #include "testutilsqemu.h" #include "virstring.h" +#define VIR_FROM_THIS VIR_FROM_NONE + const char create_tool[] = "qemu-img"; static int diff --git a/tests/storagevolxml2xmltest.c b/tests/storagevolxml2xmltest.c index e87b016..05d2306 100644 --- a/tests/storagevolxml2xmltest.c +++ b/tests/storagevolxml2xmltest.c @@ -14,6 +14,8 @@ #include "testutilsqemu.h" #include "virstring.h" +#define VIR_FROM_THIS VIR_FROM_NONE + static int testCompareXMLToXMLFiles(const char *poolxml, const char *inxml, const char *outxml) diff --git a/tests/sysinfotest.c b/tests/sysinfotest.c index dc0451b..ba57a7a 100644 --- a/tests/sysinfotest.c +++ b/tests/sysinfotest.c @@ -36,6 +36,8 @@ #include "virfile.h" #include "virstring.h" +#define VIR_FROM_THIS VIR_FROM_NONE + #if defined (__linux__) # if defined(__s390__) || defined(__s390x__) || \ diff --git a/tests/virbuftest.c b/tests/virbuftest.c index 3938f0d..febe6e4 100644 --- a/tests/virbuftest.c +++ b/tests/virbuftest.c @@ -10,6 +10,8 @@ #include "viralloc.h" #include "virstring.h" +#define VIR_FROM_THIS VIR_FROM_NONE + #define TEST_ERROR(...) \ do { \ if (virTestGetDebug()) \ diff --git a/tests/virhashtest.c b/tests/virhashtest.c index f36fc76..9b7fcbb 100644 --- a/tests/virhashtest.c +++ b/tests/virhashtest.c @@ -13,6 +13,8 @@ #include "virlog.h" #include "virstring.h" +#define VIR_FROM_THIS VIR_FROM_NONE + #define testError(...) \ do { \ char *str; \ diff --git a/tests/virshtest.c b/tests/virshtest.c index fad6774..ca35bb0 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -9,6 +9,8 @@ #include "testutils.h" #include "virstring.h" +#define VIR_FROM_THIS VIR_FROM_NONE + #ifdef WIN32 int diff --git a/tests/xencapstest.c b/tests/xencapstest.c index 8bdd6cd..9de3919 100644 --- a/tests/xencapstest.c +++ b/tests/xencapstest.c @@ -12,6 +12,8 @@ #include "virfile.h" #include "virstring.h" +#define VIR_FROM_THIS VIR_FROM_NONE + static int testCompareFiles(virArch hostmachine, const char *xml_rel, const char *cpuinfo_rel, const char *capabilities_rel) diff --git a/tests/xml2sexprtest.c b/tests/xml2sexprtest.c index ec196c4..87ac2c3 100644 --- a/tests/xml2sexprtest.c +++ b/tests/xml2sexprtest.c @@ -16,6 +16,8 @@ #include "testutilsxen.h" #include "virstring.h" +#define VIR_FROM_THIS VIR_FROM_NONE + static virCapsPtr caps; static virDomainXMLOptionPtr xmlopt; diff --git a/tools/virt-host-validate-common.c b/tools/virt-host-validate-common.c index c17c257..496324e 100644 --- a/tools/virt-host-validate-common.c +++ b/tools/virt-host-validate-common.c @@ -33,6 +33,8 @@ #include "virt-host-validate-common.h" #include "virstring.h" +#define VIR_FROM_THIS VIR_FROM_NONE + static bool quiet; void virHostMsgSetQuiet(bool quietFlag) -- 1.8.1.5

On 07/04/13 14:06, Michal Privoznik wrote:
Actually, I'm turning this function into a macro as filename, function name and line number needs to be passed. The new function virAsprintfInternal is introduced with the extended set of arguments. --- cfg.mk | 2 +- src/conf/domain_audit.c | 36 ++++++++++----------- src/driver.c | 4 +-- src/libvirt_private.syms | 4 +-- src/util/virerror.c | 2 +- src/util/virstring.c | 36 ++++++++++++--------- src/util/virstring.h | 67 +++++++++++++++++++++++++++++++++++---- tests/domainsnapshotxml2xmltest.c | 2 ++ tests/fchosttest.c | 2 ++ tests/interfacexml2xmltest.c | 2 ++ tests/lxcxml2xmltest.c | 2 ++ tests/networkxml2xmltest.c | 2 ++ tests/nodedevxml2xmltest.c | 2 ++ tests/nodeinfotest.c | 2 ++ tests/nwfilterxml2xmltest.c | 2 ++ tests/qemuargv2xmltest.c | 2 ++ tests/qemuhelptest.c | 2 ++ tests/qemuxml2xmltest.c | 2 ++ tests/sexpr2xmltest.c | 2 ++ tests/storagepoolxml2xmltest.c | 2 ++ tests/storagevolxml2argvtest.c | 2 ++ tests/storagevolxml2xmltest.c | 2 ++ tests/sysinfotest.c | 2 ++ tests/virbuftest.c | 2 ++ tests/virhashtest.c | 2 ++ tests/virshtest.c | 2 ++ tests/xencapstest.c | 2 ++ tests/xml2sexprtest.c | 2 ++ tools/virt-host-validate-common.c | 2 ++ 29 files changed, 150 insertions(+), 45 deletions(-)
Again, there are a few places (at least in src/virlog.c) that will need fixing before this patch will be ready. The bulk rest of the patch looks okay but without fixing the logging code, we might run into nasty recursions on OOM. As most of the code needs to be evaluated manually anyways, I'd change all calls to virAsprintf using a script to something like "virAsprintfUnhandled" with the original functionality along with introducing the new macros and then changing everything back according to the semantics of the code. The problem is that this approach would require lots of changes :(. Anyways, I'm okay with reviewing this again, but we need to be careful about those few places where reporting an error could hurt. If anybody has some suggestions about other places than src/util/virerror.c and src/util/virlog.c that certainly need special care, please respond so we don't break stuff. Peter

--- HACKING | 20 +++++--------------- docs/hacking.html.in | 20 +++++--------------- 2 files changed, 10 insertions(+), 30 deletions(-) diff --git a/HACKING b/HACKING index a310faa..26dc0d0 100644 --- a/HACKING +++ b/HACKING @@ -535,10 +535,8 @@ routines, use the macros from viralloc.h. virDomainPtr domain; - if (VIR_ALLOC(domain) < 0) { - virReportOOMError(); + if (VIR_ALLOC(domain) < 0) return NULL; - } @@ -547,10 +545,8 @@ routines, use the macros from viralloc.h. virDomainPtr domains; size_t ndomains = 10; - if (VIR_ALLOC_N(domains, ndomains) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(domains, ndomains) < 0) return NULL; - } @@ -559,10 +555,8 @@ routines, use the macros from viralloc.h. virDomainPtr *domains; size_t ndomains = 10; - if (VIR_ALLOC_N(domains, ndomains) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(domains, ndomains) < 0) return NULL; - } @@ -573,10 +567,8 @@ recommended only for smaller arrays): virDomainPtr domains; size_t ndomains = 0; - if (VIR_EXPAND_N(domains, ndomains, 1) < 0) { - virReportOOMError(); + if (VIR_EXPAND_N(domains, ndomains, 1) < 0) return NULL; - } domains[ndomains - 1] = domain; @@ -588,10 +580,8 @@ scales better, but requires tracking allocation separately from usage) size_t ndomains = 0; size_t ndomains_max = 0; - if (VIR_RESIZE_N(domains, ndomains_max, ndomains, 1) < 0) { - virReportOOMError(); + if (VIR_RESIZE_N(domains, ndomains_max, ndomains, 1) < 0) return NULL; - } domains[ndomains++] = domain; diff --git a/docs/hacking.html.in b/docs/hacking.html.in index 904b846..b266533 100644 --- a/docs/hacking.html.in +++ b/docs/hacking.html.in @@ -661,10 +661,8 @@ <pre> virDomainPtr domain; - if (VIR_ALLOC(domain) < 0) { - virReportOOMError(); + if (VIR_ALLOC(domain) < 0) return NULL; - } </pre> </li> @@ -673,10 +671,8 @@ virDomainPtr domains; size_t ndomains = 10; - if (VIR_ALLOC_N(domains, ndomains) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(domains, ndomains) < 0) return NULL; - } </pre> </li> @@ -685,10 +681,8 @@ virDomainPtr *domains; size_t ndomains = 10; - if (VIR_ALLOC_N(domains, ndomains) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(domains, ndomains) < 0) return NULL; - } </pre> </li> @@ -700,10 +694,8 @@ virDomainPtr domains; size_t ndomains = 0; - if (VIR_EXPAND_N(domains, ndomains, 1) < 0) { - virReportOOMError(); + if (VIR_EXPAND_N(domains, ndomains, 1) < 0) return NULL; - } domains[ndomains - 1] = domain; </pre></li> @@ -716,10 +708,8 @@ size_t ndomains = 0; size_t ndomains_max = 0; - if (VIR_RESIZE_N(domains, ndomains_max, ndomains, 1) < 0) { - virReportOOMError(); + if (VIR_RESIZE_N(domains, ndomains_max, ndomains, 1) < 0) return NULL; - } domains[ndomains++] = domain; </pre> </li> -- 1.8.1.5

--- daemon/libvirtd-config.c | 12 +-- daemon/libvirtd.c | 24 ++--- daemon/remote.c | 234 ++++++++++++----------------------------------- daemon/stream.c | 4 +- 4 files changed, 70 insertions(+), 204 deletions(-) diff --git a/daemon/libvirtd-config.c b/daemon/libvirtd-config.c index 017d470..a3cc56f 100644 --- a/daemon/libvirtd-config.c +++ b/daemon/libvirtd-config.c @@ -200,15 +200,13 @@ daemonConfigFilePath(bool privileged, char **configfile) if (virAsprintf(configfile, "%s/libvirtd.conf", configdir) < 0) { VIR_FREE(configdir); - goto no_memory; + goto error; } VIR_FREE(configdir); } return 0; -no_memory: - virReportOOMError(); error: return -1; } @@ -220,10 +218,8 @@ daemonConfigNew(bool privileged ATTRIBUTE_UNUSED) char *localhost; int ret; - if (VIR_ALLOC(data) < 0) { - virReportOOMError(); + if (VIR_ALLOC(data) < 0) return NULL; - } data->listen_tls = 1; data->listen_tcp = 0; @@ -294,12 +290,10 @@ daemonConfigNew(bool privileged ATTRIBUTE_UNUSED) } VIR_FREE(localhost); if (ret < 0) - goto no_memory; + goto error; return data; -no_memory: - virReportOOMError(); error: daemonConfigFree(data); return NULL; diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c index 3db4f1c..9f7fd8a 100644 --- a/daemon/libvirtd.c +++ b/daemon/libvirtd.c @@ -263,7 +263,7 @@ daemonPidFilePath(bool privileged, if (virAsprintf(pidfile, "%s/libvirtd.pid", rundir) < 0) { VIR_FREE(rundir); - goto no_memory; + goto error; } VIR_FREE(rundir); @@ -271,8 +271,6 @@ daemonPidFilePath(bool privileged, return 0; -no_memory: - virReportOOMError(); error: return -1; } @@ -285,10 +283,10 @@ daemonUnixSocketPaths(struct daemonConfig *config, { if (config->unix_sock_dir) { if (virAsprintf(sockfile, "%s/libvirt-sock", config->unix_sock_dir) < 0) - goto no_memory; + goto error; if (privileged && virAsprintf(rosockfile, "%s/libvirt-sock-ro", config->unix_sock_dir) < 0) - goto no_memory; + goto error; } else { if (privileged) { if (VIR_STRDUP(*sockfile, LOCALSTATEDIR "/run/libvirt/libvirt-sock") < 0 || @@ -310,7 +308,7 @@ daemonUnixSocketPaths(struct daemonConfig *config, if (virAsprintf(sockfile, "%s/libvirt-sock", rundir) < 0) { VIR_FREE(rundir); - goto no_memory; + goto error; } VIR_FREE(rundir); @@ -318,8 +316,6 @@ daemonUnixSocketPaths(struct daemonConfig *config, } return 0; -no_memory: - virReportOOMError(); error: return -1; } @@ -666,7 +662,7 @@ daemonSetupLogging(struct daemonConfig *config, char *tmp; if (access("/run/systemd/journal/socket", W_OK) >= 0) { if (virAsprintf(&tmp, "%d:journald", virLogGetDefaultPriority()) < 0) - goto no_memory; + goto error; virLogParseOutputs(tmp); VIR_FREE(tmp); } @@ -684,7 +680,7 @@ daemonSetupLogging(struct daemonConfig *config, if (virAsprintf(&tmp, "%d:file:%s/log/libvirt/libvirtd.log", virLogGetDefaultPriority(), LOCALSTATEDIR) == -1) - goto no_memory; + goto error; } else { char *logdir = virGetUserCacheDirectory(); mode_t old_umask; @@ -702,13 +698,13 @@ daemonSetupLogging(struct daemonConfig *config, if (virAsprintf(&tmp, "%d:file:%s/libvirtd.log", virLogGetDefaultPriority(), logdir) == -1) { VIR_FREE(logdir); - goto no_memory; + goto error; } VIR_FREE(logdir); } } else { if (virAsprintf(&tmp, "%d:stderr", virLogGetDefaultPriority()) < 0) - goto no_memory; + goto error; } virLogParseOutputs(tmp); VIR_FREE(tmp); @@ -722,8 +718,6 @@ daemonSetupLogging(struct daemonConfig *config, return 0; -no_memory: - virReportOOMError(); error: return -1; } @@ -1153,7 +1147,7 @@ int main(int argc, char **argv) { } *tmp = '\0'; char *driverdir; - if (virAsprintf(&driverdir, "%s/../../src/.libs", argv[0]) < 0) { + if (virAsprintfQuiet(&driverdir, "%s/../../src/.libs", argv[0]) < 0) { fprintf(stderr, _("%s: initialization failed\n"), argv[0]); exit(EXIT_FAILURE); } diff --git a/daemon/remote.c b/daemon/remote.c index cb362da..a465d4e 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -332,10 +332,8 @@ static int remoteRelayDomainEventGraphics(virConnectPtr conn ATTRIBUTE_UNUSED, goto error; data.subject.subject_len = subject->nidentity; - if (VIR_ALLOC_N(data.subject.subject_val, data.subject.subject_len) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(data.subject.subject_val, data.subject.subject_len) < 0) goto error; - } for (i = 0; i < data.subject.subject_len; i++) { if (VIR_STRDUP(data.subject.subject_val[i].type, subject->identities[i].type) < 0 || @@ -448,12 +446,12 @@ static int remoteRelayDomainEventDiskChange(virConnectPtr conn ATTRIBUTE_UNUSED, if (oldSrcPath && ((VIR_ALLOC(oldSrcPath_p) < 0) || VIR_STRDUP(*oldSrcPath_p, oldSrcPath) < 0)) - goto mem_error; + goto error; if (newSrcPath && ((VIR_ALLOC(newSrcPath_p) < 0) || VIR_STRDUP(*newSrcPath_p, newSrcPath) < 0)) - goto mem_error; + goto error; data.oldSrcPath = oldSrcPath_p; data.newSrcPath = newSrcPath_p; @@ -469,8 +467,6 @@ static int remoteRelayDomainEventDiskChange(virConnectPtr conn ATTRIBUTE_UNUSED, return 0; -mem_error: - virReportOOMError(); error: VIR_FREE(oldSrcPath_p); VIR_FREE(newSrcPath_p); @@ -670,14 +666,12 @@ void *remoteClientInitHook(virNetServerClientPtr client, struct daemonClientPrivate *priv; int i; - if (VIR_ALLOC(priv) < 0) { - virReportOOMError(); + if (VIR_ALLOC(priv) < 0) return NULL; - } if (virMutexInit(&priv->lock) < 0) { VIR_FREE(priv); - virReportOOMError(); + virReportSystemError(errno, "%s", _("unable to init mutex")); return NULL; } @@ -807,10 +801,8 @@ remoteSerializeTypedParameters(virTypedParameterPtr params, remote_typed_param *val; *ret_params_len = nparams; - if (VIR_ALLOC_N(val, nparams) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(val, nparams) < 0) goto cleanup; - } for (i = 0, j = 0; i < nparams; ++i) { /* virDomainGetCPUStats can return a sparse array; also, we @@ -889,10 +881,8 @@ remoteDeserializeTypedParameters(remote_typed_param *args_params_val, virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too large")); goto cleanup; } - if (VIR_ALLOC_N(params, args_params_len) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(params, args_params_len) < 0) goto cleanup; - } *nparams = args_params_len; @@ -978,7 +968,7 @@ remoteDispatchDomainGetSchedulerParameters(virNetServerPtr server ATTRIBUTE_UNUS goto cleanup; } if (args->nparams && VIR_ALLOC_N(params, args->nparams) < 0) - goto no_memory; + goto cleanup; nparams = args->nparams; if (!(dom = get_nonnull_domain(priv->conn, args->dom))) @@ -1002,10 +992,6 @@ cleanup: if (dom) virDomainFree(dom); return rv; - -no_memory: - virReportOOMError(); - goto cleanup; } static int @@ -1033,10 +1019,8 @@ remoteDispatchConnectListAllDomains(virNetServerPtr server ATTRIBUTE_UNUSED, goto cleanup; if (doms && ndomains) { - if (VIR_ALLOC_N(ret->domains.domains_val, ndomains) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(ret->domains.domains_val, ndomains) < 0) goto cleanup; - } ret->domains.domains_len = ndomains; @@ -1087,7 +1071,7 @@ remoteDispatchDomainGetSchedulerParametersFlags(virNetServerPtr server ATTRIBUTE goto cleanup; } if (args->nparams && VIR_ALLOC_N(params, args->nparams) < 0) - goto no_memory; + goto cleanup; nparams = args->nparams; if (!(dom = get_nonnull_domain(priv->conn, args->dom))) @@ -1112,10 +1096,6 @@ cleanup: if (dom) virDomainFree(dom); return rv; - -no_memory: - virReportOOMError(); - goto cleanup; } static int @@ -1148,20 +1128,16 @@ remoteDispatchDomainMemoryStats(virNetServerPtr server ATTRIBUTE_UNUSED, goto cleanup; /* Allocate stats array for making dispatch call */ - if (VIR_ALLOC_N(stats, args->maxStats) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(stats, args->maxStats) < 0) goto cleanup; - } nr_stats = virDomainMemoryStats(dom, stats, args->maxStats, args->flags); if (nr_stats < 0) goto cleanup; /* Allocate return buffer */ - if (VIR_ALLOC_N(ret->stats.stats_val, args->maxStats) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(ret->stats.stats_val, args->maxStats) < 0) goto cleanup; - } /* Copy the stats into the xdr return structure */ for (i = 0; i < nr_stats; i++) { @@ -1216,10 +1192,8 @@ remoteDispatchDomainBlockPeek(virNetServerPtr server ATTRIBUTE_UNUSED, } ret->buffer.buffer_len = size; - if (VIR_ALLOC_N(ret->buffer.buffer_val, size) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(ret->buffer.buffer_val, size) < 0) goto cleanup; - } if (virDomainBlockPeek(dom, path, offset, size, ret->buffer.buffer_val, flags) < 0) @@ -1267,10 +1241,8 @@ remoteDispatchDomainBlockStatsFlags(virNetServerPtr server ATTRIBUTE_UNUSED, virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too large")); goto cleanup; } - if (args->nparams && VIR_ALLOC_N(params, args->nparams) < 0) { - virReportOOMError(); + if (args->nparams && VIR_ALLOC_N(params, args->nparams) < 0) goto cleanup; - } nparams = args->nparams; if (virDomainBlockStatsFlags(dom, path, params, &nparams, flags) < 0) @@ -1337,10 +1309,8 @@ remoteDispatchDomainMemoryPeek(virNetServerPtr server ATTRIBUTE_UNUSED, } ret->buffer.buffer_len = size; - if (VIR_ALLOC_N(ret->buffer.buffer_val, size) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(ret->buffer.buffer_val, size) < 0) goto cleanup; - } if (virDomainMemoryPeek(dom, offset, size, ret->buffer.buffer_val, flags) < 0) @@ -1380,19 +1350,15 @@ remoteDispatchDomainGetSecurityLabel(virNetServerPtr server ATTRIBUTE_UNUSED, if (!(dom = get_nonnull_domain(priv->conn, args->dom))) goto cleanup; - if (VIR_ALLOC(seclabel) < 0) { - virReportOOMError(); + if (VIR_ALLOC(seclabel) < 0) goto cleanup; - } if (virDomainGetSecurityLabel(dom, seclabel) < 0) goto cleanup; ret->label.label_len = strlen(seclabel->label) + 1; - if (VIR_ALLOC_N(ret->label.label_val, ret->label.label_len) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(ret->label.label_val, ret->label.label_len) < 0) goto cleanup; - } strcpy(ret->label.label_val, seclabel->label); ret->enforcing = seclabel->enforcing; @@ -1436,18 +1402,14 @@ remoteDispatchDomainGetSecurityLabelList(virNetServerPtr server ATTRIBUTE_UNUSED goto done; } - if (VIR_ALLOC_N(ret->labels.labels_val, len) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(ret->labels.labels_val, len) < 0) goto cleanup; - } for (i = 0; i < len; i++) { size_t label_len = strlen(seclabels[i].label) + 1; remote_domain_get_security_label_ret *cur = &ret->labels.labels_val[i]; - if (VIR_ALLOC_N(cur->label.label_val, label_len) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(cur->label.label_val, label_len) < 0) goto cleanup; - } if (virStrcpy(cur->label.label_val, seclabels[i].label, label_len) == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("failed to copy security label")); @@ -1492,17 +1454,13 @@ remoteDispatchNodeGetSecurityModel(virNetServerPtr server ATTRIBUTE_UNUSED, goto cleanup; ret->model.model_len = strlen(secmodel.model) + 1; - if (VIR_ALLOC_N(ret->model.model_val, ret->model.model_len) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(ret->model.model_val, ret->model.model_len) < 0) goto cleanup; - } strcpy(ret->model.model_val, secmodel.model); ret->doi.doi_len = strlen(secmodel.doi) + 1; - if (VIR_ALLOC_N(ret->doi.doi_val, ret->doi.doi_len) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(ret->doi.doi_val, ret->doi.doi_len) < 0) goto cleanup; - } strcpy(ret->doi.doi_val, secmodel.doi); rv = 0; @@ -1550,7 +1508,7 @@ remoteDispatchDomainGetVcpuPinInfo(virNetServerPtr server ATTRIBUTE_UNUSED, /* Allocate buffers to take the results. */ if (args->maplen > 0 && VIR_ALLOC_N(cpumaps, args->ncpumaps * args->maplen) < 0) - goto no_memory; + goto cleanup; if ((num = virDomainGetVcpuPinInfo(dom, args->ncpumaps, @@ -1577,10 +1535,6 @@ cleanup: if (dom) virDomainFree(dom); return rv; - -no_memory: - virReportOOMError(); - goto cleanup; } static int @@ -1646,7 +1600,7 @@ remoteDispatchDomainGetEmulatorPinInfo(virNetServerPtr server ATTRIBUTE_UNUSED, /* Allocate buffers to take the results */ if (args->maplen > 0 && VIR_ALLOC_N(cpumaps, args->maplen) < 0) - goto no_memory; + goto cleanup; if ((r = virDomainGetEmulatorPinInfo(dom, cpumaps, @@ -1668,10 +1622,6 @@ cleanup: if (dom) virDomainFree(dom); return rv; - -no_memory: - virReportOOMError(); - goto cleanup; } static int @@ -1711,10 +1661,10 @@ remoteDispatchDomainGetVcpus(virNetServerPtr server ATTRIBUTE_UNUSED, /* Allocate buffers to take the results. */ if (VIR_ALLOC_N(info, args->maxinfo) < 0) - goto no_memory; + goto cleanup; if (args->maplen > 0 && VIR_ALLOC_N(cpumaps, args->maxinfo * args->maplen) < 0) - goto no_memory; + goto cleanup; if ((info_len = virDomainGetVcpus(dom, info, args->maxinfo, @@ -1724,7 +1674,7 @@ remoteDispatchDomainGetVcpus(virNetServerPtr server ATTRIBUTE_UNUSED, /* Allocate the return buffer for info. */ ret->info.info_len = info_len; if (VIR_ALLOC_N(ret->info.info_val, info_len) < 0) - goto no_memory; + goto cleanup; for (i = 0; i < info_len; ++i) { ret->info.info_val[i].number = info[i].number; @@ -1753,10 +1703,6 @@ cleanup: if (dom) virDomainFree(dom); return rv; - -no_memory: - virReportOOMError(); - goto cleanup; } static int @@ -1785,10 +1731,8 @@ remoteDispatchDomainMigratePrepare(virNetServerPtr server ATTRIBUTE_UNUSED, dname = args->dname == NULL ? NULL : *args->dname; /* Wacky world of XDR ... */ - if (VIR_ALLOC(uri_out) < 0) { - virReportOOMError(); + if (VIR_ALLOC(uri_out) < 0) goto cleanup; - } if (virDomainMigratePrepare(priv->conn, &cookie, &cookielen, uri_in, uri_out, @@ -1842,10 +1786,8 @@ remoteDispatchDomainMigratePrepare2(virNetServerPtr server ATTRIBUTE_UNUSED, dname = args->dname == NULL ? NULL : *args->dname; /* Wacky world of XDR ... */ - if (VIR_ALLOC(uri_out) < 0) { - virReportOOMError(); + if (VIR_ALLOC(uri_out) < 0) goto cleanup; - } if (virDomainMigratePrepare2(priv->conn, &cookie, &cookielen, uri_in, uri_out, @@ -1895,10 +1837,8 @@ remoteDispatchDomainGetMemoryParameters(virNetServerPtr server ATTRIBUTE_UNUSED, virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too large")); goto cleanup; } - if (args->nparams && VIR_ALLOC_N(params, args->nparams) < 0) { - virReportOOMError(); + if (args->nparams && VIR_ALLOC_N(params, args->nparams) < 0) goto cleanup; - } nparams = args->nparams; if (!(dom = get_nonnull_domain(priv->conn, args->dom))) @@ -1960,10 +1900,8 @@ remoteDispatchDomainGetNumaParameters(virNetServerPtr server ATTRIBUTE_UNUSED, virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too large")); goto cleanup; } - if (args->nparams && VIR_ALLOC_N(params, args->nparams) < 0) { - virReportOOMError(); + if (args->nparams && VIR_ALLOC_N(params, args->nparams) < 0) goto cleanup; - } nparams = args->nparams; if (!(dom = get_nonnull_domain(priv->conn, args->dom))) @@ -2025,10 +1963,8 @@ remoteDispatchDomainGetBlkioParameters(virNetServerPtr server ATTRIBUTE_UNUSED, virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too large")); goto cleanup; } - if (args->nparams && VIR_ALLOC_N(params, args->nparams) < 0) { - virReportOOMError(); + if (args->nparams && VIR_ALLOC_N(params, args->nparams) < 0) goto cleanup; - } nparams = args->nparams; if (!(dom = get_nonnull_domain(priv->conn, args->dom))) @@ -2091,10 +2027,8 @@ remoteDispatchNodeGetCPUStats(virNetServerPtr server ATTRIBUTE_UNUSED, virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too large")); goto cleanup; } - if (args->nparams && VIR_ALLOC_N(params, args->nparams) < 0) { - virReportOOMError(); + if (args->nparams && VIR_ALLOC_N(params, args->nparams) < 0) goto cleanup; - } nparams = args->nparams; if (virNodeGetCPUStats(priv->conn, cpuNum, params, &nparams, flags) < 0) @@ -2111,7 +2045,7 @@ remoteDispatchNodeGetCPUStats(virNetServerPtr server ATTRIBUTE_UNUSED, /* Serialise the memory parameters. */ ret->params.params_len = nparams; if (VIR_ALLOC_N(ret->params.params_val, nparams) < 0) - goto no_memory; + goto cleanup; for (i = 0; i < nparams; ++i) { /* remoteDispatchClientRequest will free this: */ @@ -2135,10 +2069,6 @@ cleanup: } VIR_FREE(params); return rv; - -no_memory: - virReportOOMError(); - goto cleanup; } static int @@ -2169,10 +2099,8 @@ remoteDispatchNodeGetMemoryStats(virNetServerPtr server ATTRIBUTE_UNUSED, virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too large")); goto cleanup; } - if (args->nparams && VIR_ALLOC_N(params, args->nparams) < 0) { - virReportOOMError(); + if (args->nparams && VIR_ALLOC_N(params, args->nparams) < 0) goto cleanup; - } nparams = args->nparams; if (virNodeGetMemoryStats(priv->conn, cellNum, params, &nparams, flags) < 0) @@ -2189,7 +2117,7 @@ remoteDispatchNodeGetMemoryStats(virNetServerPtr server ATTRIBUTE_UNUSED, /* Serialise the memory parameters. */ ret->params.params_len = nparams; if (VIR_ALLOC_N(ret->params.params_val, nparams) < 0) - goto no_memory; + goto cleanup; for (i = 0; i < nparams; ++i) { /* remoteDispatchClientRequest will free this: */ @@ -2213,10 +2141,6 @@ cleanup: } VIR_FREE(params); return rv; - -no_memory: - virReportOOMError(); - goto cleanup; } static int @@ -2285,10 +2209,8 @@ remoteDispatchDomainGetBlockIoTune(virNetServerPtr server ATTRIBUTE_UNUSED, goto cleanup; } - if (args->nparams && VIR_ALLOC_N(params, args->nparams) < 0) { - virReportOOMError(); + if (args->nparams && VIR_ALLOC_N(params, args->nparams) < 0) goto cleanup; - } nparams = args->nparams; if (!(dom = get_nonnull_domain(priv->conn, args->dom))) @@ -2354,10 +2276,8 @@ remoteDispatchAuthList(virNetServerPtr server ATTRIBUTE_UNUSED, } else if (callerUid == 0) { char *ident; if (virAsprintf(&ident, "pid:%lld,uid:%d", - (long long) callerPid, (int) callerUid) < 0) { - virReportOOMError(); + (long long) callerPid, (int) callerUid) < 0) goto cleanup; - } VIR_INFO("Bypass polkit auth for privileged client %s", ident); virNetServerClientSetAuth(client, 0); auth = VIR_NET_SERVER_SERVICE_AUTH_NONE; @@ -2366,10 +2286,8 @@ remoteDispatchAuthList(virNetServerPtr server ATTRIBUTE_UNUSED, } ret->types.types_len = 1; - if (VIR_ALLOC_N(ret->types.types_val, ret->types.types_len) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(ret->types.types_val, ret->types.types_len) < 0) goto cleanup; - } switch (auth) { case VIR_NET_SERVER_SERVICE_AUTH_NONE: @@ -2815,10 +2733,8 @@ remoteDispatchAuthPolkit(virNetServerPtr server ATTRIBUTE_UNUSED, virCommandAddArg(cmd, "--allow-user-interaction"); if (virAsprintf(&ident, "pid:%lld,uid:%d", - (long long) callerPid, callerUid) < 0) { - virReportOOMError(); + (long long) callerPid, callerUid) < 0) goto authfail; - } if (virCommandRun(cmd, &status) < 0) goto authfail; @@ -2920,10 +2836,8 @@ remoteDispatchAuthPolkit(virNetServerPtr server ATTRIBUTE_UNUSED, } if (virAsprintf(&ident, "pid:%lld,uid:%d", - (long long) callerPid, callerUid) < 0) { - virReportOOMError(); + (long long) callerPid, callerUid) < 0) goto authfail; - } if (!(sysbus = virDBusGetSystemBus())) goto authfail; @@ -3073,10 +2987,8 @@ remoteDispatchNodeDeviceGetParent(virNetServerPtr server ATTRIBUTE_UNUSED, } else { /* remoteDispatchClientRequest will free this. */ char **parent_p; - if (VIR_ALLOC(parent_p) < 0) { - virReportOOMError(); + if (VIR_ALLOC(parent_p) < 0) goto cleanup; - } if (VIR_STRDUP(*parent_p, parent) < 0) { VIR_FREE(parent_p); goto cleanup; @@ -3495,10 +3407,8 @@ remoteDispatchDomainMigratePrepare3(virNetServerPtr server ATTRIBUTE_UNUSED, dname = args->dname == NULL ? NULL : *args->dname; /* Wacky world of XDR ... */ - if (VIR_ALLOC(uri_out) < 0) { - virReportOOMError(); + if (VIR_ALLOC(uri_out) < 0) goto cleanup; - } if (virDomainMigratePrepare3(priv->conn, args->cookie_in.cookie_in_val, @@ -3792,10 +3702,8 @@ remoteDispatchDomainGetInterfaceParameters(virNetServerPtr server ATTRIBUTE_UNUS virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too large")); goto cleanup; } - if (args->nparams && VIR_ALLOC_N(params, args->nparams) < 0) { - virReportOOMError(); + if (args->nparams && VIR_ALLOC_N(params, args->nparams) < 0) goto cleanup; - } nparams = args->nparams; if (!(dom = get_nonnull_domain(priv->conn, args->dom))) @@ -3860,10 +3768,8 @@ remoteDispatchDomainGetCPUStats(virNetServerPtr server ATTRIBUTE_UNUSED, } if (args->nparams > 0 && - VIR_ALLOC_N(params, args->ncpus * args->nparams) < 0) { - virReportOOMError(); + VIR_ALLOC_N(params, args->ncpus * args->nparams) < 0) goto cleanup; - } if (!(dom = get_nonnull_domain(priv->conn, args->dom))) goto cleanup; @@ -3934,10 +3840,8 @@ static int remoteDispatchDomainGetDiskErrors( } if (args->maxerrors && - VIR_ALLOC_N(errors, args->maxerrors) < 0) { - virReportOOMError(); + VIR_ALLOC_N(errors, args->maxerrors) < 0) goto cleanup; - } if ((len = virDomainGetDiskErrors(dom, errors, args->maxerrors, @@ -3996,10 +3900,8 @@ remoteDispatchDomainListAllSnapshots(virNetServerPtr server ATTRIBUTE_UNUSED, goto cleanup; if (snaps && nsnaps) { - if (VIR_ALLOC_N(ret->snapshots.snapshots_val, nsnaps) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(ret->snapshots.snapshots_val, nsnaps) < 0) goto cleanup; - } ret->snapshots.snapshots_len = nsnaps; @@ -4060,10 +3962,8 @@ remoteDispatchDomainSnapshotListAllChildren(virNetServerPtr server ATTRIBUTE_UNU goto cleanup; if (snaps && nsnaps) { - if (VIR_ALLOC_N(ret->snapshots.snapshots_val, nsnaps) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(ret->snapshots.snapshots_val, nsnaps) < 0) goto cleanup; - } ret->snapshots.snapshots_len = nsnaps; @@ -4118,10 +4018,8 @@ remoteDispatchConnectListAllStoragePools(virNetServerPtr server ATTRIBUTE_UNUSED goto cleanup; if (pools && npools) { - if (VIR_ALLOC_N(ret->pools.pools_val, npools) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(ret->pools.pools_val, npools) < 0) goto cleanup; - } ret->pools.pools_len = npools; @@ -4176,10 +4074,8 @@ remoteDispatchStoragePoolListAllVolumes(virNetServerPtr server ATTRIBUTE_UNUSED, goto cleanup; if (vols && nvols) { - if (VIR_ALLOC_N(ret->vols.vols_val, nvols) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(ret->vols.vols_val, nvols) < 0) goto cleanup; - } ret->vols.vols_len = nvols; @@ -4232,10 +4128,8 @@ remoteDispatchConnectListAllNetworks(virNetServerPtr server ATTRIBUTE_UNUSED, goto cleanup; if (nets && nnets) { - if (VIR_ALLOC_N(ret->nets.nets_val, nnets) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(ret->nets.nets_val, nnets) < 0) goto cleanup; - } ret->nets.nets_len = nnets; @@ -4286,10 +4180,8 @@ remoteDispatchConnectListAllInterfaces(virNetServerPtr server ATTRIBUTE_UNUSED, goto cleanup; if (ifaces && nifaces) { - if (VIR_ALLOC_N(ret->ifaces.ifaces_val, nifaces) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(ret->ifaces.ifaces_val, nifaces) < 0) goto cleanup; - } ret->ifaces.ifaces_len = nifaces; @@ -4340,10 +4232,8 @@ remoteDispatchConnectListAllNodeDevices(virNetServerPtr server ATTRIBUTE_UNUSED, goto cleanup; if (devices && ndevices) { - if (VIR_ALLOC_N(ret->devices.devices_val, ndevices) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(ret->devices.devices_val, ndevices) < 0) goto cleanup; - } ret->devices.devices_len = ndevices; @@ -4394,10 +4284,8 @@ remoteDispatchConnectListAllNWFilters(virNetServerPtr server ATTRIBUTE_UNUSED, goto cleanup; if (filters && nfilters) { - if (VIR_ALLOC_N(ret->filters.filters_val, nfilters) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(ret->filters.filters_val, nfilters) < 0) goto cleanup; - } ret->filters.filters_len = nfilters; @@ -4448,10 +4336,8 @@ remoteDispatchConnectListAllSecrets(virNetServerPtr server ATTRIBUTE_UNUSED, goto cleanup; if (secrets && nsecrets) { - if (VIR_ALLOC_N(ret->secrets.secrets_val, nsecrets) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(ret->secrets.secrets_val, nsecrets) < 0) goto cleanup; - } ret->secrets.secrets_len = nsecrets; @@ -4503,10 +4389,8 @@ remoteDispatchNodeGetMemoryParameters(virNetServerPtr server ATTRIBUTE_UNUSED, virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too large")); goto cleanup; } - if (args->nparams && VIR_ALLOC_N(params, args->nparams) < 0) { - virReportOOMError(); + if (args->nparams && VIR_ALLOC_N(params, args->nparams) < 0) goto cleanup; - } nparams = args->nparams; if (virNodeGetMemoryParameters(priv->conn, params, &nparams, flags) < 0) @@ -4758,10 +4642,8 @@ remoteDispatchDomainMigratePrepare3Params( goto cleanup; /* Wacky world of XDR ... */ - if (VIR_ALLOC(uri_out) < 0) { - virReportOOMError(); + if (VIR_ALLOC(uri_out) < 0) goto cleanup; - } if (virDomainMigratePrepare3Params(priv->conn, params, nparams, args->cookie_in.cookie_in_val, @@ -5148,10 +5030,8 @@ remoteSerializeDomainDiskErrors(virDomainDiskErrorPtr errors, remote_domain_disk_error *val = NULL; int i = 0; - if (VIR_ALLOC_N(val, nerrors) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(val, nerrors) < 0) goto error; - } for (i = 0; i < nerrors; i++) { if (VIR_STRDUP(val[i].disk, errors[i].disk) < 0) diff --git a/daemon/stream.c b/daemon/stream.c index 0fb5c85..87dfaf5 100644 --- a/daemon/stream.c +++ b/daemon/stream.c @@ -325,10 +325,8 @@ daemonCreateClientStream(virNetServerClientPtr client, VIR_DEBUG("client=%p, proc=%d, serial=%d, st=%p", client, header->proc, header->serial, st); - if (VIR_ALLOC(stream) < 0) { - virReportOOMError(); + if (VIR_ALLOC(stream) < 0) return NULL; - } stream->refs = 1; stream->priv = priv; -- 1.8.1.5

On 07/04/13 14:06, Michal Privoznik wrote:
--- daemon/libvirtd-config.c | 12 +-- daemon/libvirtd.c | 24 ++--- daemon/remote.c | 234 ++++++++++++----------------------------------- daemon/stream.c | 4 +- 4 files changed, 70 insertions(+), 204 deletions(-)
ACK. Peter

--- src/access/viraccessdriverpolkit.c | 4 +--- src/access/viraccessdriverstack.c | 4 +--- src/access/viraccessmanager.c | 4 +--- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/access/viraccessdriverpolkit.c b/src/access/viraccessdriverpolkit.c index 6e503ba..4c76e64 100644 --- a/src/access/viraccessdriverpolkit.c +++ b/src/access/viraccessdriverpolkit.c @@ -57,10 +57,8 @@ virAccessDriverPolkitFormatAction(const char *typename, if (virAsprintf(&actionid, "%s.%s.%s", VIR_ACCESS_DRIVER_POLKIT_ACTION_PREFIX, - typename, permname) < 0) { - virReportOOMError(); + typename, permname) < 0) return NULL; - } for (i = 0; actionid[i]; i++) if (actionid[i] == '_') diff --git a/src/access/viraccessdriverstack.c b/src/access/viraccessdriverstack.c index ea20db8..11ed4f6 100644 --- a/src/access/viraccessdriverstack.c +++ b/src/access/viraccessdriverstack.c @@ -40,10 +40,8 @@ int virAccessDriverStackAppend(virAccessManagerPtr manager, { virAccessDriverStackPrivatePtr priv = virAccessManagerGetPrivateData(manager); - if (VIR_EXPAND_N(priv->managers, priv->managersLen, 1) < 0) { - virReportOOMError(); + if (VIR_EXPAND_N(priv->managers, priv->managersLen, 1) < 0) return -1; - } priv->managers[priv->managersLen-1] = child; diff --git a/src/access/viraccessmanager.c b/src/access/viraccessmanager.c index 559a844..16e3853 100644 --- a/src/access/viraccessmanager.c +++ b/src/access/viraccessmanager.c @@ -85,10 +85,8 @@ static virAccessManagerPtr virAccessManagerNewDriver(virAccessDriverPtr drv) if (virAccessManagerInitialize() < 0) return NULL; - if (VIR_ALLOC_N(privateData, drv->privateDataLen) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(privateData, drv->privateDataLen) < 0) return NULL; - } if (!(mgr = virObjectLockableNew(virAccessManagerClass))) { VIR_FREE(privateData); -- 1.8.1.5

On 07/04/13 14:06, Michal Privoznik wrote:
--- src/access/viraccessdriverpolkit.c | 4 +--- src/access/viraccessdriverstack.c | 4 +--- src/access/viraccessmanager.c | 4 +--- 3 files changed, 3 insertions(+), 9 deletions(-)
ACK. Peter

--- src/conf/cpu_conf.c | 34 +--- src/conf/domain_conf.c | 328 +++++++++++------------------------ src/conf/domain_event.c | 30 +--- src/conf/interface_conf.c | 35 +--- src/conf/netdev_bandwidth_conf.c | 12 +- src/conf/netdev_vlan_conf.c | 4 +- src/conf/netdev_vport_profile_conf.c | 4 +- src/conf/network_conf.c | 86 +++------ src/conf/node_device_conf.c | 29 +--- src/conf/nwfilter_conf.c | 33 +--- src/conf/nwfilter_ipaddrmap.c | 8 +- src/conf/nwfilter_params.c | 35 +--- src/conf/secret_conf.c | 4 +- src/conf/snapshot_conf.c | 47 ++--- src/conf/storage_conf.c | 38 +--- src/conf/storage_encryption_conf.c | 12 +- src/conf/virchrdev.c | 12 +- 17 files changed, 200 insertions(+), 551 deletions(-) diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c index 960d8a6..16e2d52 100644 --- a/src/conf/cpu_conf.c +++ b/src/conf/cpu_conf.c @@ -103,7 +103,7 @@ virCPUDefCopyModel(virCPUDefPtr dst, VIR_STRDUP(dst->vendor, src->vendor) < 0 || VIR_STRDUP(dst->vendor_id, src->vendor_id) < 0 || VIR_ALLOC_N(dst->features, src->nfeatures) < 0) - goto no_memory; + return -1; dst->nfeatures_max = dst->nfeatures = src->nfeatures; for (i = 0; i < dst->nfeatures; i++) { @@ -123,10 +123,6 @@ virCPUDefCopyModel(virCPUDefPtr dst, } return 0; - -no_memory: - virReportOOMError(); - return -1; } virCPUDefPtr @@ -135,12 +131,9 @@ virCPUDefCopy(const virCPUDefPtr cpu) virCPUDefPtr copy; unsigned int i; - if (!cpu) + if (!cpu || VIR_ALLOC(copy) < 0) return NULL; - if (VIR_ALLOC(copy) < 0) - goto no_memory; - copy->type = cpu->type; copy->mode = cpu->mode; copy->match = cpu->match; @@ -155,7 +148,7 @@ virCPUDefCopy(const virCPUDefPtr cpu) if (cpu->ncells) { if (VIR_ALLOC_N(copy->cells, cpu->ncells) < 0) - goto no_memory; + goto error; copy->ncells_max = copy->ncells = cpu->ncells; for (i = 0; i < cpu->ncells; i++) { @@ -165,7 +158,7 @@ virCPUDefCopy(const virCPUDefPtr cpu) copy->cells[i].cpumask = virBitmapNewCopy(cpu->cells[i].cpumask); if (!copy->cells[i].cpumask) - goto no_memory; + goto error; if (VIR_STRDUP(copy->cells[i].cpustr, cpu->cells[i].cpustr) < 0) goto error; @@ -175,8 +168,6 @@ virCPUDefCopy(const virCPUDefPtr cpu) return copy; -no_memory: - virReportOOMError(); error: virCPUDefFree(copy); return NULL; @@ -202,10 +193,8 @@ virCPUDefParseXML(const xmlNodePtr node, return NULL; } - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } if (mode == VIR_CPU_TYPE_AUTO) { if (virXPathBoolean("boolean(./arch)", ctxt)) { @@ -383,7 +372,7 @@ virCPUDefParseXML(const xmlNodePtr node, if (VIR_RESIZE_N(def->features, def->nfeatures_max, def->nfeatures, n) < 0) - goto no_memory; + goto error; def->nfeatures = n; } @@ -443,7 +432,7 @@ virCPUDefParseXML(const xmlNodePtr node, if (VIR_RESIZE_N(def->cells, def->ncells_max, def->ncells, n) < 0) - goto no_memory; + goto error; def->ncells = n; @@ -490,9 +479,6 @@ cleanup: VIR_FREE(nodes); return def; -no_memory: - virReportOOMError(); - error: virCPUDefFree(def); def = NULL; @@ -689,7 +675,7 @@ virCPUDefAddFeature(virCPUDefPtr def, if (VIR_RESIZE_N(def->features, def->nfeatures_max, def->nfeatures, 1) < 0) - goto no_memory; + return -1; if (def->type == VIR_CPU_TYPE_HOST) policy = -1; @@ -701,10 +687,6 @@ virCPUDefAddFeature(virCPUDefPtr def, def->nfeatures++; return 0; - -no_memory: - virReportOOMError(); - return -1; } bool diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 921a4f6..d45c770 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1603,15 +1603,9 @@ virDomainHostdevDefPtr virDomainHostdevDefAlloc(void) { virDomainHostdevDefPtr def = NULL; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); - return NULL; - } - if (VIR_ALLOC(def->info) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0 || + VIR_ALLOC(def->info) < 0) VIR_FREE(def); - return NULL; - } return def; } @@ -1793,21 +1787,20 @@ virDomainVcpuPinDefCopy(virDomainVcpuPinDefPtr *src, int nvcpupin) int i = 0; virDomainVcpuPinDefPtr *ret = NULL; - if (VIR_ALLOC_N(ret, nvcpupin) < 0) { - goto no_memory; - } + if (VIR_ALLOC_N(ret, nvcpupin) < 0) + goto error; for (i = 0; i < nvcpupin; i++) { if (VIR_ALLOC(ret[i]) < 0) - goto no_memory; + goto error; ret[i]->vcpuid = src[i]->vcpuid; if ((ret[i]->cpumask = virBitmapNewCopy(src[i]->cpumask)) == NULL) - goto no_memory; + goto error; } return ret; -no_memory: +error: if (ret) { for (; i >= 0; --i) { if (ret[i]) { @@ -1817,7 +1810,6 @@ no_memory: } VIR_FREE(ret); } - virReportOOMError(); return NULL; } @@ -2031,10 +2023,8 @@ virDomainObjNew(virDomainXMLOptionPtr xmlopt) return NULL; if (xmlopt->privateData.alloc) { - if (!(domain->privateData = (xmlopt->privateData.alloc)())) { - virReportOOMError(); + if (!(domain->privateData = (xmlopt->privateData.alloc)())) goto error; - } domain->privateDataFreeFunc = xmlopt->privateData.free; } @@ -2060,10 +2050,8 @@ virDomainDefPtr virDomainDefNew(const char *name, { virDomainDefPtr def; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } if (VIR_STRDUP(def->name, name) < 0) { VIR_FREE(def); @@ -2664,7 +2652,7 @@ virDomainDefRejectDuplicateControllers(virDomainDefPtr def) for (i = 0; i < VIR_DOMAIN_CONTROLLER_TYPE_LAST; i++) { if (max_idx[i] >= 0 && !(bitmaps[i] = virBitmapNew(max_idx[i] + 1))) - goto no_memory; + goto cleanup; nbitmaps++; } @@ -2690,10 +2678,6 @@ cleanup: for (i = 0; i < nbitmaps; i++) virBitmapFree(bitmaps[i]); return ret; - -no_memory: - virReportOOMError(); - goto cleanup; } @@ -2769,7 +2753,7 @@ virDomainDefPostParseInternal(virDomainDefPtr def, if (!def->consoles[0]) { /* allocate a new console type for the stolen one */ if (VIR_ALLOC(def->consoles[0]) < 0) - goto no_memory; + return -1; /* Create an console alias for the serial port */ def->consoles[0]->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE; @@ -2780,10 +2764,6 @@ virDomainDefPostParseInternal(virDomainDefPtr def, if (virDomainDefRejectDuplicateControllers(def) < 0) return -1; return 0; - -no_memory: - virReportOOMError(); - return -1; } @@ -4257,10 +4237,8 @@ virSecurityLabelDefParseXML(xmlXPathContextPtr ctxt, char *p; virSecurityLabelDefPtr def = NULL; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) goto error; - } p = virXPathStringLimit("string(./@type)", VIR_SECURITY_LABEL_BUFLEN-1, ctxt); @@ -4381,10 +4359,8 @@ virSecurityLabelDefsParseXML(virDomainDefPtr def, if (n == 0) return 0; - if (VIR_ALLOC_N(def->seclabels, n) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(def->seclabels, n) < 0) goto error; - } /* Parse each "seclabel" tag */ for (i = 0; i < n; i++) { @@ -4467,16 +4443,12 @@ virSecurityDeviceLabelDefParseXML(virSecurityDeviceLabelDefPtr **seclabels_rtn, if (n == 0) return 0; - if (VIR_ALLOC_N(seclabels, n) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(seclabels, n) < 0) goto error; - } nseclabels = n; for (i = 0; i < n; i++) { - if (VIR_ALLOC(seclabels[i]) < 0) { - virReportOOMError(); + if (VIR_ALLOC(seclabels[i]) < 0) goto error; - } } for (i = 0; i < n; i++) { @@ -4561,10 +4533,8 @@ virDomainLeaseDefParseXML(xmlNodePtr node) char *path = NULL; char *offset = NULL; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } cur = node->children; while (cur != NULL) { @@ -4642,10 +4612,8 @@ virDomainDiskSourcePoolDefParse(xmlNodePtr node, goto cleanup; } - if (VIR_ALLOC(def->srcpool) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def->srcpool) < 0) goto cleanup; - } def->srcpool->pool = pool; pool = NULL; @@ -4722,10 +4690,8 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, int expected_secret_usage = -1; int auth_secret_usage = -1; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } def->geometry.cylinders = 0; def->geometry.heads = 0; @@ -4800,10 +4766,8 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, while (child != NULL) { if (child->type == XML_ELEMENT_NODE && xmlStrEqual(child->name, BAD_CAST "host")) { - if (VIR_REALLOC_N(hosts, nhosts + 1) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(hosts, nhosts + 1) < 0) goto error; - } hosts[nhosts].name = NULL; hosts[nhosts].port = NULL; hosts[nhosts].transport = VIR_DOMAIN_DISK_PROTO_TRANS_TCP; @@ -5186,10 +5150,8 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, if (def->srcpool) { char *tmp; if (virAsprintf(&tmp, "pool = '%s', volume = '%s'", - def->srcpool->pool, def->srcpool->volume) < 0) { - virReportOOMError(); + def->srcpool->pool, def->srcpool->volume) < 0) goto error; - } virReportError(VIR_ERR_NO_TARGET, "%s", tmp); VIR_FREE(tmp); @@ -5577,10 +5539,8 @@ virDomainControllerDefParseXML(xmlNodePtr node, char *model = NULL; char *queues = NULL; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } type = virXMLPropString(node, "type"); if (type) { @@ -5750,10 +5710,8 @@ virDomainParseScaledValue(const char *xpath, unsigned long long bytes; *val = 0; - if (virAsprintf(&xpath_full, "string(%s)", xpath) < 0) { - virReportOOMError(); + if (virAsprintf(&xpath_full, "string(%s)", xpath) < 0) goto cleanup; - } ret = virXPathULongLong(xpath_full, ctxt, &bytes); if (ret < 0) { if (ret == -2) @@ -5770,10 +5728,8 @@ virDomainParseScaledValue(const char *xpath, } VIR_FREE(xpath_full); - if (virAsprintf(&xpath_full, "string(%s/@unit)", xpath) < 0) { - virReportOOMError(); + if (virAsprintf(&xpath_full, "string(%s/@unit)", xpath) < 0) goto cleanup; - } unit = virXPathString(xpath_full, ctxt); if (virScaleInteger(&bytes, unit, scale, max) < 0) @@ -5809,10 +5765,8 @@ virDomainFSDefParseXML(xmlNodePtr node, ctxt->node = node; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } type = virXMLPropString(node, "type"); if (type) { @@ -5984,10 +5938,8 @@ virDomainActualNetDefParseXML(xmlNodePtr node, char *mode = NULL; char *addrtype = NULL; - if (VIR_ALLOC(actual) < 0) { - virReportOOMError(); + if (VIR_ALLOC(actual) < 0) return -1; - } ctxt->node = node; @@ -6148,10 +6100,8 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt, xmlNodePtr oldnode = ctxt->node; int ret; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } ctxt->node = node; @@ -6703,10 +6653,8 @@ virDomainChrDefParseTargetXML(virDomainChrDefPtr def, addrStr = virXMLPropString(cur, "address"); portStr = virXMLPropString(cur, "port"); - if (VIR_ALLOC(def->target.addr) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def->target.addr) < 0) goto error; - } if (addrStr == NULL) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -7002,10 +6950,8 @@ virDomainChrDefPtr virDomainChrDefNew(void) { virDomainChrDefPtr def = NULL; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } def->target.port = -1; return def; @@ -7147,10 +7093,8 @@ virDomainSmartcardDefParseXML(xmlNodePtr node, virDomainSmartcardDefPtr def; int i; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } mode = virXMLPropString(node, "mode"); if (mode == NULL) { @@ -7291,10 +7235,8 @@ virDomainTPMDefParseXML(const xmlNodePtr node, xmlNodePtr *backends = NULL; int nbackends; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } model = virXMLPropString(node, "model"); if (model != NULL && @@ -7377,10 +7319,8 @@ virDomainInputDefParseXML(const char *ostype, char *type = NULL; char *bus = NULL; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } type = virXMLPropString(node, "type"); bus = virXMLPropString(node, "bus"); @@ -7473,10 +7413,8 @@ virDomainHubDefParseXML(xmlNodePtr node, unsigned int flags) virDomainHubDefPtr def; char *type = NULL; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } type = virXMLPropString(node, "type"); @@ -7523,10 +7461,8 @@ virDomainTimerDefParseXML(const xmlNodePtr node, xmlNodePtr catchup; int ret; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } ctxt->node = node; @@ -7796,10 +7732,8 @@ virDomainGraphicsDefParseXML(xmlNodePtr node, char *listenAddr = NULL; xmlNodePtr save = ctxt->node; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } ctxt->node = node; @@ -7829,10 +7763,8 @@ virDomainGraphicsDefParseXML(xmlNodePtr node, if (nListens > 0) { int ii; - if (VIR_ALLOC_N(def->listens, nListens) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(def->listens, nListens) < 0) goto error; - } for (ii = 0; ii < nListens; ii++) { int ret = virDomainGraphicsListenDefParseXML(&def->listens[ii], @@ -8320,10 +8252,8 @@ virDomainSoundCodecDefParseXML(const xmlNodePtr node) char *type; virDomainSoundCodecDefPtr def; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } type = virXMLPropString(node, "type"); if ((def->type = virDomainSoundCodecTypeFromString(type)) < 0) { @@ -8353,10 +8283,8 @@ virDomainSoundDefParseXML(const xmlNodePtr node, virDomainSoundDefPtr def; xmlNodePtr save = ctxt->node; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } ctxt->node = node; @@ -8380,7 +8308,6 @@ virDomainSoundDefParseXML(const xmlNodePtr node, int ii; if (VIR_ALLOC_N(def->codecs, ncodecs) < 0) { - virReportOOMError(); VIR_FREE(codecNodes); goto error; } @@ -8422,10 +8349,8 @@ virDomainWatchdogDefParseXML(const xmlNodePtr node, char *action = NULL; virDomainWatchdogDefPtr def; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } model = virXMLPropString(node, "model"); if (model == NULL) { @@ -8481,10 +8406,8 @@ virDomainRNGDefParseXML(const xmlNodePtr node, xmlNodePtr *backends = NULL; int nbackends; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } if (!(model = virXMLPropString(node, "model"))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing RNG device model")); @@ -8552,10 +8475,8 @@ virDomainRNGDefParseXML(const xmlNodePtr node, goto error; } - if (VIR_ALLOC(def->source.chardev) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def->source.chardev) < 0) goto error; - } def->source.chardev->type = virDomainChrTypeFromString(type); if (def->source.chardev->type < 0) { @@ -8600,10 +8521,8 @@ virDomainMemballoonDefParseXML(const xmlNodePtr node, char *model; virDomainMemballoonDefPtr def; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } model = virXMLPropString(node, "model"); if (model == NULL) { @@ -8637,10 +8556,8 @@ virDomainNVRAMDefParseXML(const xmlNodePtr node, { virDomainNVRAMDefPtr def; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } if (virDomainDeviceInfoParseXML(node, NULL, &def->info, flags) < 0) goto error; @@ -8668,10 +8585,8 @@ virSysinfoParseXML(const xmlNodePtr node, return NULL; } - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } type = virXMLPropString(node, "type"); if (type == NULL) { @@ -8853,10 +8768,8 @@ virDomainVideoAccelDefParseXML(const xmlNodePtr node) { if (!support3d && !support2d) return NULL; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } if (support3d) { if (STREQ(support3d, "yes")) @@ -8890,10 +8803,8 @@ virDomainVideoDefParseXML(const xmlNodePtr node, char *ram = NULL; char *primary = NULL; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } cur = node->children; while (cur != NULL) { @@ -9087,10 +8998,8 @@ virDomainRedirdevDefParseXML(const xmlNodePtr node, char *bus, *type = NULL; int remaining; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } bus = virXMLPropString(node, "bus"); if (bus) { @@ -9224,10 +9133,8 @@ virDomainRedirFilterUsbDevDefParseXML(const xmlNodePtr node) char *version = NULL, *allow = NULL; virDomainRedirFilterUsbDevDefPtr def; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } class = virXMLPropString(node, "class"); if (class) { @@ -9320,7 +9227,7 @@ virDomainRedirFilterDefParseXML(const xmlNodePtr node, virDomainRedirFilterDefPtr def = NULL; if (VIR_ALLOC(def) < 0) - goto no_memory; + goto error; ctxt->node = node; if ((n = virXPathNodeSet("./usbdev", ctxt, &nodes)) < 0) { @@ -9328,7 +9235,7 @@ virDomainRedirFilterDefParseXML(const xmlNodePtr node, } if (n && VIR_ALLOC_N(def->usbdevs, n) < 0) - goto no_memory; + goto error; for (i = 0; i < n; i++) { virDomainRedirFilterUsbDevDefPtr usbdev = @@ -9343,9 +9250,6 @@ virDomainRedirFilterDefParseXML(const xmlNodePtr node, ctxt->node = save; return def; -no_memory: - virReportOOMError(); - error: VIR_FREE(nodes); virDomainRedirFilterDefFree(def); @@ -9415,10 +9319,8 @@ virDomainDeviceDefParse(const char *xmlStr, node = ctxt->node; - if (VIR_ALLOC(dev) < 0) { - virReportOOMError(); + if (VIR_ALLOC(dev) < 0) goto error; - } if (xmlStrEqual(node->name, BAD_CAST "disk")) { dev->type = VIR_DOMAIN_DEVICE_DISK; @@ -10047,11 +9949,7 @@ int virDomainLeaseIndex(virDomainDefPtr def, int virDomainLeaseInsertPreAlloc(virDomainDefPtr def) { - if (VIR_EXPAND_N(def->leases, def->nleases, 1) < 0) { - virReportOOMError(); - return -1; - } - return 0; + return VIR_EXPAND_N(def->leases, def->nleases, 1); } int virDomainLeaseInsert(virDomainDefPtr def, @@ -10275,10 +10173,8 @@ virDomainIdmapDefParseXML(xmlXPathContextPtr ctxt, virDomainIdMapEntryPtr idmap = NULL; xmlNodePtr save_ctxt = ctxt->node; - if (VIR_ALLOC_N(idmap, num) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(idmap, num) < 0) goto cleanup; - } for (i = 0; i < num; i++) { ctxt->node = node[i]; @@ -10332,10 +10228,8 @@ virDomainVcpuPinDefParseXML(const xmlNodePtr node, char *tmp = NULL; int ret; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } ctxt->node = node; @@ -10421,10 +10315,8 @@ virDomainDefMaybeAddController(virDomainDefPtr def, return 0; } - if (VIR_ALLOC(cont) < 0) { - virReportOOMError(); + if (VIR_ALLOC(cont) < 0) return -1; - } cont->type = type; cont->idx = idx; @@ -10483,10 +10375,8 @@ virDomainResourceDefParse(xmlNodePtr node, ctxt->node = node; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) goto error; - } /* Find out what type of virtualization to use */ if (!(def->partition = virXPathString("string(./partition)", ctxt))) { @@ -10552,10 +10442,8 @@ virDomainDefParseXML(xmlDocPtr xml, bool usb_master = false; bool primaryVideo = false; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } if (!(flags & VIR_DOMAIN_XML_INACTIVE)) if (virXPathLong("string(./@id)", ctxt, &id) < 0) @@ -10715,7 +10603,7 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; } if (n && VIR_ALLOC_N(def->blkio.devices, n) < 0) - goto no_memory; + goto error; for (i = 0; i < n; i++) { int j; @@ -10894,7 +10782,7 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; if (n && VIR_ALLOC_N(def->cputune.vcpupin, n) < 0) - goto no_memory; + goto error; if (n > def->maxvcpus) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -10934,10 +10822,8 @@ virDomainDefParseXML(xmlDocPtr xml, * the policy specified explicitly as def->cpuset. */ if (def->cpumask) { - if (VIR_REALLOC_N(def->cputune.vcpupin, def->vcpus) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(def->cputune.vcpupin, def->vcpus) < 0) goto error; - } for (i = 0; i < def->vcpus; i++) { if (virDomainVcpuPinIsDuplicate(def->cputune.vcpupin, @@ -10947,10 +10833,8 @@ virDomainDefParseXML(xmlDocPtr xml, virDomainVcpuPinDefPtr vcpupin = NULL; - if (VIR_ALLOC(vcpupin) < 0) { - virReportOOMError(); + if (VIR_ALLOC(vcpupin) < 0) goto error; - } vcpupin->cpumask = virBitmapNew(VIR_DOMAIN_CPUMASK_LEN); virBitmapCopy(vcpupin->cpumask, def->cpumask); @@ -11360,7 +11244,7 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; if (n && VIR_ALLOC_N(def->clock.timers, n) < 0) - goto no_memory; + goto error; for (i = 0; i < n; i++) { virDomainTimerDefPtr timer = virDomainTimerDefParseXML(nodes[i], @@ -11471,7 +11355,7 @@ virDomainDefParseXML(xmlDocPtr xml, } if (VIR_ALLOC_N(def->os.initargv, n+1) < 0) - goto no_memory; + goto error; for (i = 0; i < n; i++) { if (!nodes[i]->children || !nodes[i]->children->content) { @@ -11512,7 +11396,7 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; if (n && VIR_ALLOC_N(def->disks, n) < 0) - goto no_memory; + goto error; for (i = 0; i < n; i++) { virDomainDiskDefPtr disk = virDomainDiskDefParseXML(xmlopt, @@ -11534,7 +11418,7 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; if (n && VIR_ALLOC_N(def->controllers, n) < 0) - goto no_memory; + goto error; for (i = 0; i < n; i++) { virDomainControllerDefPtr controller = virDomainControllerDefParseXML(nodes[i], @@ -11591,7 +11475,7 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; } if (n && VIR_ALLOC_N(def->leases, n) < 0) - goto no_memory; + goto error; for (i = 0; i < n; i++) { virDomainLeaseDefPtr lease = virDomainLeaseDefParseXML(nodes[i]); if (!lease) @@ -11606,7 +11490,7 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; } if (n && VIR_ALLOC_N(def->fss, n) < 0) - goto no_memory; + goto error; for (i = 0; i < n; i++) { virDomainFSDefPtr fs = virDomainFSDefParseXML(nodes[i], ctxt, flags); @@ -11622,7 +11506,7 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; } if (n && VIR_ALLOC_N(def->nets, n) < 0) - goto no_memory; + goto error; for (i = 0; i < n; i++) { virDomainNetDefPtr net = virDomainNetDefParseXML(xmlopt, nodes[i], @@ -11637,7 +11521,7 @@ virDomainDefParseXML(xmlDocPtr xml, /* <interface type='hostdev'> must also be in the hostdevs array */ if (net->type == VIR_DOMAIN_NET_TYPE_HOSTDEV && virDomainHostdevInsert(def, &net->data.hostdev.def) < 0) { - goto no_memory; + goto error; } } VIR_FREE(nodes); @@ -11648,7 +11532,7 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; } if (n && VIR_ALLOC_N(def->smartcards, n) < 0) - goto no_memory; + goto error; for (i = 0; i < n; i++) { virDomainSmartcardDefPtr card = virDomainSmartcardDefParseXML(nodes[i], @@ -11666,7 +11550,7 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; } if (n && VIR_ALLOC_N(def->parallels, n) < 0) - goto no_memory; + goto error; for (i = 0; i < n; i++) { virDomainChrDefPtr chr = virDomainChrDefParseXML(ctxt, @@ -11694,7 +11578,7 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; if (n && VIR_ALLOC_N(def->serials, n) < 0) - goto no_memory; + goto error; for (i = 0; i < n; i++) { virDomainChrDefPtr chr = virDomainChrDefParseXML(ctxt, @@ -11724,7 +11608,7 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; } if (n && VIR_ALLOC_N(def->consoles, n) < 0) - goto no_memory; + goto error; for (i = 0; i < n; i++) { virDomainChrDefPtr chr = virDomainChrDefParseXML(ctxt, @@ -11744,7 +11628,7 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; } if (n && VIR_ALLOC_N(def->channels, n) < 0) - goto no_memory; + goto error; for (i = 0; i < n; i++) { virDomainChrDefPtr chr = virDomainChrDefParseXML(ctxt, @@ -11785,7 +11669,7 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; } if (n && VIR_ALLOC_N(def->inputs, n) < 0) - goto no_memory; + goto error; for (i = 0; i < n; i++) { virDomainInputDefPtr input = virDomainInputDefParseXML(def->os.type, @@ -11825,7 +11709,7 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; } if (n && VIR_ALLOC_N(def->graphics, n) < 0) - goto no_memory; + goto error; for (i = 0; i < n; i++) { virDomainGraphicsDefPtr graphics = virDomainGraphicsDefParseXML(nodes[i], ctxt, @@ -11842,7 +11726,7 @@ virDomainDefParseXML(xmlDocPtr xml, virDomainInputDefPtr input; if (VIR_ALLOC(input) < 0) { - goto no_memory; + goto error; } if (STREQ(def->os.type, "hvm")) { input->type = VIR_DOMAIN_INPUT_TYPE_MOUSE; @@ -11854,7 +11738,7 @@ virDomainDefParseXML(xmlDocPtr xml, if (VIR_REALLOC_N(def->inputs, def->ninputs + 1) < 0) { virDomainInputDefFree(input); - goto no_memory; + goto error; } def->inputs[def->ninputs] = input; def->ninputs++; @@ -11866,7 +11750,7 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; } if (n && VIR_ALLOC_N(def->sounds, n) < 0) - goto no_memory; + goto error; for (i = 0; i < n; i++) { virDomainSoundDefPtr sound = virDomainSoundDefParseXML(nodes[i], ctxt, @@ -11883,7 +11767,7 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; } if (n && VIR_ALLOC_N(def->videos, n) < 0) - goto no_memory; + goto error; for (i = 0; i < n; i++) { size_t ii = def->nvideos; virDomainVideoDefPtr video = virDomainVideoDefParseXML(nodes[i], @@ -11918,7 +11802,7 @@ virDomainDefParseXML(xmlDocPtr xml, if (def->ngraphics && !def->nvideos) { virDomainVideoDefPtr video; if (VIR_ALLOC(video) < 0) - goto no_memory; + goto error; video->type = virDomainVideoDefaultType(def); if (video->type < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -11930,7 +11814,7 @@ virDomainDefParseXML(xmlDocPtr xml, video->heads = 1; if (VIR_ALLOC_N(def->videos, 1) < 0) { virDomainVideoDefFree(video); - goto no_memory; + goto error; } def->videos[def->nvideos++] = video; } @@ -11940,7 +11824,7 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; } if (n && VIR_REALLOC_N(def->hostdevs, def->nhostdevs + n) < 0) - goto no_memory; + goto error; for (i = 0; i < n; i++) { virDomainHostdevDefPtr hostdev; @@ -12009,7 +11893,7 @@ virDomainDefParseXML(xmlDocPtr xml, def->virtType == VIR_DOMAIN_VIRT_KVM) { virDomainMemballoonDefPtr memballoon; if (VIR_ALLOC(memballoon) < 0) - goto no_memory; + goto error; memballoon->model = def->virtType == VIR_DOMAIN_VIRT_XEN ? VIR_DOMAIN_MEMBALLOON_MODEL_XEN : VIR_DOMAIN_MEMBALLOON_MODEL_VIRTIO; @@ -12072,7 +11956,7 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; } if (n && VIR_ALLOC_N(def->hubs, n) < 0) - goto no_memory; + goto error; for (i = 0; i < n; i++) { virDomainHubDefPtr hub = virDomainHubDefParseXML(nodes[i], flags); if (!hub) @@ -12095,7 +11979,7 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; } if (n && VIR_ALLOC_N(def->redirdevs, n) < 0) - goto no_memory; + goto error; for (i = 0; i < n; i++) { virDomainRedirdevDefPtr redirdev = virDomainRedirdevDefParseXML(nodes[i], bootHash, @@ -12240,8 +12124,6 @@ virDomainDefParseXML(xmlDocPtr xml, return def; -no_memory: - virReportOOMError(); error: VIR_FREE(tmp); VIR_FREE(nodes); @@ -13692,10 +13574,8 @@ virDomainVcpuPinAdd(virDomainVcpuPinDefPtr **vcpupin_list, vcpupin->vcpuid = vcpu; virBitmapFree(vcpupin->cpumask); vcpupin->cpumask = virBitmapNewData(cpumap, maplen); - if (!vcpupin->cpumask) { - virReportOOMError(); + if (!vcpupin->cpumask) return -1; - } return 0; } @@ -13703,22 +13583,21 @@ virDomainVcpuPinAdd(virDomainVcpuPinDefPtr **vcpupin_list, /* No existing vcpupin matches vcpu, adding a new one */ if (VIR_ALLOC(vcpupin) < 0) - goto no_memory; + goto error; vcpupin->vcpuid = vcpu; vcpupin->cpumask = virBitmapNewData(cpumap, maplen); if (!vcpupin->cpumask) - goto no_memory; + goto error; if (VIR_REALLOC_N(*vcpupin_list, *nvcpupin + 1) < 0) - goto no_memory; + goto error; (*vcpupin_list)[(*nvcpupin)++] = vcpupin; return 0; -no_memory: - virReportOOMError(); +error: virDomainVcpuPinDefFree(vcpupin); return -1; } @@ -13753,10 +13632,8 @@ virDomainVcpuPinDel(virDomainDefPtr def, int vcpu) if (--def->cputune.nvcpupin == 0) { VIR_FREE(def->cputune.vcpupin); } else { - if (VIR_REALLOC_N(def->cputune.vcpupin, def->cputune.nvcpupin) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(def->cputune.vcpupin, def->cputune.nvcpupin) < 0) return -1; - } } return 0; @@ -13771,10 +13648,8 @@ virDomainEmulatorPinAdd(virDomainDefPtr def, if (!def->cputune.emulatorpin) { /* No emulatorpin exists yet. */ - if (VIR_ALLOC(emulatorpin) < 0) { - virReportOOMError(); + if (VIR_ALLOC(emulatorpin) < 0) return -1; - } emulatorpin->vcpuid = -1; emulatorpin->cpumask = virBitmapNewData(cpumap, maplen); @@ -17063,9 +16938,7 @@ char { char *ret; - if (virAsprintf(&ret, "%s/%s.xml", dir, name) < 0) - virReportOOMError(); - + ignore_value(virAsprintf(&ret, "%s/%s.xml", dir, name)); return ret; } @@ -17690,9 +17563,7 @@ virDomainGraphicsGetListen(virDomainGraphicsDefPtr def, size_t ii, bool force0) def->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE) { if (!def->listens && (ii == 0) && force0) { - if (VIR_ALLOC(def->listens) < 0) - virReportOOMError(); - else + if (VIR_ALLOC(def->listens) >= 0) def->nListens = 1; } @@ -18082,12 +17953,9 @@ virDomainObjListExport(virDomainObjListPtr doms, }; virObjectLock(doms); - if (domains) { - if (VIR_ALLOC_N(data.domains, virHashSize(doms->objs) + 1) < 0) { - virReportOOMError(); - goto cleanup; - } - } + if (domains && + VIR_ALLOC_N(data.domains, virHashSize(doms->objs) + 1) < 0) + goto cleanup; virHashForEach(doms->objs, virDomainListPopulate, &data); @@ -18171,7 +18039,6 @@ virDomainDefGenSecurityLabelDef(const char *model) if (VIR_ALLOC(seclabel) < 0 || VIR_STRDUP(seclabel->model, model) < 0) { - virReportOOMError(); virSecurityLabelDefFree(seclabel); seclabel = NULL; } @@ -18186,7 +18053,6 @@ virDomainDiskDefGenSecurityLabelDef(const char *model) if (VIR_ALLOC(seclabel) < 0 || VIR_STRDUP(seclabel->model, model) < 0) { - virReportOOMError(); virSecurityDeviceLabelDefFree(seclabel); seclabel = NULL; } diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c index bc43c28..260e554 100644 --- a/src/conf/domain_event.c +++ b/src/conf/domain_event.c @@ -376,7 +376,7 @@ virDomainEventCallbackListAddID(virConnectPtr conn, } /* Allocate new event */ if (VIR_ALLOC(event) < 0) - goto no_memory; + goto error; event->conn = conn; event->cb = callback; event->eventID = eventID; @@ -385,7 +385,7 @@ virDomainEventCallbackListAddID(virConnectPtr conn, if (dom) { if (VIR_ALLOC(event->dom) < 0) - goto no_memory; + goto error; if (VIR_STRDUP(event->dom->name, dom->name) < 0) goto error; memcpy(event->dom->uuid, dom->uuid, VIR_UUID_BUFLEN); @@ -394,7 +394,7 @@ virDomainEventCallbackListAddID(virConnectPtr conn, /* Make space on list */ if (VIR_REALLOC_N(cbList->callbacks, cbList->count + 1) < 0) - goto no_memory; + goto error; virObjectRef(event->conn); @@ -415,8 +415,6 @@ virDomainEventCallbackListAddID(virConnectPtr conn, return ret; -no_memory: - virReportOOMError(); error: if (event) { if (event->dom) @@ -566,11 +564,7 @@ virDomainEventQueueNew(void) { virDomainEventQueuePtr ret; - if (VIR_ALLOC(ret) < 0) { - virReportOOMError(); - return NULL; - } - + ignore_value(VIR_ALLOC(ret)); return ret; } @@ -627,10 +621,8 @@ virDomainEventStateNew(void) { virDomainEventStatePtr state = NULL; - if (VIR_ALLOC(state) < 0) { - virReportOOMError(); + if (VIR_ALLOC(state) < 0) goto error; - } if (virMutexInit(&state->lock) < 0) { virReportSystemError(errno, "%s", @@ -639,10 +631,8 @@ virDomainEventStateNew(void) goto error; } - if (VIR_ALLOC(state->callbacks) < 0) { - virReportOOMError(); + if (VIR_ALLOC(state->callbacks) < 0) goto error; - } if (!(state->queue = virDomainEventQueueNew())) goto error; @@ -663,10 +653,8 @@ static virDomainEventPtr virDomainEventNewInternal(int eventID, { virDomainEventPtr event; - if (VIR_ALLOC(event) < 0) { - virReportOOMError(); + if (VIR_ALLOC(event) < 0) return NULL; - } event->eventID = eventID; if (VIR_STRDUP(event->dom.name, name) < 0) { @@ -1188,10 +1176,8 @@ virDomainEventQueuePush(virDomainEventQueuePtr evtQueue, /* Make space on queue */ if (VIR_REALLOC_N(evtQueue->events, - evtQueue->count + 1) < 0) { - virReportOOMError(); + evtQueue->count + 1) < 0) return -1; - } evtQueue->events[evtQueue->count] = event; evtQueue->count++; diff --git a/src/conf/interface_conf.c b/src/conf/interface_conf.c index 025a454..7725b39 100644 --- a/src/conf/interface_conf.c +++ b/src/conf/interface_conf.c @@ -318,20 +318,16 @@ virInterfaceDefParseProtoIPv4(virInterfaceProtocolDefPtr def, if (ipNodes == NULL) return 0; - if (VIR_ALLOC_N(def->ips, nIpNodes) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(def->ips, nIpNodes) < 0) goto error; - } def->nips = 0; for (ii = 0; ii < nIpNodes; ii++) { virInterfaceIpDefPtr ip; - if (VIR_ALLOC(ip) < 0) { - virReportOOMError(); + if (VIR_ALLOC(ip) < 0) goto error; - } ctxt->node = ipNodes[ii]; ret = virInterfaceDefParseIp(ip, ctxt); @@ -377,20 +373,16 @@ virInterfaceDefParseProtoIPv6(virInterfaceProtocolDefPtr def, if (ipNodes == NULL) return 0; - if (VIR_ALLOC_N(def->ips, nIpNodes) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(def->ips, nIpNodes) < 0) goto error; - } def->nips = 0; for (ii = 0; ii < nIpNodes; ii++) { virInterfaceIpDefPtr ip; - if (VIR_ALLOC(ip) < 0) { - virReportOOMError(); + if (VIR_ALLOC(ip) < 0) goto error; - } ctxt->node = ipNodes[ii]; ret = virInterfaceDefParseIp(ip, ctxt); @@ -427,20 +419,16 @@ virInterfaceDefParseIfAdressing(virInterfaceDefPtr def, return 0; } - if (VIR_ALLOC_N(def->protos, nProtoNodes) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(def->protos, nProtoNodes) < 0) goto error; - } def->nprotos = 0; for (pp = 0; pp < nProtoNodes; pp++) { virInterfaceProtocolDefPtr proto; - if (VIR_ALLOC(proto) < 0) { - virReportOOMError(); + if (VIR_ALLOC(proto) < 0) goto error; - } ctxt->node = protoNodes[pp]; tmp = virXPathString("string(./@family)", ctxt); @@ -498,7 +486,6 @@ virInterfaceDefParseBridge(virInterfaceDefPtr def, } if (nbItf > 0) { if (VIR_ALLOC_N(def->data.bridge.itf, nbItf) < 0) { - virReportOOMError(); ret = -1; goto error; } @@ -545,7 +532,6 @@ virInterfaceDefParseBondItfs(virInterfaceDefPtr def, } if (VIR_ALLOC_N(def->data.bond.itf, nbItf) < 0) { - virReportOOMError(); ret = -1; goto error; } @@ -682,10 +668,8 @@ virInterfaceDefParseXML(xmlXPathContextPtr ctxt, int parentIfType) { } VIR_FREE(tmp); - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } if (((parentIfType == VIR_INTERFACE_TYPE_BOND) && (type != VIR_INTERFACE_TYPE_ETHERNET)) @@ -1266,10 +1250,8 @@ virInterfaceObjPtr virInterfaceAssignDef(virInterfaceObjListPtr interfaces, return iface; } - if (VIR_ALLOC(iface) < 0) { - virReportOOMError(); + if (VIR_ALLOC(iface) < 0) return NULL; - } if (virMutexInit(&iface->lock) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot initialize mutex")); @@ -1280,7 +1262,6 @@ virInterfaceObjPtr virInterfaceAssignDef(virInterfaceObjListPtr interfaces, iface->def = def; if (VIR_REALLOC_N(interfaces->objs, interfaces->count + 1) < 0) { - virReportOOMError(); VIR_FREE(iface); return NULL; } diff --git a/src/conf/netdev_bandwidth_conf.c b/src/conf/netdev_bandwidth_conf.c index 87249cb..da14909 100644 --- a/src/conf/netdev_bandwidth_conf.c +++ b/src/conf/netdev_bandwidth_conf.c @@ -120,10 +120,8 @@ virNetDevBandwidthParse(xmlNodePtr node, xmlNodePtr cur; xmlNodePtr in = NULL, out = NULL; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } if (!node || !xmlStrEqual(node->name, BAD_CAST "bandwidth")) { virReportError(VIR_ERR_INVALID_ARG, "%s", @@ -158,10 +156,8 @@ virNetDevBandwidthParse(xmlNodePtr node, } if (in) { - if (VIR_ALLOC(def->in) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def->in) < 0) goto error; - } if (virNetDevBandwidthParseRate(in, def->in) < 0) { /* helper reported error for us */ @@ -184,10 +180,8 @@ virNetDevBandwidthParse(xmlNodePtr node, } if (out) { - if (VIR_ALLOC(def->out) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def->out) < 0) goto error; - } if (virNetDevBandwidthParseRate(out, def->out) < 0) { /* helper reported error for us */ diff --git a/src/conf/netdev_vlan_conf.c b/src/conf/netdev_vlan_conf.c index 880a7ce..54fb0fd 100644 --- a/src/conf/netdev_vlan_conf.c +++ b/src/conf/netdev_vlan_conf.c @@ -54,10 +54,8 @@ virNetDevVlanParse(xmlNodePtr node, xmlXPathContextPtr ctxt, virNetDevVlanPtr de goto cleanup; } - if (VIR_ALLOC_N(def->tag, nTags) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(def->tag, nTags) < 0) goto cleanup; - } def->nativeMode = 0; def->nativeTag = 0; diff --git a/src/conf/netdev_vport_profile_conf.c b/src/conf/netdev_vport_profile_conf.c index c275339..e8199e2 100644 --- a/src/conf/netdev_vport_profile_conf.c +++ b/src/conf/netdev_vport_profile_conf.c @@ -50,10 +50,8 @@ virNetDevVPortProfileParse(xmlNodePtr node, unsigned int flags) virNetDevVPortProfilePtr virtPort = NULL; xmlNodePtr cur = node->children; - if (VIR_ALLOC(virtPort) < 0) { - virReportOOMError(); + if (VIR_ALLOC(virtPort) < 0) return NULL; - } if ((virtPortType = virXMLPropString(node, "type")) && (virtPort->virtPortType = virNetDevVPortTypeFromString(virtPortType)) <= 0) { diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index d6799d2..2ca120b 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -344,15 +344,11 @@ virNetworkAssignDef(virNetworkObjListPtr nets, return network; } - if (VIR_REALLOC_N(nets->objs, nets->count + 1) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(nets->objs, nets->count + 1) < 0) return NULL; - } - if (VIR_ALLOC(network) < 0) { - virReportOOMError(); + if (VIR_ALLOC(network) < 0) return NULL; - } if (virMutexInit(&network->lock) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot initialize mutex")); @@ -362,10 +358,8 @@ virNetworkAssignDef(virNetworkObjListPtr nets, virNetworkObjLock(network); network->def = def; - if (!(network->class_id = virBitmapNew(CLASS_ID_BITMAP_SIZE))) { - virReportOOMError(); + if (!(network->class_id = virBitmapNew(CLASS_ID_BITMAP_SIZE))) goto error; - } /* The first three class IDs are already taken */ ignore_value(virBitmapSetBit(network->class_id, 0)); @@ -796,10 +790,8 @@ virNetworkDHCPDefParseXML(const char *networkName, if (cur->type == XML_ELEMENT_NODE && xmlStrEqual(cur->name, BAD_CAST "range")) { - if (VIR_REALLOC_N(def->ranges, def->nranges + 1) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(def->ranges, def->nranges + 1) < 0) return -1; - } if (virSocketAddrRangeParseXML(networkName, cur, &def->ranges[def->nranges]) < 0) { return -1; @@ -809,10 +801,8 @@ virNetworkDHCPDefParseXML(const char *networkName, } else if (cur->type == XML_ELEMENT_NODE && xmlStrEqual(cur->name, BAD_CAST "host")) { - if (VIR_REALLOC_N(def->hosts, def->nhosts + 1) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(def->hosts, def->nhosts + 1) < 0) return -1; - } if (virNetworkDHCPHostDefParseXML(networkName, def, cur, &def->hosts[def->nhosts], false) < 0) { @@ -883,10 +873,8 @@ virNetworkDNSHostDefParseXML(const char *networkName, if (cur->type == XML_ELEMENT_NODE && xmlStrEqual(cur->name, BAD_CAST "hostname")) { if (cur->children != NULL) { - if (VIR_REALLOC_N(def->names, def->nnames + 1) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(def->names, def->nnames + 1) < 0) goto error; - } def->names[def->nnames++] = (char *)xmlNodeGetContent(cur); if (!def->names[def->nnames - 1]) { virReportError(VIR_ERR_XML_DETAIL, @@ -1062,10 +1050,8 @@ virNetworkDNSDefParseXML(const char *networkName, goto cleanup; } if (nhosts > 0) { - if (VIR_ALLOC_N(def->hosts, nhosts) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(def->hosts, nhosts) < 0) goto cleanup; - } for (ii = 0; ii < nhosts; ii++) { if (virNetworkDNSHostDefParseXML(networkName, hostNodes[ii], @@ -1084,10 +1070,8 @@ virNetworkDNSDefParseXML(const char *networkName, goto cleanup; } if (nsrvs > 0) { - if (VIR_ALLOC_N(def->srvs, nsrvs) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(def->srvs, nsrvs) < 0) goto cleanup; - } for (ii = 0; ii < nsrvs; ii++) { if (virNetworkDNSSrvDefParseXML(networkName, srvNodes[ii], ctxt, @@ -1106,10 +1090,8 @@ virNetworkDNSDefParseXML(const char *networkName, goto cleanup; } if (ntxts > 0) { - if (VIR_ALLOC_N(def->txts, ntxts) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(def->txts, ntxts) < 0) goto cleanup; - } for (ii = 0; ii < ntxts; ii++) { if (virNetworkDNSTxtDefParseXML(networkName, txtNodes[ii], @@ -1786,11 +1768,8 @@ virNetworkForwardDefParseXML(const char *networkName, } if (nForwardIfs > 0 || forwardDev) { - - if (VIR_ALLOC_N(def->ifs, MAX(nForwardIfs, 1)) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(def->ifs, MAX(nForwardIfs, 1)) < 0) goto cleanup; - } if (forwardDev) { def->ifs[0].device.dev = forwardDev; @@ -1833,11 +1812,8 @@ virNetworkForwardDefParseXML(const char *networkName, } } else if (nForwardAddrs > 0) { - - if (VIR_ALLOC_N(def->ifs, nForwardAddrs) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(def->ifs, nForwardAddrs) < 0) goto cleanup; - } for (ii = 0; ii < nForwardAddrs; ii++) { if (!(type = virXMLPropString(forwardAddrNodes[ii], "type"))) { @@ -1880,11 +1856,8 @@ virNetworkForwardDefParseXML(const char *networkName, networkName); goto cleanup; } else if (nForwardPfs == 1) { - - if (VIR_ALLOC_N(def->pfs, nForwardPfs) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(def->pfs, nForwardPfs) < 0) goto cleanup; - } forwardDev = virXMLPropString(*forwardPfNodes, "dev"); if (!forwardDev) { @@ -1898,7 +1871,6 @@ virNetworkForwardDefParseXML(const char *networkName, def->pfs->dev = forwardDev; forwardDev = NULL; def->npfs++; - } ret = 0; @@ -1933,10 +1905,8 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt) xmlNodePtr bandwidthNode = NULL; xmlNodePtr vlanNode; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } /* Extract network name */ def->name = virXPathString("string(./name[1])", ctxt); @@ -2040,10 +2010,8 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt) int ii; /* allocate array to hold all the portgroups */ - if (VIR_ALLOC_N(def->portGroups, nPortGroups) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(def->portGroups, nPortGroups) < 0) goto error; - } /* parse each portgroup */ for (ii = 0; ii < nPortGroups; ii++) { int ret = virNetworkPortGroupParseXML(&def->portGroups[ii], @@ -2063,10 +2031,8 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt) int ii; /* allocate array to hold all the addrs */ - if (VIR_ALLOC_N(def->ips, nIps) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(def->ips, nIps) < 0) goto error; - } /* parse each addr */ for (ii = 0; ii < nIps; ii++) { int ret = virNetworkIPDefParseXML(def->name, ipNodes[ii], @@ -2086,10 +2052,8 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt) int ii; /* allocate array to hold all the route definitions */ - if (VIR_ALLOC_N(def->routes, nRoutes) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(def->routes, nRoutes) < 0) goto error; - } /* parse each definition */ for (ii = 0; ii < nRoutes; ii++) { int ret = virNetworkRouteDefParseXML(def->name, routeNodes[ii], @@ -3121,11 +3085,7 @@ char *virNetworkConfigFile(const char *dir, { char *ret = NULL; - if (virAsprintf(&ret, "%s/%s.xml", dir, name) < 0) { - virReportOOMError(); - return NULL; - } - + ignore_value(virAsprintf(&ret, "%s/%s.xml", dir, name)); return ret; } @@ -3159,10 +3119,8 @@ char *virNetworkAllocateBridge(const virNetworkObjListPtr nets, template = "virbr%d"; do { - if (virAsprintf(&newname, template, id) < 0) { - virReportOOMError(); + if (virAsprintf(&newname, template, id) < 0) return NULL; - } if (!virNetworkBridgeInUse(nets, newname, NULL)) { return newname; } @@ -4281,12 +4239,8 @@ virNetworkObjListExport(virConnectPtr conn, int ret = -1; int i; - if (nets) { - if (VIR_ALLOC_N(tmp_nets, netobjs.count + 1) < 0) { - virReportOOMError(); - goto cleanup; - } - } + if (nets && VIR_ALLOC_N(tmp_nets, netobjs.count + 1) < 0) + goto cleanup; for (i = 0; i < netobjs.count; i++) { virNetworkObjPtr netobj = netobjs.objs[i]; diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 7406652..6f97dc0 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -176,10 +176,8 @@ virNodeDeviceObjPtr virNodeDeviceAssignDef(virNodeDeviceObjListPtr devs, return device; } - if (VIR_ALLOC(device) < 0) { - virReportOOMError(); + if (VIR_ALLOC(device) < 0) return NULL; - } if (virMutexInit(&device->lock) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -194,7 +192,6 @@ virNodeDeviceObjPtr virNodeDeviceAssignDef(virNodeDeviceObjListPtr devs, device->def = NULL; virNodeDeviceObjUnlock(device); virNodeDeviceObjFree(device); - virReportOOMError(); return NULL; } devs->objs[devs->count++] = device; @@ -1015,20 +1012,16 @@ virNodeDevCapPciDevIommuGroupParseXML(xmlXPathContextPtr ctxt, virDevicePCIAddress addr = { 0, 0, 0, 0, 0 }; if (virDevicePCIAddressParseXML(addrNodes[ii], &addr) < 0) goto cleanup; - if (VIR_ALLOC(pciAddr) < 0) { - virReportOOMError(); + if (VIR_ALLOC(pciAddr) < 0) goto cleanup; - } pciAddr->domain = addr.domain; pciAddr->bus = addr.bus; pciAddr->slot = addr.slot; pciAddr->function = addr.function; if (VIR_APPEND_ELEMENT(data->pci_dev.iommuGroupDevices, data->pci_dev.nIommuGroupDevices, - pciAddr, false) < 0) { - virReportOOMError(); + pciAddr, true) < 0) goto cleanup; - } } ret = 0; @@ -1159,10 +1152,8 @@ virNodeDevCapsDefParseXML(xmlXPathContextPtr ctxt, char *tmp; int val, ret; - if (VIR_ALLOC(caps) < 0) { - virReportOOMError(); + if (VIR_ALLOC(caps) < 0) return NULL; - } tmp = virXMLPropString(node, "type"); if (!tmp) { @@ -1238,10 +1229,8 @@ virNodeDeviceDefParseXML(xmlXPathContextPtr ctxt, xmlNodePtr *nodes; int n, i; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } /* Extract device name */ if (create == EXISTING_DEVICE) { @@ -1606,12 +1595,8 @@ virNodeDeviceObjListExport(virConnectPtr conn, int ret = -1; int i; - if (devices) { - if (VIR_ALLOC_N(tmp_devices, devobjs.count + 1) < 0) { - virReportOOMError(); - goto cleanup; - } - } + if (devices && VIR_ALLOC_N(tmp_devices, devobjs.count + 1) < 0) + goto cleanup; for (i = 0; i < devobjs.count; i++) { virNodeDeviceObjPtr devobj = devobjs.objs[i]; diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c index b2be99a..664701d 100644 --- a/src/conf/nwfilter_conf.c +++ b/src/conf/nwfilter_conf.c @@ -378,7 +378,6 @@ virNWFilterRuleDefAddVar(virNWFilterRuleDefPtr nwf, } if (VIR_EXPAND_N(nwf->varAccess, nwf->nVarAccess, 1) < 0) { - virReportOOMError(); virNWFilterVarAccessFree(varAccess); return -1; } @@ -395,10 +394,8 @@ virNWFilterRuleDefAddString(virNWFilterRuleDefPtr nwf, const char *string, size_t maxstrlen) { - if (VIR_REALLOC_N(nwf->strings, nwf->nstrings+1) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(nwf->strings, nwf->nstrings+1) < 0) return NULL; - } if (VIR_STRNDUP(nwf->strings[nwf->nstrings], string, maxstrlen) < 0) return NULL; @@ -2039,10 +2036,8 @@ virNWFilterIncludeParse(xmlNodePtr cur) { virNWFilterIncludeDefPtr ret; - if (VIR_ALLOC(ret) < 0) { - virReportOOMError(); + if (VIR_ALLOC(ret) < 0) return NULL; - } ret->filterref = virXMLPropString(cur, "filter"); if (!ret->filterref) { @@ -2303,10 +2298,8 @@ virNWFilterRuleParse(xmlNodePtr node) xmlNodePtr cur; virNWFilterRuleDefPtr ret; - if (VIR_ALLOC(ret) < 0) { - virReportOOMError(); + if (VIR_ALLOC(ret) < 0) return NULL; - } action = virXMLPropString(node, "action"); direction = virXMLPropString(node, "direction"); @@ -2499,10 +2492,8 @@ virNWFilterDefParseXML(xmlXPathContextPtr ctxt) { int chain_priority; const char *name_prefix; - if (VIR_ALLOC(ret) < 0) { - virReportOOMError(); + if (VIR_ALLOC(ret) < 0) return NULL; - } ret->name = virXPathString("string(./@name)", ctxt); if (!ret->name) { @@ -2577,10 +2568,8 @@ virNWFilterDefParseXML(xmlXPathContextPtr ctxt) { while (curr != NULL) { if (curr->type == XML_ELEMENT_NODE) { - if (VIR_ALLOC(entry) < 0) { - virReportOOMError(); + if (VIR_ALLOC(entry) < 0) goto cleanup; - } /* ignore malformed rule and include elements */ if (xmlStrEqual(curr->name, BAD_CAST "rule")) @@ -2591,7 +2580,6 @@ virNWFilterDefParseXML(xmlXPathContextPtr ctxt) { if (entry->rule || entry->include) { if (VIR_REALLOC_N(ret->filterEntries, ret->nentries+1) < 0) { VIR_FREE(entry); - virReportOOMError(); goto cleanup; } ret->filterEntries[ret->nentries++] = entry; @@ -3032,10 +3020,8 @@ virNWFilterObjAssignDef(virConnectPtr conn, virNWFilterUnlockFilterUpdates(); - if (VIR_ALLOC(nwfilter) < 0) { - virReportOOMError(); + if (VIR_ALLOC(nwfilter) < 0) return NULL; - } if (virMutexInitRecursive(&nwfilter->lock) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -3051,7 +3037,6 @@ virNWFilterObjAssignDef(virConnectPtr conn, nwfilter->def = NULL; virNWFilterObjUnlock(nwfilter); virNWFilterObjFree(nwfilter); - virReportOOMError(); return NULL; } nwfilters->objs[nwfilters->count++] = nwfilter; @@ -3485,11 +3470,7 @@ char *virNWFilterConfigFile(const char *dir, { char *ret = NULL; - if (virAsprintf(&ret, "%s/%s.xml", dir, name) < 0) { - virReportOOMError(); - return NULL; - } - + ignore_value(virAsprintf(&ret, "%s/%s.xml", dir, name)); return ret; } diff --git a/src/conf/nwfilter_ipaddrmap.c b/src/conf/nwfilter_ipaddrmap.c index 317069d..b592a90 100644 --- a/src/conf/nwfilter_ipaddrmap.c +++ b/src/conf/nwfilter_ipaddrmap.c @@ -58,10 +58,8 @@ virNWFilterIPAddrMapAddIPAddr(const char *ifname, char *addr) val = virHashLookup(ipAddressMap->hashTable, ifname); if (!val) { val = virNWFilterVarValueCreateSimple(addr); - if (!val) { - virReportOOMError(); + if (!val) goto cleanup; - } ret = virNWFilterHashTablePut(ipAddressMap, ifname, val, 1); goto cleanup; } else { @@ -146,10 +144,8 @@ int virNWFilterIPAddrMapInit(void) { ipAddressMap = virNWFilterHashTableCreate(0); - if (!ipAddressMap) { - virReportOOMError(); + if (!ipAddressMap) return -1; - } if (virMutexInit(&ipAddressMapLock) < 0) { virNWFilterIPAddrMapShutdown(); diff --git a/src/conf/nwfilter_params.c b/src/conf/nwfilter_params.c index 48b89b7..84ddbfa 100644 --- a/src/conf/nwfilter_params.c +++ b/src/conf/nwfilter_params.c @@ -71,10 +71,8 @@ virNWFilterVarValueCopy(const virNWFilterVarValuePtr val) unsigned i; char *str; - if (VIR_ALLOC(res) < 0) { - virReportOOMError(); + if (VIR_ALLOC(res) < 0) return NULL; - } res->valType = val->valType; switch (res->valType) { @@ -99,7 +97,6 @@ virNWFilterVarValueCopy(const virNWFilterVarValuePtr val) return res; err_exit: - virReportOOMError(); virNWFilterVarValueFree(res); return NULL; } @@ -115,10 +112,8 @@ virNWFilterVarValueCreateSimple(char *value) return NULL; } - if (VIR_ALLOC(val) < 0) { - virReportOOMError(); + if (VIR_ALLOC(val) < 0) return NULL; - } val->valType = NWFILTER_VALUE_TYPE_SIMPLE; val->u.simple.value = value; @@ -227,7 +222,6 @@ virNWFilterVarValueAddValue(virNWFilterVarValuePtr val, char *value) tmp = val->u.simple.value; if (VIR_ALLOC_N(val->u.array.values, 2) < 0) { val->u.simple.value = tmp; - virReportOOMError(); return -1; } val->valType = NWFILTER_VALUE_TYPE_ARRAY; @@ -239,10 +233,8 @@ virNWFilterVarValueAddValue(virNWFilterVarValuePtr val, char *value) case NWFILTER_VALUE_TYPE_ARRAY: if (VIR_EXPAND_N(val->u.array.values, - val->u.array.nValues, 1) < 0) { - virReportOOMError(); + val->u.array.nValues, 1) < 0) return -1; - } val->u.array.values[val->u.array.nValues - 1] = value; rc = 0; break; @@ -383,10 +375,8 @@ virNWFilterVarCombIterAddVariable(virNWFilterVarCombIterEntryPtr cie, } } - if (VIR_EXPAND_N(cie->varNames, cie->nVarNames, 1) < 0) { - virReportOOMError(); + if (VIR_EXPAND_N(cie->varNames, cie->nVarNames, 1) < 0) return -1; - } cie->varNames[cie->nVarNames - 1] = varName; @@ -477,10 +467,8 @@ virNWFilterVarCombIterCreate(virNWFilterHashTablePtr hash, int iterIndex = -1; unsigned int nextIntIterId = VIR_NWFILTER_MAX_ITERID + 1; - if (VIR_ALLOC_VAR(res, virNWFilterVarCombIterEntry, 1 + nVarAccess) < 0) { - virReportOOMError(); + if (VIR_ALLOC_VAR(res, virNWFilterVarCombIterEntry, 1 + nVarAccess) < 0) return NULL; - } res->hashTable = hash; @@ -703,10 +691,8 @@ virNWFilterHashTablePtr virNWFilterHashTableCreate(int n) { virNWFilterHashTablePtr ret; - if (VIR_ALLOC(ret) < 0) { - virReportOOMError(); + if (VIR_ALLOC(ret) < 0) return NULL; - } ret->hashTable = virHashCreate(n, hashDataFree); if (!ret->hashTable) { VIR_FREE(ret); @@ -754,7 +740,6 @@ addToTable(void *payload, const void *name, void *data) val = virNWFilterVarValueCopy((virNWFilterVarValuePtr)payload); if (!val) { - virReportOOMError(); atts->errOccurred = 1; return; } @@ -836,10 +821,8 @@ virNWFilterParseParamAttributes(xmlNodePtr cur) virNWFilterVarValuePtr value; virNWFilterHashTablePtr table = virNWFilterHashTableCreate(0); - if (!table) { - virReportOOMError(); + if (!table) return NULL; - } cur = cur->children; @@ -989,10 +972,8 @@ virNWFilterVarAccessParse(const char *varAccess) virNWFilterVarAccessPtr dest; const char *input = varAccess; - if (VIR_ALLOC(dest) < 0) { - virReportOOMError(); + if (VIR_ALLOC(dest) < 0) return NULL; - } idx = strspn(input, VALID_VARNAME); diff --git a/src/conf/secret_conf.c b/src/conf/secret_conf.c index 5bcfe12..335884e 100644 --- a/src/conf/secret_conf.c +++ b/src/conf/secret_conf.c @@ -152,10 +152,8 @@ secretXMLParseNode(xmlDocPtr xml, xmlNodePtr root) } ctxt->node = root; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) goto cleanup; - } prop = virXPathString("string(./@ephemeral)", ctxt); if (prop != NULL) { diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index b500111..4610737 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -195,10 +195,8 @@ virDomainSnapshotDefParseString(const char *xmlStr, } xmlKeepBlanksDefault(keepBlanksDefault); - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) goto cleanup; - } if (!xmlStrEqual(ctxt->node->name, BAD_CAST "domainsnapshot")) { virReportError(VIR_ERR_XML_ERROR, "%s", _("domainsnapshot")); @@ -214,10 +212,8 @@ virDomainSnapshotDefParseString(const char *xmlStr, _("a redefined snapshot must have a name")); goto cleanup; } - if (virAsprintf(&def->name, "%lld", (long long)tv.tv_sec) < 0) { - virReportOOMError(); + if (virAsprintf(&def->name, "%lld", (long long)tv.tv_sec) < 0) goto cleanup; - } } def->description = virXPathString("string(./description)", ctxt); @@ -321,10 +317,8 @@ virDomainSnapshotDefParseString(const char *xmlStr, goto cleanup; if (flags & VIR_DOMAIN_SNAPSHOT_PARSE_DISKS) { def->ndisks = i; - if (def->ndisks && VIR_ALLOC_N(def->disks, def->ndisks) < 0) { - virReportOOMError(); + if (def->ndisks && VIR_ALLOC_N(def->disks, def->ndisks) < 0) goto cleanup; - } for (i = 0; i < def->ndisks; i++) { if (virDomainSnapshotDiskDefParseXML(nodes[i], &def->disks[i]) < 0) goto cleanup; @@ -407,10 +401,8 @@ virDomainSnapshotAlignDisks(virDomainSnapshotDefPtr def, goto cleanup; } - if (!(map = virBitmapNew(def->dom->ndisks))) { - virReportOOMError(); + if (!(map = virBitmapNew(def->dom->ndisks))) goto cleanup; - } /* Double check requested disks. */ for (i = 0; i < def->ndisks; i++) { @@ -471,10 +463,8 @@ virDomainSnapshotAlignDisks(virDomainSnapshotDefPtr def, /* Provide defaults for all remaining disks. */ ndisks = def->ndisks; if (VIR_EXPAND_N(def->disks, def->ndisks, - def->dom->ndisks - def->ndisks) < 0) { - virReportOOMError(); + def->dom->ndisks - def->ndisks) < 0) goto cleanup; - } for (i = 0; i < def->dom->ndisks; i++) { virDomainSnapshotDiskDefPtr disk; @@ -522,21 +512,18 @@ virDomainSnapshotAlignDisks(virDomainSnapshotDefPtr def, tmp = strrchr(original, '.'); if (!tmp || strchr(tmp, '/')) { - ignore_value(virAsprintf(&disk->file, "%s.%s", - original, def->name)); + if (virAsprintf(&disk->file, "%s.%s", original, def->name) < 0) + goto cleanup; } else { if ((tmp - original) > INT_MAX) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("integer overflow")); goto cleanup; } - ignore_value(virAsprintf(&disk->file, "%.*s.%s", - (int) (tmp - original), original, - def->name)); - } - if (!disk->file) { - virReportOOMError(); - goto cleanup; + if (virAsprintf(&disk->file, "%.*s.%s", + (int) (tmp - original), original, + def->name) < 0) + goto cleanup; } } } @@ -644,10 +631,8 @@ static virDomainSnapshotObjPtr virDomainSnapshotObjNew(void) { virDomainSnapshotObjPtr snapshot; - if (VIR_ALLOC(snapshot) < 0) { - virReportOOMError(); + if (VIR_ALLOC(snapshot) < 0) return NULL; - } VIR_DEBUG("obj=%p", snapshot); @@ -703,10 +688,8 @@ virDomainSnapshotObjListPtr virDomainSnapshotObjListNew(void) { virDomainSnapshotObjListPtr snapshots; - if (VIR_ALLOC(snapshots) < 0) { - virReportOOMError(); + if (VIR_ALLOC(snapshots) < 0) return NULL; - } snapshots->objs = virHashCreate(50, virDomainSnapshotObjListDataFree); if (!snapshots->objs) { VIR_FREE(snapshots); @@ -1031,10 +1014,8 @@ virDomainListSnapshots(virDomainSnapshotObjListPtr snapshots, if (!snaps || count < 0) return count; if (VIR_ALLOC_N(names, count) < 0 || - VIR_ALLOC_N(list, count + 1) < 0) { - virReportOOMError(); + VIR_ALLOC_N(list, count + 1) < 0) goto cleanup; - } if (virDomainSnapshotObjListGetNames(snapshots, from, names, count, flags) < 0) diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index 2539c45..507f6dd 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -569,10 +569,8 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt, source->nhost = n; if (source->nhost) { - if (VIR_ALLOC_N(source->hosts, source->nhost) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(source->hosts, source->nhost) < 0) goto cleanup; - } for (i = 0; i < source->nhost; i++) { name = virXMLPropString(nodeset[i], "name"); @@ -605,7 +603,6 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt, if (nsource > 0) { if (VIR_ALLOC_N(source->devices, nsource) < 0) { VIR_FREE(nodeset); - virReportOOMError(); goto cleanup; } @@ -728,10 +725,8 @@ virStoragePoolDefParseSourceString(const char *srcSpec, &xpath_ctxt))) goto cleanup; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) goto cleanup; - } if (!(node = virXPathNode("/source", xpath_ctxt))) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -840,10 +835,8 @@ virStoragePoolDefParseXML(xmlXPathContextPtr ctxt) char *uuid = NULL; char *target_path = NULL; - if (VIR_ALLOC(ret) < 0) { - virReportOOMError(); + if (VIR_ALLOC(ret) < 0) return NULL; - } type = virXPathString("string(./@type)", ctxt); if (type == NULL) { @@ -1267,10 +1260,8 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool, if (options == NULL) return NULL; - if (VIR_ALLOC(ret) < 0) { - virReportOOMError(); + if (VIR_ALLOC(ret) < 0) return NULL; - } ret->name = virXPathString("string(./name)", ctxt); if (ret->name == NULL) { @@ -1373,7 +1364,7 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool, goto error; if (!(ret->target.features = virBitmapNew(VIR_STORAGE_FILE_FEATURE_LAST))) - goto no_memory; + goto error; for (i = 0; i < n; i++) { int f = options->featureFromString((const char*)nodes[i]->name); @@ -1400,8 +1391,6 @@ cleanup: VIR_FREE(unit); return ret; -no_memory: - virReportOOMError(); error: virStorageVolDefFree(ret); ret = NULL; @@ -1743,10 +1732,8 @@ virStoragePoolObjAssignDef(virStoragePoolObjListPtr pools, return pool; } - if (VIR_ALLOC(pool) < 0) { - virReportOOMError(); + if (VIR_ALLOC(pool) < 0) return NULL; - } if (virMutexInit(&pool->lock) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -1762,7 +1749,6 @@ virStoragePoolObjAssignDef(virStoragePoolObjListPtr pools, pool->def = NULL; virStoragePoolObjUnlock(pool); virStoragePoolObjFree(pool); - virReportOOMError(); return NULL; } pools->objs[pools->count++] = pool; @@ -1933,10 +1919,8 @@ virStoragePoolSourceListNewSource(virStoragePoolSourceListPtr list) { virStoragePoolSourcePtr source; - if (VIR_REALLOC_N(list->sources, list->nsources + 1) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(list->sources, list->nsources + 1) < 0) return NULL; - } source = &list->sources[list->nsources++]; memset(source, 0, sizeof(*source)); @@ -2215,12 +2199,8 @@ virStoragePoolObjListExport(virConnectPtr conn, int ret = -1; int i; - if (pools) { - if (VIR_ALLOC_N(tmp_pools, poolobjs.count + 1) < 0) { - virReportOOMError(); - goto cleanup; - } - } + if (pools && VIR_ALLOC_N(tmp_pools, poolobjs.count + 1) < 0) + goto cleanup; for (i = 0; i < poolobjs.count; i++) { virStoragePoolObjPtr poolobj = poolobjs.objs[i]; diff --git a/src/conf/storage_encryption_conf.c b/src/conf/storage_encryption_conf.c index c710bbd..f52500f 100644 --- a/src/conf/storage_encryption_conf.c +++ b/src/conf/storage_encryption_conf.c @@ -77,10 +77,8 @@ virStorageEncryptionSecretParse(xmlXPathContextPtr ctxt, int type; char *uuidstr = NULL; - if (VIR_ALLOC(ret) < 0) { - virReportOOMError(); + if (VIR_ALLOC(ret) < 0) return NULL; - } old_node = ctxt->node; ctxt->node = node; @@ -134,10 +132,8 @@ virStorageEncryptionParseXML(xmlXPathContextPtr ctxt) char *format_str; int format, i, n; - if (VIR_ALLOC(ret) < 0) { - virReportOOMError(); + if (VIR_ALLOC(ret) < 0) return NULL; - } format_str = virXPathString("string(./@format)", ctxt); if (format_str == NULL) { @@ -160,10 +156,8 @@ virStorageEncryptionParseXML(xmlXPathContextPtr ctxt) if (n < 0){ goto cleanup; } - if (n != 0 && VIR_ALLOC_N(ret->secrets, n) < 0) { - virReportOOMError(); + if (n != 0 && VIR_ALLOC_N(ret->secrets, n) < 0) goto cleanup; - } ret->nsecrets = n; for (i = 0; i < n; i++) { ret->secrets[i] = virStorageEncryptionSecretParse(ctxt, nodes[i]); diff --git a/src/conf/virchrdev.c b/src/conf/virchrdev.c index 36fbb97..0ec184a 100644 --- a/src/conf/virchrdev.c +++ b/src/conf/virchrdev.c @@ -89,10 +89,8 @@ static char *virChrdevLockFilePath(const char *dev) ++p; } - if (virAsprintf(&path, "%s/LCK..%s", VIR_CHRDEV_LOCK_FILE_PATH, filename) < 0) { - virReportOOMError(); + if (virAsprintf(&path, "%s/LCK..%s", VIR_CHRDEV_LOCK_FILE_PATH, filename) < 0) goto cleanup; - } sanitizedPath = virFileSanitizePath(path); @@ -138,10 +136,8 @@ static int virChrdevLockFileCreate(const char *dev) /* ensure correct format according to filesystem hierarchy standard */ /* http://www.pathname.com/fhs/pub/fhs-2.3.html#VARLOCKLOCKFILES */ - if (virAsprintf(&pidStr, "%10lld\n", (long long) getpid()) < 0) { - virReportOOMError(); + if (virAsprintf(&pidStr, "%10lld\n", (long long) getpid()) < 0) goto cleanup; - } /* create the lock file */ if ((lockfd = open(path, O_WRONLY | O_CREAT | O_EXCL, 00644)) < 0) { @@ -396,10 +392,8 @@ int virChrdevOpen(virChrdevsPtr devs, return -1; } - if (VIR_ALLOC(cbdata) < 0) { - virReportOOMError(); + if (VIR_ALLOC(cbdata) < 0) goto error; - } if (virHashAddEntry(devs->hash, path, st) < 0) goto error; -- 1.8.1.5

On 07/04/2013 02:06 PM, Michal Privoznik wrote:
--- src/conf/cpu_conf.c | 34 +--- src/conf/domain_conf.c | 328 +++++++++++------------------------ src/conf/domain_event.c | 30 +--- src/conf/interface_conf.c | 35 +--- src/conf/netdev_bandwidth_conf.c | 12 +- src/conf/netdev_vlan_conf.c | 4 +- src/conf/netdev_vport_profile_conf.c | 4 +- src/conf/network_conf.c | 86 +++------ src/conf/node_device_conf.c | 29 +--- src/conf/nwfilter_conf.c | 33 +--- src/conf/nwfilter_ipaddrmap.c | 8 +- src/conf/nwfilter_params.c | 35 +--- src/conf/secret_conf.c | 4 +- src/conf/snapshot_conf.c | 47 ++--- src/conf/storage_conf.c | 38 +--- src/conf/storage_encryption_conf.c | 12 +- src/conf/virchrdev.c | 12 +- 17 files changed, 200 insertions(+), 551 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 921a4f6..d45c770 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2031,10 +2023,8 @@ virDomainObjNew(virDomainXMLOptionPtr xmlopt) return NULL;
if (xmlopt->privateData.alloc) { - if (!(domain->privateData = (xmlopt->privateData.alloc)())) { - virReportOOMError(); + if (!(domain->privateData = (xmlopt->privateData.alloc)())) goto error; - } domain->privateDataFreeFunc = xmlopt->privateData.free; }
It seems qemuDomainObjPrivateAlloc can fail without reporting an error.
@@ -17690,9 +17563,7 @@ virDomainGraphicsGetListen(virDomainGraphicsDefPtr def, size_t ii, bool force0) def->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE) {
if (!def->listens && (ii == 0) && force0) { - if (VIR_ALLOC(def->listens) < 0) - virReportOOMError(); - else + if (VIR_ALLOC(def->listens) >= 0) def->nListens = 1; }
Weird, but pre-existing. ACK Jan

--- src/cpu/cpu.c | 4 +-- src/cpu/cpu_arm.c | 6 +--- src/cpu/cpu_generic.c | 12 +++---- src/cpu/cpu_powerpc.c | 20 +++--------- src/cpu/cpu_s390.c | 4 +-- src/cpu/cpu_x86.c | 86 +++++++++++++++++++-------------------------------- 6 files changed, 44 insertions(+), 88 deletions(-) diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c index 68125a5..33d91f5 100644 --- a/src/cpu/cpu.c +++ b/src/cpu/cpu.c @@ -308,7 +308,7 @@ cpuBaselineXML(const char **xmlCPUs, } if (VIR_ALLOC_N(cpus, ncpus)) - goto no_memory; + goto error; for (i = 0; i < ncpus; i++) { if (!(doc = virXMLParseStringCtxt(xmlCPUs[i], _("(CPU_definition)"), &ctxt))) @@ -341,8 +341,6 @@ cleanup: return cpustr; -no_memory: - virReportOOMError(); error: cpustr = NULL; goto cleanup; diff --git a/src/cpu/cpu_arm.c b/src/cpu/cpu_arm.c index cfe1a23..0748267 100644 --- a/src/cpu/cpu_arm.c +++ b/src/cpu/cpu_arm.c @@ -35,11 +35,7 @@ ArmNodeData(void) { union cpuData *data; - if (VIR_ALLOC(data) < 0) { - virReportOOMError(); - return NULL; - } - + ignore_value(VIR_ALLOC(data)); return data; } diff --git a/src/cpu/cpu_generic.c b/src/cpu/cpu_generic.c index 7e3eda2..0d99901 100644 --- a/src/cpu/cpu_generic.c +++ b/src/cpu/cpu_generic.c @@ -69,10 +69,8 @@ genericCompare(virCPUDefPtr host, STRNEQ(host->model, cpu->model)) return VIR_CPU_COMPARE_INCOMPATIBLE; - if ((hash = genericHashFeatures(host)) == NULL) { - virReportOOMError(); + if ((hash = genericHashFeatures(host)) == NULL) goto cleanup; - } reqfeatures = 0; for (i = 0; i < cpu->nfeatures; i++) { @@ -133,7 +131,7 @@ genericBaseline(virCPUDefPtr *cpus, if (VIR_ALLOC(cpu) < 0 || VIR_STRDUP(cpu->model, cpus[0]->model) < 0 || VIR_ALLOC_N(features, cpus[0]->nfeatures) < 0) - goto no_memory; + goto error; cpu->arch = cpus[0]->arch; cpu->type = VIR_CPU_TYPE_HOST; @@ -161,7 +159,7 @@ genericBaseline(virCPUDefPtr *cpus, } if (!(hash = genericHashFeatures(cpus[i]))) - goto no_memory; + goto error; for (j = 0; j < nfeatures; j++) { if (features[j].name && @@ -175,7 +173,7 @@ genericBaseline(virCPUDefPtr *cpus, } if (VIR_ALLOC_N(cpu->features, count) < 0) - goto no_memory; + goto error; cpu->nfeatures = count; j = 0; @@ -192,8 +190,6 @@ cleanup: return cpu; -no_memory: - virReportOOMError(); error: virCPUDefFree(cpu); cpu = NULL; diff --git a/src/cpu/cpu_powerpc.c b/src/cpu/cpu_powerpc.c index d17f9ca..c0e257b 100644 --- a/src/cpu/cpu_powerpc.c +++ b/src/cpu/cpu_powerpc.c @@ -132,10 +132,8 @@ ppcVendorLoad(xmlXPathContextPtr ctxt, { struct ppc_vendor *vendor = NULL; - if (VIR_ALLOC(vendor) < 0) { - virReportOOMError(); + if (VIR_ALLOC(vendor) < 0) return -1; - } vendor->name = virXPathString("string(@name)", ctxt); if (!vendor->name) { @@ -173,10 +171,8 @@ ppcModelLoad(xmlXPathContextPtr ctxt, char *vendor = NULL; unsigned long pvr; - if (VIR_ALLOC(model) < 0) { - virReportOOMError(); + if (VIR_ALLOC(model) < 0) return -1; - } model->name = virXPathString("string(@name)", ctxt); if (!model->name) { @@ -279,10 +275,8 @@ ppcLoadMap(void) { struct ppc_map *map; - if (VIR_ALLOC(map) < 0) { - virReportOOMError(); + if (VIR_ALLOC(map) < 0) return NULL; - } if (cpuMapLoad("ppc64", ppcMapLoadCallback, map) < 0) goto error; @@ -362,10 +356,8 @@ ppcNodeData(void) { union cpuData *data; - if (VIR_ALLOC(data) < 0) { - virReportOOMError(); + if (VIR_ALLOC(data) < 0) return NULL; - } asm("mfpvr %0" : "=r" (data->ppc.pvr)); @@ -449,7 +441,7 @@ ppcBaseline(virCPUDefPtr *cpus, if (VIR_ALLOC(cpu) < 0 || VIR_STRDUP(cpu->model, model->name) < 0) - goto no_memory; + goto error; if (vendor && VIR_STRDUP(cpu->vendor, vendor->name) < 0) goto error; @@ -462,8 +454,6 @@ cleanup: return cpu; -no_memory: - virReportOOMError(); error: virCPUDefFree(cpu); cpu = NULL; diff --git a/src/cpu/cpu_s390.c b/src/cpu/cpu_s390.c index 998197c..0d578a4 100644 --- a/src/cpu/cpu_s390.c +++ b/src/cpu/cpu_s390.c @@ -36,10 +36,8 @@ s390NodeData(void) { union cpuData *data; - if (VIR_ALLOC(data) < 0) { - virReportOOMError(); + if (VIR_ALLOC(data) < 0) return NULL; - } return data; } diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c index 5d479c2..79a244e 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -252,7 +252,7 @@ x86DataExpand(union cpuData *data, if (basic_by > 0) { size_t len = data->x86.basic_len; if (VIR_EXPAND_N(data->x86.basic, data->x86.basic_len, basic_by) < 0) - goto no_memory; + return -1; for (i = 0; i < basic_by; i++) data->x86.basic[len + i].function = len + i; @@ -261,17 +261,13 @@ x86DataExpand(union cpuData *data, if (extended_by > 0) { size_t len = data->x86.extended_len; if (VIR_EXPAND_N(data->x86.extended, data->x86.extended_len, extended_by) < 0) - goto no_memory; + return -1; for (i = 0; i < extended_by; i++) data->x86.extended[len + i].function = len + i + CPUX86_EXTENDED; } return 0; - -no_memory: - virReportOOMError(); - return -1; } @@ -452,11 +448,11 @@ x86DataToCPU(const union cpuData *data, VIR_STRDUP(cpu->model, model->name) < 0 || !(copy = x86DataCopy(data)) || !(modelData = x86DataCopy(model->data))) - goto no_memory; + goto error; if ((vendor = x86DataToVendor(copy, map)) && VIR_STRDUP(cpu->vendor, vendor->name) < 0) - goto no_memory; + goto error; x86DataSubtract(copy, modelData); x86DataSubtract(modelData, data); @@ -473,8 +469,6 @@ cleanup: x86DataFree(copy); return cpu; -no_memory: - virReportOOMError(); error: virCPUDefFree(cpu); cpu = NULL; @@ -520,7 +514,7 @@ x86VendorLoad(xmlXPathContextPtr ctxt, int ret = 0; if (VIR_ALLOC(vendor) < 0) - goto no_memory; + goto error; vendor->name = virXPathString("string(@name)", ctxt); if (!vendor->name) { @@ -564,8 +558,7 @@ out: return ret; -no_memory: - virReportOOMError(); +error: ret = -1; ignore: x86VendorFree(vendor); @@ -660,7 +653,7 @@ x86FeatureLoad(xmlXPathContextPtr ctxt, int n; if (!(feature = x86FeatureNew())) - goto no_memory; + goto error; feature->name = virXPathString("string(@name)", ctxt); if (feature->name == NULL) { @@ -706,7 +699,7 @@ x86FeatureLoad(xmlXPathContextPtr ctxt, cpuid.edx = edx; if (x86DataAddCpuid(feature->data, &cpuid)) - goto no_memory; + goto error; } if (map->features == NULL) @@ -722,8 +715,7 @@ out: return ret; -no_memory: - virReportOOMError(); +error: ret = -1; ignore: @@ -813,9 +805,9 @@ x86ModelFromCPU(const virCPUDefPtr cpu, } if ((model = x86ModelCopy(model)) == NULL) - goto no_memory; + goto error; } else if (!(model = x86ModelNew())) { - goto no_memory; + goto error; } else if (cpu->type == VIR_CPU_TYPE_HOST) { return model; } @@ -834,14 +826,11 @@ x86ModelFromCPU(const virCPUDefPtr cpu, } if (x86DataAdd(model->data, feature->data)) - goto no_memory; + goto error; } return model; -no_memory: - virReportOOMError(); - error: x86ModelFree(model); return NULL; @@ -940,7 +929,7 @@ x86ModelLoad(xmlXPathContextPtr ctxt, int n; if (!(model = x86ModelNew())) - goto no_memory; + goto error; model->name = virXPathString("string(@name)", ctxt); if (model->name == NULL) { @@ -974,7 +963,7 @@ x86ModelLoad(xmlXPathContextPtr ctxt, model->vendor = ancestor->vendor; x86DataFree(model->data); if (!(model->data = x86DataCopy(ancestor->data))) - goto no_memory; + goto error; } if (virXPathBoolean("boolean(./vendor)", ctxt)) { @@ -1018,7 +1007,7 @@ x86ModelLoad(xmlXPathContextPtr ctxt, VIR_FREE(name); if (x86DataAdd(model->data, feature->data)) - goto no_memory; + goto error; } if (map->models == NULL) @@ -1033,8 +1022,7 @@ out: VIR_FREE(nodes); return ret; -no_memory: - virReportOOMError(); +error: ret = -1; ignore: @@ -1098,10 +1086,8 @@ x86LoadMap(void) { struct x86_map *map; - if (VIR_ALLOC(map) < 0) { - virReportOOMError(); + if (VIR_ALLOC(map) < 0) return NULL; - } if (cpuMapLoad("x86", x86MapLoadCallback, map) < 0) goto error; @@ -1125,12 +1111,14 @@ error: #define virX86CpuIncompatible(MSG, CPU_DEF) \ do { \ char *flagsStr = NULL; \ - if (!(flagsStr = x86FeatureNames(map, ", ", (CPU_DEF)))) \ - goto no_memory; \ + if (!(flagsStr = x86FeatureNames(map, ", ", (CPU_DEF)))) { \ + virReportOOMError(); \ + goto error; \ + } \ if (message && \ virAsprintf(message, "%s: %s", _(MSG), flagsStr) < 0) { \ VIR_FREE(flagsStr); \ - goto no_memory; \ + goto error; \ } \ VIR_DEBUG("%s: %s", MSG, flagsStr); \ VIR_FREE(flagsStr); \ @@ -1173,7 +1161,7 @@ x86Compute(virCPUDefPtr host, virAsprintf(message, _("CPU arch %s does not match host arch"), virArchToString(cpu->arch)) < 0) - goto no_memory; + goto error; return VIR_CPU_COMPARE_INCOMPATIBLE; } } @@ -1187,7 +1175,7 @@ x86Compute(virCPUDefPtr host, _("host CPU vendor does not match required " "CPU vendor %s"), cpu->vendor) < 0) - goto no_memory; + goto error; return VIR_CPU_COMPARE_INCOMPATIBLE; } @@ -1220,7 +1208,7 @@ x86Compute(virCPUDefPtr host, ret = VIR_CPU_COMPARE_IDENTICAL; if ((diff = x86ModelCopy(host_model)) == NULL) - goto no_memory; + goto error; x86DataSubtract(diff->data, cpu_optional->data); x86DataSubtract(diff->data, cpu_require->data); @@ -1241,19 +1229,19 @@ x86Compute(virCPUDefPtr host, if (guest != NULL) { if ((guest_model = x86ModelCopy(host_model)) == NULL) - goto no_memory; + goto error; if (cpu->type == VIR_CPU_TYPE_GUEST && cpu->match == VIR_CPU_MATCH_EXACT) x86DataSubtract(guest_model->data, diff->data); if (x86DataAdd(guest_model->data, cpu_force->data)) - goto no_memory; + goto error; x86DataSubtract(guest_model->data, cpu_disable->data); if ((*guest = x86DataCopy(guest_model->data)) == NULL) - goto no_memory; + goto error; } out: @@ -1269,9 +1257,6 @@ out: return ret; -no_memory: - virReportOOMError(); - error: ret = VIR_CPU_COMPARE_ERROR; goto out; @@ -1481,7 +1466,6 @@ x86Encode(const virCPUDefPtr cpu, if (v && (VIR_ALLOC(data_vendor) < 0 || x86DataAddCpuid(data_vendor, &v->cpuid) < 0)) { - virReportOOMError(); goto error; } } @@ -1562,10 +1546,8 @@ cpuidSet(uint32_t base, struct cpuX86cpuid **set) cpuidCall(&cpuid); max = cpuid.eax - base; - if (VIR_ALLOC_N(*set, max + 1) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(*set, max + 1) < 0) return -1; - } for (i = 0; i <= max; i++) { cpuid.function = base | i; @@ -1583,10 +1565,8 @@ x86NodeData(void) union cpuData *data; int ret; - if (VIR_ALLOC(data) < 0) { - virReportOOMError(); + if (VIR_ALLOC(data) < 0) return NULL; - } if ((ret = cpuidSet(CPUX86_BASIC, &data->x86.basic)) < 0) goto error; @@ -1627,7 +1607,7 @@ x86Baseline(virCPUDefPtr *cpus, goto error; if (VIR_ALLOC(cpu) < 0) - goto no_memory; + goto error; cpu->arch = cpus[0]->arch; cpu->type = VIR_CPU_TYPE_GUEST; @@ -1689,7 +1669,7 @@ x86Baseline(virCPUDefPtr *cpus, } if (vendor && x86DataAddCpuid(base_model->data, &vendor->cpuid) < 0) - goto no_memory; + goto error; if (x86Decode(cpu, base_model->data, models, nmodels, NULL) < 0) goto error; @@ -1705,8 +1685,6 @@ cleanup: return cpu; -no_memory: - virReportOOMError(); error: x86ModelFree(model); virCPUDefFree(cpu); -- 1.8.1.5

On 07/04/2013 02:06 PM, Michal Privoznik wrote:
--- src/cpu/cpu.c | 4 +-- src/cpu/cpu_arm.c | 6 +--- src/cpu/cpu_generic.c | 12 +++---- src/cpu/cpu_powerpc.c | 20 +++--------- src/cpu/cpu_s390.c | 4 +-- src/cpu/cpu_x86.c | 86 +++++++++++++++++++-------------------------------- 6 files changed, 44 insertions(+), 88 deletions(-)
ACK Jan

--- src/esx/esx_driver.c | 62 ++++++++--------------------- src/esx/esx_network_driver.c | 16 ++------ src/esx/esx_storage_backend_iscsi.c | 4 +- src/esx/esx_storage_backend_vmfs.c | 78 +++++++++---------------------------- src/esx/esx_util.c | 4 +- src/esx/esx_vi.c | 50 +++++++----------------- src/esx/esx_vi.h | 3 +- src/esx/esx_vi_types.c | 3 +- 8 files changed, 60 insertions(+), 160 deletions(-) diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index a5df810..26a3f1d 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -146,10 +146,8 @@ esxParseVMXFileName(const char *fileName, void *opaque) if (strchr(fileName, '/') == NULL && strchr(fileName, '\\') == NULL) { /* Plain file name, use same directory as for the .vmx file */ if (virAsprintf(&result, "%s/%s", - data->datastorePathWithoutFileName, fileName) < 0) { - virReportOOMError(); + data->datastorePathWithoutFileName, fileName) < 0) goto cleanup; - } } else { if (esxVI_String_AppendValueToList(&propertyNameList, "summary.name") < 0 || @@ -199,10 +197,8 @@ esxParseVMXFileName(const char *fileName, void *opaque) } if (virAsprintf(&result, "[%s] %s", datastoreName, - strippedFileName) < 0) { - virReportOOMError(); + strippedFileName) < 0) goto cleanup; - } break; } @@ -239,10 +235,8 @@ esxParseVMXFileName(const char *fileName, void *opaque) } if (virAsprintf(&result, "[%s] %s", datastoreName, - directoryAndFileName) < 0) { - virReportOOMError(); + directoryAndFileName) < 0) goto cleanup; - } } /* If it's an absolute path outside of a datastore just use it as is */ @@ -587,10 +581,8 @@ esxCapsInit(esxPrivate *priv) caps = virCapabilitiesNew(VIR_ARCH_I686, 1, 1); } - if (caps == NULL) { - virReportOOMError(); + if (caps == NULL) return NULL; - } virCapabilitiesAddHostMigrateTransport(caps, "vpxmigr"); @@ -695,10 +687,8 @@ esxConnectToHost(esxPrivate *priv, } if (virAsprintf(&url, "%s://%s:%d/sdk", priv->parsedUri->transport, - conn->uri->server, conn->uri->port) < 0) { - virReportOOMError(); + conn->uri->server, conn->uri->port) < 0) goto cleanup; - } if (esxVI_Context_Alloc(&priv->host) < 0 || esxVI_Context_Connect(priv->host, url, ipAddress, username, password, @@ -818,10 +808,8 @@ esxConnectToVCenter(esxPrivate *priv, } if (virAsprintf(&url, "%s://%s:%d/sdk", priv->parsedUri->transport, - hostname, conn->uri->port) < 0) { - virReportOOMError(); + hostname, conn->uri->port) < 0) goto cleanup; - } if (esxVI_Context_Alloc(&priv->vCenter) < 0 || esxVI_Context_Connect(priv->vCenter, url, ipAddress, username, @@ -973,10 +961,8 @@ esxConnectOpen(virConnectPtr conn, virConnectAuthPtr auth, } /* Allocate per-connection private data */ - if (VIR_ALLOC(priv) < 0) { - virReportOOMError(); + if (VIR_ALLOC(priv) < 0) goto cleanup; - } if (esxUtil_ParseUri(&priv->parsedUri, conn->uri) < 0) { goto cleanup; @@ -1269,10 +1255,8 @@ esxConnectGetHostname(virConnectPtr conn) if (VIR_STRDUP(complete, hostName) < 0) goto cleanup; } else { - if (virAsprintf(&complete, "%s.%s", hostName, domainName) < 0) { - virReportOOMError(); + if (virAsprintf(&complete, "%s.%s", hostName, domainName) < 0) goto cleanup; - } } cleanup: @@ -2739,16 +2723,12 @@ esxDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) if (directoryName == NULL) { if (virAsprintf(&data.datastorePathWithoutFileName, "[%s]", - datastoreName) < 0) { - virReportOOMError(); + datastoreName) < 0) goto cleanup; - } } else { if (virAsprintf(&data.datastorePathWithoutFileName, "[%s] %s", - datastoreName, directoryName) < 0) { - virReportOOMError(); + datastoreName, directoryName) < 0) goto cleanup; - } } ctx.opaque = &data; @@ -3213,16 +3193,12 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml) /* Register the domain */ if (directoryName != NULL) { if (virAsprintf(&datastoreRelatedPath, "[%s] %s/%s.vmx", datastoreName, - directoryName, escapedName) < 0) { - virReportOOMError(); + directoryName, escapedName) < 0) goto cleanup; - } } else { if (virAsprintf(&datastoreRelatedPath, "[%s] %s.vmx", datastoreName, - escapedName) < 0) { - virReportOOMError(); + escapedName) < 0) goto cleanup; - } } if (esxVI_RegisterVM_Task(priv->primary, priv->primary->datacenter->vmFolder, @@ -3860,10 +3836,8 @@ esxDomainMigratePrepare(virConnectPtr dconn, if (virAsprintf(uri_out, "vpxmigr://%s/%s/%s", priv->vCenter->ipAddress, priv->vCenter->computeResource->resourcePool->value, - priv->vCenter->hostSystem->_reference->value) < 0) { - virReportOOMError(); + priv->vCenter->hostSystem->_reference->value) < 0) return -1; - } } return 0; @@ -5020,7 +4994,7 @@ esxConnectListAllDomains(virConnectPtr conn, !MATCH(VIR_CONNECT_LIST_DOMAINS_NO_MANAGEDSAVE))) { if (domains && VIR_ALLOC_N(*domains, 1) < 0) - goto no_memory; + goto cleanup; ret = 0; goto cleanup; @@ -5074,7 +5048,7 @@ esxConnectListAllDomains(virConnectPtr conn, if (domains) { if (VIR_ALLOC_N(doms, 1) < 0) - goto no_memory; + goto cleanup; ndoms = 1; } @@ -5167,7 +5141,7 @@ esxConnectListAllDomains(virConnectPtr conn, } if (VIR_RESIZE_N(doms, ndoms, count, 2) < 0) - goto no_memory; + goto cleanup; if (!(dom = virGetDomain(conn, name, uuid))) goto cleanup; @@ -5203,10 +5177,6 @@ cleanup: esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotTreeList); return ret; - -no_memory: - virReportOOMError(); - goto cleanup; } #undef MATCH diff --git a/src/esx/esx_network_driver.c b/src/esx/esx_network_driver.c index 9aacffc..d51aad1 100644 --- a/src/esx/esx_network_driver.c +++ b/src/esx/esx_network_driver.c @@ -642,10 +642,8 @@ esxShapingPolicyToBandwidth(esxVI_HostNetworkTrafficShapingPolicy *shapingPolicy if (VIR_ALLOC(*bandwidth) < 0 || VIR_ALLOC((*bandwidth)->in) < 0 || - VIR_ALLOC((*bandwidth)->out) < 0) { - virReportOOMError(); + VIR_ALLOC((*bandwidth)->out) < 0) return -1; - } if (shapingPolicy->averageBandwidth != NULL) { /* Scale bits per second to kilobytes per second */ @@ -694,10 +692,8 @@ esxNetworkGetXMLDesc(virNetworkPtr network_, unsigned int flags) return NULL; } - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) goto cleanup; - } /* Lookup HostVirtualSwitch */ if (esxVI_LookupHostVirtualSwitchByName(priv->primary, network_->name, @@ -724,10 +720,8 @@ esxNetworkGetXMLDesc(virNetworkPtr network_, unsigned int flags) if (count > 0) { def->forward.type = VIR_NETWORK_FORWARD_BRIDGE; - if (VIR_ALLOC_N(def->forward.ifs, count) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(def->forward.ifs, count) < 0) goto cleanup; - } /* Find PhysicalNic by key */ if (esxVI_LookupPhysicalNicList(priv->primary, &physicalNicList) < 0) { @@ -772,10 +766,8 @@ esxNetworkGetXMLDesc(virNetworkPtr network_, unsigned int flags) } if (count > 0) { - if (VIR_ALLOC_N(def->portGroups, count) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(def->portGroups, count) < 0) goto cleanup; - } /* Lookup Network list and create name list */ if (esxVI_String_AppendValueToList(&propertyNameList, "name") < 0 || diff --git a/src/esx/esx_storage_backend_iscsi.c b/src/esx/esx_storage_backend_iscsi.c index 6e1095e..346596f 100644 --- a/src/esx/esx_storage_backend_iscsi.c +++ b/src/esx/esx_storage_backend_iscsi.c @@ -334,10 +334,8 @@ esxStoragePoolGetXMLDesc(virStoragePoolPtr pool, unsigned int flags) def.source.nhost = 1; - if (VIR_ALLOC_N(def.source.hosts, def.source.nhost) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(def.source.hosts, def.source.nhost) < 0) goto cleanup; - } def.source.hosts[0].name = target->address; diff --git a/src/esx/esx_storage_backend_vmfs.c b/src/esx/esx_storage_backend_vmfs.c index 2966109..dc2b308 100644 --- a/src/esx/esx_storage_backend_vmfs.c +++ b/src/esx/esx_storage_backend_vmfs.c @@ -484,10 +484,8 @@ esxStoragePoolGetXMLDesc(virStoragePoolPtr pool, unsigned int flags) if (esxVI_LocalDatastoreInfo_DynamicCast(info) != NULL) { def.type = VIR_STORAGE_POOL_DIR; } else if ((nasInfo = esxVI_NasDatastoreInfo_DynamicCast(info)) != NULL) { - if (VIR_ALLOC_N(def.source.hosts, 1) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(def.source.hosts, 1) < 0) goto cleanup; - } def.type = VIR_STORAGE_POOL_NETFS; def.source.hosts[0].name = nasInfo->nas->remoteHost; def.source.dir = nasInfo->nas->remotePath; @@ -614,10 +612,8 @@ esxStoragePoolListVolumes(virStoragePoolPtr pool, char **const names, if (VIR_STRDUP(names[count], fileInfo->path) < 0) goto cleanup; } else if (virAsprintf(&names[count], "%s/%s", directoryAndFileName, - fileInfo->path) < 0) { - virReportOOMError(); + fileInfo->path) < 0) goto cleanup; - } ++count; } @@ -651,10 +647,8 @@ esxStorageVolLookupByName(virStoragePoolPtr pool, char *datastorePath = NULL; char *key = NULL; - if (virAsprintf(&datastorePath, "[%s] %s", pool->name, name) < 0) { - virReportOOMError(); + if (virAsprintf(&datastorePath, "[%s] %s", pool->name, name) < 0) goto cleanup; - } if (esxVI_LookupStorageVolumeKeyByDatastorePath(priv->primary, datastorePath, &key) < 0) { @@ -788,16 +782,12 @@ esxStorageVolLookupByKey(virConnectPtr conn, const char *key) goto cleanup; } else if (virAsprintf(&volumeName, "%s/%s", directoryAndFileName, - fileInfo->path) < 0) { - virReportOOMError(); + fileInfo->path) < 0) goto cleanup; - } if (virAsprintf(&datastorePath, "[%s] %s", datastoreName, - volumeName) < 0) { - virReportOOMError(); + volumeName) < 0) goto cleanup; - } if (esxVI_VmDiskFileInfo_DynamicCast(fileInfo) == NULL) { /* Only a VirtualDisk has a UUID */ @@ -907,10 +897,8 @@ esxStorageVolCreateXML(virStoragePoolPtr pool, } if (virAsprintf(&unescapedDatastorePath, "[%s] %s", pool->name, - def->name) < 0) { - virReportOOMError(); + def->name) < 0) goto cleanup; - } if (def->target.format == VIR_STORAGE_FILE_VMDK) { /* Parse and escape datastore path */ @@ -934,16 +922,12 @@ esxStorageVolCreateXML(virStoragePoolPtr pool, } if (virAsprintf(&datastorePathWithoutFileName, "[%s] %s", pool->name, - directoryName) < 0) { - virReportOOMError(); + directoryName) < 0) goto cleanup; - } if (virAsprintf(&datastorePath, "[%s] %s/%s", pool->name, directoryName, - fileName) < 0) { - virReportOOMError(); + fileName) < 0) goto cleanup; - } /* Create directory, if it doesn't exist yet */ if (esxVI_LookupFileInfoByDatastorePath @@ -1015,10 +999,8 @@ esxStorageVolCreateXML(virStoragePoolPtr pool, } if (priv->primary->hasQueryVirtualDiskUuid) { - if (VIR_ALLOC_N(key, VIR_UUID_STRING_BUFLEN) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(key, VIR_UUID_STRING_BUFLEN) < 0) goto cleanup; - } if (esxVI_QueryVirtualDiskUuid(priv->primary, datastorePath, priv->primary->datacenter->_reference, @@ -1107,10 +1089,8 @@ esxStorageVolCreateXMLFrom(virStoragePoolPtr pool, } if (virAsprintf(&sourceDatastorePath, "[%s] %s", sourceVolume->pool, - sourceVolume->name) < 0) { - virReportOOMError(); + sourceVolume->name) < 0) goto cleanup; - } /* Parse config */ def = virStorageVolDefParseString(&poolDef, xmldesc); @@ -1143,10 +1123,8 @@ esxStorageVolCreateXMLFrom(virStoragePoolPtr pool, } if (virAsprintf(&unescapedDatastorePath, "[%s] %s", pool->name, - def->name) < 0) { - virReportOOMError(); + def->name) < 0) goto cleanup; - } if (def->target.format == VIR_STORAGE_FILE_VMDK) { /* Parse and escape datastore path */ @@ -1170,16 +1148,12 @@ esxStorageVolCreateXMLFrom(virStoragePoolPtr pool, } if (virAsprintf(&datastorePathWithoutFileName, "[%s] %s", pool->name, - directoryName) < 0) { - virReportOOMError(); + directoryName) < 0) goto cleanup; - } if (virAsprintf(&datastorePath, "[%s] %s/%s", pool->name, directoryName, - fileName) < 0) { - virReportOOMError(); + fileName) < 0) goto cleanup; - } /* Create directory, if it doesn't exist yet */ if (esxVI_LookupFileInfoByDatastorePath @@ -1217,10 +1191,8 @@ esxStorageVolCreateXMLFrom(virStoragePoolPtr pool, } if (priv->primary->hasQueryVirtualDiskUuid) { - if (VIR_ALLOC_N(key, VIR_UUID_STRING_BUFLEN) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(key, VIR_UUID_STRING_BUFLEN) < 0) goto cleanup; - } if (esxVI_QueryVirtualDiskUuid(priv->primary, datastorePath, priv->primary->datacenter->_reference, @@ -1280,10 +1252,8 @@ esxStorageVolDelete(virStorageVolPtr volume, unsigned int flags) virCheckFlags(0, -1); - if (virAsprintf(&datastorePath, "[%s] %s", volume->pool, volume->name) < 0) { - virReportOOMError(); + if (virAsprintf(&datastorePath, "[%s] %s", volume->pool, volume->name) < 0) goto cleanup; - } if (esxVI_DeleteVirtualDisk_Task(priv->primary, datastorePath, priv->primary->datacenter->_reference, @@ -1325,10 +1295,8 @@ esxStorageVolWipe(virStorageVolPtr volume, unsigned int flags) virCheckFlags(0, -1); - if (virAsprintf(&datastorePath, "[%s] %s", volume->pool, volume->name) < 0) { - virReportOOMError(); + if (virAsprintf(&datastorePath, "[%s] %s", volume->pool, volume->name) < 0) goto cleanup; - } if (esxVI_ZeroFillVirtualDisk_Task(priv->primary, datastorePath, priv->primary->datacenter->_reference, @@ -1370,10 +1338,8 @@ esxStorageVolGetInfo(virStorageVolPtr volume, memset(info, 0, sizeof(*info)); - if (virAsprintf(&datastorePath, "[%s] %s", volume->pool, volume->name) < 0) { - virReportOOMError(); + if (virAsprintf(&datastorePath, "[%s] %s", volume->pool, volume->name) < 0) goto cleanup; - } if (esxVI_LookupFileInfoByDatastorePath(priv->primary, datastorePath, false, &fileInfo, @@ -1430,10 +1396,8 @@ esxStorageVolGetXMLDesc(virStorageVolPtr volume, } /* Lookup file info */ - if (virAsprintf(&datastorePath, "[%s] %s", volume->pool, volume->name) < 0) { - virReportOOMError(); + if (virAsprintf(&datastorePath, "[%s] %s", volume->pool, volume->name) < 0) goto cleanup; - } if (esxVI_LookupFileInfoByDatastorePath(priv->primary, datastorePath, false, &fileInfo, @@ -1494,11 +1458,7 @@ esxStorageVolGetPath(virStorageVolPtr volume) { char *path; - if (virAsprintf(&path, "[%s] %s", volume->pool, volume->name) < 0) { - virReportOOMError(); - return NULL; - } - + ignore_value(virAsprintf(&path, "[%s] %s", volume->pool, volume->name)); return path; } diff --git a/src/esx/esx_util.c b/src/esx/esx_util.c index a4b931d..536864d 100644 --- a/src/esx/esx_util.c +++ b/src/esx/esx_util.c @@ -54,10 +54,8 @@ esxUtil_ParseUri(esxUtil_ParsedUri **parsedUri, virURIPtr uri) return -1; } - if (VIR_ALLOC(*parsedUri) < 0) { - virReportOOMError(); + if (VIR_ALLOC(*parsedUri) < 0) return -1; - } for (i = 0; i < uri->paramsCount; i++) { virURIParamPtr queryParam = &uri->params[i]; diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c index 39420b6..e4a58c4 100644 --- a/src/esx/esx_vi.c +++ b/src/esx/esx_vi.c @@ -51,7 +51,8 @@ int \ esxVI_##_type##_Alloc(esxVI_##_type **ptrptr) \ { \ - return esxVI_Alloc((void **)ptrptr, sizeof(esxVI_##_type)); \ + return esxVI_Alloc((void **)ptrptr, sizeof(esxVI_##_type), \ + __FILE__, __FUNCTION__, __LINE__); \ } @@ -392,15 +393,11 @@ esxVI_CURL_Download(esxVI_CURL *curl, const char *url, char **content, return -1; } - if (virAsprintf(&range, "%llu-%llu", offset, offset + *length - 1) < 0) { - virReportOOMError(); + if (virAsprintf(&range, "%llu-%llu", offset, offset + *length - 1) < 0) goto cleanup; - } } else if (offset > 0) { - if (virAsprintf(&range, "%llu-", offset) < 0) { - virReportOOMError(); + if (virAsprintf(&range, "%llu-", offset) < 0) goto cleanup; - } } virMutexLock(&curl->lock); @@ -808,10 +805,8 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *url, return -1; } - if (VIR_ALLOC(ctx->sessionLock) < 0) { - virReportOOMError(); + if (VIR_ALLOC(ctx->sessionLock) < 0) return -1; - } if (virMutexInit(ctx->sessionLock) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -1315,10 +1310,8 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName, } else { if (virAsprintf(&xpathExpression, "/soapenv:Envelope/soapenv:Body/vim:%sResponse", - methodName) < 0) { - virReportOOMError(); + methodName) < 0) goto cleanup; - } responseNode = virXPathNode(xpathExpression, xpathContext); @@ -1743,19 +1736,16 @@ esxVI_List_Deserialize(xmlNodePtr node, esxVI_List **list, */ int -esxVI_Alloc(void **ptrptr, size_t size) +esxVI_Alloc(void **ptrptr, size_t size, const char *file, + const char *function, size_t linenr) { if (ptrptr == NULL || *ptrptr != NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); return -1; } - if (virAllocN(ptrptr, size, 1, false, 0, NULL, NULL, 0) < 0) { - virReportOOMError(); - return -1; - } - - return 0; + return virAllocN(ptrptr, size, 1, true, VIR_FROM_THIS, + file, function, linenr); } @@ -3480,20 +3470,16 @@ esxVI_LookupFileInfoByDatastorePath(esxVI_Context *ctx, * that the <path> part is actually the file name. */ if (virAsprintf(&datastorePathWithoutFileName, "[%s]", - datastoreName) < 0) { - virReportOOMError(); + datastoreName) < 0) goto cleanup; - } if (VIR_STRDUP(fileName, directoryAndFileName) < 0) { goto cleanup; } } else { if (virAsprintf(&datastorePathWithoutFileName, "[%s] %s", - datastoreName, directoryName) < 0) { - virReportOOMError(); + datastoreName, directoryName) < 0) goto cleanup; - } length = strlen(directoryName); @@ -3715,10 +3701,8 @@ esxVI_LookupDatastoreContentByDatastoreName } /* Search datastore for files */ - if (virAsprintf(&datastorePath, "[%s]", datastoreName) < 0) { - virReportOOMError(); + if (virAsprintf(&datastorePath, "[%s]", datastoreName) < 0) goto cleanup; - } if (esxVI_SearchDatastoreSubFolders_Task(ctx, hostDatastoreBrowser, datastorePath, searchSpec, @@ -3788,10 +3772,8 @@ esxVI_LookupStorageVolumeKeyByDatastorePath(esxVI_Context *ctx, goto cleanup; } - if (VIR_ALLOC_N(*key, VIR_UUID_STRING_BUFLEN) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(*key, VIR_UUID_STRING_BUFLEN) < 0) goto cleanup; - } if (esxUtil_ReformatUuid(uuid_string, *key) < 0) { goto cleanup; @@ -4493,10 +4475,8 @@ esxVI_WaitForTaskCompletion(esxVI_Context *ctx, } else { if (virAsprintf(errorMessage, "%s - %s", taskInfo->error->fault->_actualType, - taskInfo->error->localizedMessage) < 0) { - virReportOOMError(); + taskInfo->error->localizedMessage) < 0) goto cleanup; - } } } diff --git a/src/esx/esx_vi.h b/src/esx/esx_vi.h index 3eaeb38..c1612e2 100644 --- a/src/esx/esx_vi.h +++ b/src/esx/esx_vi.h @@ -330,7 +330,8 @@ int esxVI_List_Deserialize(xmlNodePtr node, esxVI_List **list, * - 'get' functions get information from a local object */ -int esxVI_Alloc(void **ptrptr, size_t size); +int esxVI_Alloc(void **ptrptr, size_t size, const char *file, + const char *function, size_t linenr); int esxVI_BuildSelectSet (esxVI_SelectionSpec **selectSet, const char *name, diff --git a/src/esx/esx_vi_types.c b/src/esx/esx_vi_types.c index 7908b1c..14caeeb 100644 --- a/src/esx/esx_vi_types.c +++ b/src/esx/esx_vi_types.c @@ -43,7 +43,8 @@ int \ esxVI_##__type##_Alloc(esxVI_##__type **ptrptr) \ { \ - if (esxVI_Alloc((void **)ptrptr, sizeof(esxVI_##__type)) < 0) { \ + if (esxVI_Alloc((void **)ptrptr, sizeof(esxVI_##__type), \ + __FILE__, __FUNCTION__, __LINE__) < 0) { \ return -1; \ } \ \ -- 1.8.1.5

On 07/04/2013 02:06 PM, Michal Privoznik wrote:
--- src/esx/esx_driver.c | 62 ++++++++--------------------- src/esx/esx_network_driver.c | 16 ++------ src/esx/esx_storage_backend_iscsi.c | 4 +- src/esx/esx_storage_backend_vmfs.c | 78 +++++++++---------------------------- src/esx/esx_util.c | 4 +- src/esx/esx_vi.c | 50 +++++++----------------- src/esx/esx_vi.h | 3 +- src/esx/esx_vi_types.c | 3 +- 8 files changed, 60 insertions(+), 160 deletions(-)
@@ -614,10 +612,8 @@ esxStoragePoolListVolumes(virStoragePoolPtr pool, char **const names, if (VIR_STRDUP(names[count], fileInfo->path) < 0) goto cleanup; } else if (virAsprintf(&names[count], "%s/%s", directoryAndFileName, - fileInfo->path) < 0) { - virReportOOMError(); + fileInfo->path) < 0) goto cleanup; - }
Leave the braces since the 'if' branch has them too.
++count; }
@@ -788,16 +782,12 @@ esxStorageVolLookupByKey(virConnectPtr conn, const char *key) goto cleanup; } else if (virAsprintf(&volumeName, "%s/%s", directoryAndFileName, - fileInfo->path) < 0) { - virReportOOMError(); + fileInfo->path) < 0) goto cleanup; - }
Same here.
if (virAsprintf(&datastorePath, "[%s] %s", datastoreName, - volumeName) < 0) { - virReportOOMError(); + volumeName) < 0) goto cleanup; - }
if (esxVI_VmDiskFileInfo_DynamicCast(fileInfo) == NULL) { /* Only a VirtualDisk has a UUID */
ACK Jan

--- src/hyperv/hyperv_driver.c | 21 ++++++--------------- src/hyperv/hyperv_util.c | 4 +--- src/hyperv/hyperv_wmi.c | 8 ++------ 3 files changed, 9 insertions(+), 24 deletions(-) diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c index dd8d018..389a151 100644 --- a/src/hyperv/hyperv_driver.c +++ b/src/hyperv/hyperv_driver.c @@ -117,10 +117,8 @@ hypervConnectOpen(virConnectPtr conn, virConnectAuthPtr auth, unsigned int flags } /* Allocate per-connection private data */ - if (VIR_ALLOC(priv) < 0) { - virReportOOMError(); + if (VIR_ALLOC(priv) < 0) goto cleanup; - } if (hypervParseUri(&priv->parsedUri, conn->uri) < 0) { goto cleanup; @@ -802,10 +800,8 @@ hypervDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) /* Flags checked by virDomainDefFormat */ - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) goto cleanup; - } virUUIDFormat(domain->uuid, uuid_string); @@ -1255,9 +1251,8 @@ hypervConnectListAllDomains(virConnectPtr conn, !MATCH(VIR_CONNECT_LIST_DOMAINS_NO_AUTOSTART)) || (MATCH(VIR_CONNECT_LIST_DOMAINS_HAS_SNAPSHOT) && !MATCH(VIR_CONNECT_LIST_DOMAINS_NO_SNAPSHOT))) { - if (domains && - VIR_ALLOC_N(*domains, 1) < 0) - goto no_memory; + if (domains && VIR_ALLOC_N(*domains, 1) < 0) + goto cleanup; ret = 0; goto cleanup; @@ -1287,7 +1282,7 @@ hypervConnectListAllDomains(virConnectPtr conn, if (domains) { if (VIR_ALLOC_N(doms, 1) < 0) - goto no_memory; + goto cleanup; ndoms = 1; } @@ -1326,7 +1321,7 @@ hypervConnectListAllDomains(virConnectPtr conn, } if (VIR_RESIZE_N(doms, ndoms, count, 2) < 0) - goto no_memory; + goto cleanup; domain = NULL; @@ -1354,10 +1349,6 @@ cleanup: hypervFreeObject(priv, (hypervObject *)computerSystemList); return ret; - -no_memory: - virReportOOMError(); - goto cleanup; } #undef MATCH diff --git a/src/hyperv/hyperv_util.c b/src/hyperv/hyperv_util.c index b7c2a17..53c0530 100644 --- a/src/hyperv/hyperv_util.c +++ b/src/hyperv/hyperv_util.c @@ -46,10 +46,8 @@ hypervParseUri(hypervParsedUri **parsedUri, virURIPtr uri) return -1; } - if (VIR_ALLOC(*parsedUri) < 0) { - virReportOOMError(); + if (VIR_ALLOC(*parsedUri) < 0) return -1; - } for (i = 0; i < uri->paramsCount; i++) { virURIParamPtr queryParam = &uri->params[i]; diff --git a/src/hyperv/hyperv_wmi.c b/src/hyperv/hyperv_wmi.c index 65fc83d..39eed0c 100644 --- a/src/hyperv/hyperv_wmi.c +++ b/src/hyperv/hyperv_wmi.c @@ -210,10 +210,8 @@ hypervEnumAndPull(hypervPrivate *priv, virBufferPtr query, const char *root, goto cleanup; } - if (VIR_ALLOC(object) < 0) { - virReportOOMError(); + if (VIR_ALLOC(object) < 0) goto cleanup; - } object->serializerInfo = serializerInfo; object->data = data; @@ -414,10 +412,8 @@ hypervInvokeMsvmComputerSystemRequestStateChange(virDomainPtr domain, if (virAsprintf(&selector, "Name=%s&CreationClassName=Msvm_ComputerSystem", uuid_string) < 0 || - virAsprintf(&properties, "RequestedState=%d", requestedState) < 0) { - virReportOOMError(); + virAsprintf(&properties, "RequestedState=%d", requestedState) < 0) goto cleanup; - } options = wsmc_options_init(); -- 1.8.1.5

On 07/04/13 14:06, Michal Privoznik wrote:
--- src/hyperv/hyperv_driver.c | 21 ++++++--------------- src/hyperv/hyperv_util.c | 4 +--- src/hyperv/hyperv_wmi.c | 8 ++------ 3 files changed, 9 insertions(+), 24 deletions(-)
ACK, Peter

--- src/interface/interface_backend_netcf.c | 19 ++++--------------- src/interface/interface_backend_udev.c | 33 +++++++++------------------------ 2 files changed, 13 insertions(+), 39 deletions(-) diff --git a/src/interface/interface_backend_netcf.c b/src/interface/interface_backend_netcf.c index 760540a..5a74b7a 100644 --- a/src/interface/interface_backend_netcf.c +++ b/src/interface/interface_backend_netcf.c @@ -65,10 +65,8 @@ netcfGetMinimalDefForDevice(struct netcf_if *iface) virInterfaceDef *def; /* Allocate our interface definition structure */ - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } if (VIR_STRDUP(def->name, ncf_if_name(iface)) < 0) goto cleanup; @@ -157,10 +155,7 @@ static virDrvOpenStatus netcfInterfaceOpen(virConnectPtr conn, virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); if (VIR_ALLOC(driverState) < 0) - { - virReportOOMError(); goto alloc_error; - } /* initialize non-0 stuff in driverState */ if (virMutexInit(&driverState->lock) < 0) @@ -519,10 +514,8 @@ netcfConnectListAllInterfaces(virConnectPtr conn, goto cleanup; } - if (VIR_ALLOC_N(names, count) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(names, count) < 0) goto cleanup; - } if ((count = ncf_list_interfaces(driver->netcf, count, names, NETCF_IFACE_ACTIVE | @@ -536,12 +529,8 @@ netcfConnectListAllInterfaces(virConnectPtr conn, goto cleanup; } - if (ifaces) { - if (VIR_ALLOC_N(tmp_iface_objs, count + 1) < 0) { - virReportOOMError(); - goto cleanup; - } - } + if (ifaces && VIR_ALLOC_N(tmp_iface_objs, count + 1) < 0) + goto cleanup; for (i = 0; i < count; i++) { virInterfaceDefPtr def; diff --git a/src/interface/interface_backend_udev.c b/src/interface/interface_backend_udev.c index 6270c9d..f78e616 100644 --- a/src/interface/interface_backend_udev.c +++ b/src/interface/interface_backend_udev.c @@ -73,10 +73,8 @@ udevGetMinimalDefForDevice(struct udev_device *dev) virInterfaceDef *def; /* Allocate our interface definition structure */ - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } if (VIR_STRDUP(def->name, udev_device_get_sysname(dev)) < 0) goto cleanup; @@ -141,10 +139,8 @@ udevInterfaceOpen(virConnectPtr conn, virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); - if (VIR_ALLOC(driverState) < 0) { - virReportOOMError(); + if (VIR_ALLOC(driverState) < 0) goto cleanup; - } driverState->udev = udev_new(); if (!driverState->udev) { @@ -403,12 +399,9 @@ udevConnectListAllInterfaces(virConnectPtr conn, } /* If we're asked for the ifaces then alloc up memory */ - if (ifaces) { - if (VIR_ALLOC_N(ifaces_list, count + 1) < 0) { - virReportOOMError(); - ret = -1; - goto cleanup; - } + if (ifaces && VIR_ALLOC_N(ifaces_list, count + 1) < 0) { + ret = -1; + goto cleanup; } /* Get a list we can walk */ @@ -815,10 +808,8 @@ udevGetIfaceDefBond(struct udev *udev, } /* Allocate our list of slave devices */ - if (VIR_ALLOC_N(ifacedef->data.bond.itf, slave_count) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(ifacedef->data.bond.itf, slave_count) < 0) goto error; - } ifacedef->data.bond.nbItf = slave_count; for (i = 0; i < slave_count; i++) { @@ -918,10 +909,8 @@ udevGetIfaceDefBridge(struct udev *udev, /* Members of the bridge */ if (virAsprintf(&member_path, "%s/%s", - udev_device_get_syspath(dev), "brif") < 0) { - virReportOOMError(); + udev_device_get_syspath(dev), "brif") < 0) goto error; - } /* Get each member of the bridge */ member_count = scandir(member_path, &member_list, @@ -938,10 +927,8 @@ udevGetIfaceDefBridge(struct udev *udev, } /* Allocate our list of member devices */ - if (VIR_ALLOC_N(ifacedef->data.bridge.itf, member_count) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(ifacedef->data.bridge.itf, member_count) < 0) goto error; - } ifacedef->data.bridge.nbItf = member_count; /* Get the interface defintions for each member of the bridge */ @@ -1016,10 +1003,8 @@ udevGetIfaceDef(struct udev *udev, const char *name) const char *devtype; /* Allocate our interface definition structure */ - if (VIR_ALLOC(ifacedef) < 0) { - virReportOOMError(); + if (VIR_ALLOC(ifacedef) < 0) return NULL; - } /* Clear our structure and set safe defaults */ ifacedef->startmode = VIR_INTERFACE_START_UNSPECIFIED; -- 1.8.1.5

On 07/04/2013 02:06 PM, Michal Privoznik wrote:
--- src/interface/interface_backend_netcf.c | 19 ++++--------------- src/interface/interface_backend_udev.c | 33 +++++++++------------------------ 2 files changed, 13 insertions(+), 39 deletions(-)
You missed double OOM error reporting in netcfConnectNumOfInterfacesImpl and netcfConnectListInterfacesImpl. ACK with that fixed. Jan

--- src/libxl/libxl_conf.c | 18 +++++------------- src/libxl/libxl_driver.c | 46 +++++++++++----------------------------------- 2 files changed, 16 insertions(+), 48 deletions(-) diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index e170357..1b27b6f 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -278,12 +278,11 @@ libxlMakeCapabilitiesInternal(virArch hostarch, host_pae, guest_archs, nr_guest_archs)) == NULL) - goto no_memory; + goto error; return caps; - no_memory: - virReportOOMError(); + error: virObjectUnref(caps); return NULL; } @@ -576,10 +575,8 @@ libxlMakeDiskList(virDomainDefPtr def, libxl_domain_config *d_config) libxl_device_disk *x_disks; int i; - if (VIR_ALLOC_N(x_disks, ndisks) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(x_disks, ndisks) < 0) return -1; - } for (i = 0; i < ndisks; i++) { if (libxlMakeDisk(l_disks[i], &x_disks[i]) < 0) @@ -648,10 +645,8 @@ libxlMakeNicList(virDomainDefPtr def, libxl_domain_config *d_config) libxl_device_nic *x_nics; int i; - if (VIR_ALLOC_N(x_nics, nnics) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(x_nics, nnics) < 0) return -1; - } for (i = 0; i < nnics; i++) { if (libxlMakeNic(l_nics[i], &x_nics[i])) @@ -734,12 +729,9 @@ libxlMakeVfbList(libxlDriverPrivatePtr driver, if (nvfbs == 0) return 0; - if (VIR_ALLOC_N(x_vfbs, nvfbs) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(x_vfbs, nvfbs) < 0) return -1; - } if (VIR_ALLOC_N(x_vkbs, nvfbs) < 0) { - virReportOOMError(); VIR_FREE(x_vfbs); return -1; } diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 1bae3d6..c6f9616 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -183,10 +183,8 @@ libxlFDRegisterEventHook(void *priv, int fd, void **hndp, int vir_events = VIR_EVENT_HANDLE_ERROR; libxlEventHookInfoPtr info; - if (VIR_ALLOC(info) < 0) { - virReportOOMError(); + if (VIR_ALLOC(info) < 0) return -1; - } info->priv = priv; /* @@ -287,10 +285,8 @@ libxlTimeoutRegisterEventHook(void *priv, static struct timeval zero; int timeout; - if (VIR_ALLOC(info) < 0) { - virReportOOMError(); + if (VIR_ALLOC(info) < 0) return -1; - } info->priv = priv; /* @@ -548,11 +544,7 @@ static char * libxlDomainManagedSavePath(libxlDriverPrivatePtr driver, virDomainObjPtr vm) { char *ret; - if (virAsprintf(&ret, "%s/%s.save", driver->saveDir, vm->def->name) < 0) { - virReportOOMError(); - return NULL; - } - + ignore_value(virAsprintf(&ret, "%s/%s.save", driver->saveDir, vm->def->name)); return ret; } @@ -597,10 +589,8 @@ libxlSaveImageOpen(libxlDriverPrivatePtr driver, const char *from, goto error; } - if (VIR_ALLOC_N(xml, hdr.xmlLen) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(xml, hdr.xmlLen) < 0) goto error; - } if (saferead(fd, xml, hdr.xmlLen) != hdr.xmlLen) { virReportError(VIR_ERR_OPERATION_FAILED, "%s", _("failed to read XML")); @@ -845,10 +835,8 @@ libxlDomainSetVcpuAffinities(libxlDriverPrivatePtr driver, virDomainObjPtr vm) if (vcpu != def->cputune.vcpupin[vcpu]->vcpuid) continue; - if (VIR_ALLOC_N(cpumap, cpumaplen) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(cpumap, cpumaplen) < 0) goto cleanup; - } cpumask = (uint8_t*) def->cputune.vcpupin[vcpu]->cpumask; @@ -1274,7 +1262,7 @@ libxlStateInitialize(bool privileged, } if (virAsprintf(&log_file, "%s/libxl.log", libxl_driver->logDir) < 0) { - goto out_of_memory; + goto error; } if ((libxl_driver->logger_file = fopen(log_file, "a")) == NULL) { @@ -1369,8 +1357,6 @@ libxlStateInitialize(bool privileged, return 0; -out_of_memory: - virReportOOMError(); error: ret = -1; fail: @@ -2803,10 +2789,8 @@ libxlDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus, goto cleanup; maplen = VIR_CPU_MAPLEN(nvcpus); - if (VIR_ALLOC_N(bitmask, maplen) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(bitmask, maplen) < 0) goto cleanup; - } for (i = 0; i < nvcpus; ++i) { pos = i / 8; @@ -2967,10 +2951,8 @@ libxlDomainPinVcpu(virDomainPtr dom, unsigned int vcpu, unsigned char *cpumap, } if (!vm->def->cputune.vcpupin) { - if (VIR_ALLOC(vm->def->cputune.vcpupin) < 0) { - virReportOOMError(); + if (VIR_ALLOC(vm->def->cputune.vcpupin) < 0) goto cleanup; - } vm->def->cputune.nvcpupin = 0; } if (virDomainVcpuPinAdd(&vm->def->cputune.vcpupin, @@ -3176,10 +3158,8 @@ libxlConnectDomainXMLToNative(virConnectPtr conn, const char * nativeFormat, if (!(conf = xenFormatXM(conn, def, ver_info->xen_version_major))) goto cleanup; - if (VIR_ALLOC_N(ret, len) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(ret, len) < 0) goto cleanup; - } if (virConfWriteMem(ret, &len, conf) < 0) { VIR_FREE(ret); @@ -3491,10 +3471,8 @@ libxlDomainAttachDeviceDiskLive(libxlDomainObjPrivatePtr priv, goto cleanup; } - if (VIR_REALLOC_N(vm->def->disks, vm->def->ndisks+1) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(vm->def->disks, vm->def->ndisks+1) < 0) goto cleanup; - } if (libxlMakeDisk(l_disk, &x_disk) < 0) goto cleanup; @@ -3616,10 +3594,8 @@ libxlDomainAttachDeviceConfig(virDomainDefPtr vmdef, virDomainDeviceDefPtr dev) _("target %s already exists."), disk->dst); return -1; } - if (virDomainDiskInsert(vmdef, disk)) { - virReportOOMError(); + if (virDomainDiskInsert(vmdef, disk)) return -1; - } /* vmdef has the pointer. Generic codes for vmdef will do all jobs */ dev->data.disk = NULL; break; -- 1.8.1.5

On 07/04/2013 02:06 PM, Michal Privoznik wrote:
--- src/libxl/libxl_conf.c | 18 +++++------------- src/libxl/libxl_driver.c | 46 +++++++++++----------------------------------- 2 files changed, 16 insertions(+), 48 deletions(-)
@@ -1274,7 +1262,7 @@ libxlStateInitialize(bool privileged, }
if (virAsprintf(&log_file, "%s/libxl.log", libxl_driver->logDir) < 0) { - goto out_of_memory; + goto error; }
Redundant braces.
if ((libxl_driver->logger_file = fopen(log_file, "a")) == NULL) {
ACK Jan

--- src/locking/lock_daemon.c | 33 +++++++++------------------------ src/locking/lock_daemon_config.c | 8 ++------ src/locking/lock_driver_lockd.c | 23 ++++++----------------- src/locking/lock_driver_sanlock.c | 28 +++++++--------------------- src/locking/lock_manager.c | 16 ++++------------ 5 files changed, 28 insertions(+), 80 deletions(-) diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c index 23a119f..c4c1727 100644 --- a/src/locking/lock_daemon.c +++ b/src/locking/lock_daemon.c @@ -132,10 +132,8 @@ virLockDaemonNew(bool privileged) { virLockDaemonPtr lockd; - if (VIR_ALLOC(lockd) < 0) { - virReportOOMError(); + if (VIR_ALLOC(lockd) < 0) return NULL; - } if (virMutexInit(&lockd->lock) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -177,10 +175,8 @@ virLockDaemonNewPostExecRestart(virJSONValuePtr object, bool privileged) size_t i; int n; - if (VIR_ALLOC(lockd) < 0) { - virReportOOMError(); + if (VIR_ALLOC(lockd) < 0) return NULL; - } if (virMutexInit(&lockd->lock) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -388,7 +384,6 @@ virLockDaemonPidFilePath(bool privileged, if (virAsprintf(pidfile, "%s/virtlockd.pid", rundir) < 0) { VIR_FREE(rundir); - virReportOOMError(); goto error; } @@ -425,7 +420,6 @@ virLockDaemonUnixSocketPaths(bool privileged, if (virAsprintf(sockfile, "%s/virtlockd-sock", rundir) < 0) { VIR_FREE(rundir); - virReportOOMError(); goto error; } @@ -499,7 +493,7 @@ virLockDaemonSetupLogging(virLockDaemonConfigPtr config, char *tmp; if (access("/run/systemd/journal/socket", W_OK) >= 0) { if (virAsprintf(&tmp, "%d:journald", virLogGetDefaultPriority()) < 0) - goto no_memory; + goto error; virLogParseOutputs(tmp); VIR_FREE(tmp); } @@ -517,7 +511,7 @@ virLockDaemonSetupLogging(virLockDaemonConfigPtr config, if (virAsprintf(&tmp, "%d:file:%s/log/libvirt/virtlockd.log", virLogGetDefaultPriority(), LOCALSTATEDIR) == -1) - goto no_memory; + goto error; } else { char *logdir = virGetUserCacheDirectory(); mode_t old_umask; @@ -535,13 +529,13 @@ virLockDaemonSetupLogging(virLockDaemonConfigPtr config, if (virAsprintf(&tmp, "%d:file:%s/virtlockd.log", virLogGetDefaultPriority(), logdir) == -1) { VIR_FREE(logdir); - goto no_memory; + goto error; } VIR_FREE(logdir); } } else { if (virAsprintf(&tmp, "%d:stderr", virLogGetDefaultPriority()) < 0) - goto no_memory; + goto error; } virLogParseOutputs(tmp); VIR_FREE(tmp); @@ -555,8 +549,6 @@ virLockDaemonSetupLogging(virLockDaemonConfigPtr config, return 0; -no_memory: - virReportOOMError(); error: return -1; } @@ -784,14 +776,12 @@ virLockDaemonClientNew(virNetServerClientPtr client, unsigned long long timestamp; bool privileged = opaque != NULL; - if (VIR_ALLOC(priv) < 0) { - virReportOOMError(); + if (VIR_ALLOC(priv) < 0) return NULL; - } if (virMutexInit(&priv->lock) < 0) { VIR_FREE(priv); - virReportOOMError(); + virReportSystemError(errno, "%s", _("unable to init mutex")); return NULL; } @@ -940,12 +930,7 @@ virLockDaemonGetExecRestartMagic(void) { char *ret; - if (virAsprintf(&ret, "%lld", - (long long int)getpid()) < 0) { - virReportOOMError(); - return NULL; - } - + ignore_value(virAsprintf(&ret, "%lld", (long long int)getpid())); return ret; } diff --git a/src/locking/lock_daemon_config.c b/src/locking/lock_daemon_config.c index 4d7fe7d..88c4150 100644 --- a/src/locking/lock_daemon_config.c +++ b/src/locking/lock_daemon_config.c @@ -93,15 +93,13 @@ virLockDaemonConfigFilePath(bool privileged, char **configfile) if (virAsprintf(configfile, "%s/virtlockd.conf", configdir) < 0) { VIR_FREE(configdir); - goto no_memory; + goto error; } VIR_FREE(configdir); } return 0; -no_memory: - virReportOOMError(); error: return -1; } @@ -112,10 +110,8 @@ virLockDaemonConfigNew(bool privileged ATTRIBUTE_UNUSED) { virLockDaemonConfigPtr data; - if (VIR_ALLOC(data) < 0) { - virReportOOMError(); + if (VIR_ALLOC(data) < 0) return NULL; - } data->log_buffer_size = 64; diff --git a/src/locking/lock_driver_lockd.c b/src/locking/lock_driver_lockd.c index cc3b6b1..a7d5b57 100644 --- a/src/locking/lock_driver_lockd.c +++ b/src/locking/lock_driver_lockd.c @@ -181,7 +181,6 @@ static char *virLockManagerLockDaemonPath(bool privileged) if (virAsprintf(&path, "%s/virtlockd-sock", rundir) < 0) { VIR_FREE(rundir); - virReportOOMError(); return NULL; } @@ -375,10 +374,8 @@ static int virLockManagerLockDaemonInit(unsigned int version, if (driver) return 0; - if (VIR_ALLOC(driver) < 0) { - virReportOOMError(); + if (VIR_ALLOC(driver) < 0) return -1; - } driver->requireLeaseForDisks = true; driver->autoDiskLease = true; @@ -451,10 +448,8 @@ static int virLockManagerLockDaemonNew(virLockManagerPtr lock, virCheckFlags(VIR_LOCK_MANAGER_USES_STATE, -1); - if (VIR_ALLOC(priv) < 0) { - virReportOOMError(); + if (VIR_ALLOC(priv) < 0) return -1; - } lock->privateData = priv; switch (type) { @@ -525,10 +520,8 @@ static char *virLockManagerLockDaemonDiskLeaseName(const char *path) return NULL; } - if (VIR_ALLOC_N(ret, (SHA256_DIGEST_SIZE * 2) + 1) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(ret, (SHA256_DIGEST_SIZE * 2) + 1) < 0) return NULL; - } for (i = 0; i < SHA256_DIGEST_SIZE; i++) { ret[i*2] = hex[(buf[i] >> 4) & 0xf]; @@ -613,7 +606,7 @@ static int virLockManagerLockDaemonAddResource(virLockManagerPtr lock, if (VIR_STRDUP(newLockspace, driver->fileLockSpaceDir) < 0) goto error; if (!(newName = virLockManagerLockDaemonDiskLeaseName(name))) - goto no_memory; + goto error; autoCreate = true; VIR_DEBUG("Using indirect lease %s for %s", newName, name); } else { @@ -653,10 +646,8 @@ static int virLockManagerLockDaemonAddResource(virLockManagerPtr lock, return -1; } if (virAsprintf(&newLockspace, "%s/%s", - path, lockspace) < 0) { - virReportOOMError(); + path, lockspace) < 0) return -1; - } if (VIR_STRDUP(newName, name) < 0) goto error; @@ -669,7 +660,7 @@ static int virLockManagerLockDaemonAddResource(virLockManagerPtr lock, } if (VIR_EXPAND_N(priv->resources, priv->nresources, 1) < 0) - goto no_memory; + goto error; priv->resources[priv->nresources-1].lockspace = newLockspace; priv->resources[priv->nresources-1].name = newName; @@ -684,8 +675,6 @@ static int virLockManagerLockDaemonAddResource(virLockManagerPtr lock, return 0; -no_memory: - virReportOOMError(); error: VIR_FREE(newLockspace); VIR_FREE(newName); diff --git a/src/locking/lock_driver_sanlock.c b/src/locking/lock_driver_sanlock.c index de14725..f9a53d2 100644 --- a/src/locking/lock_driver_sanlock.c +++ b/src/locking/lock_driver_sanlock.c @@ -198,10 +198,8 @@ static int virLockManagerSanlockSetupLockspace(void) if (virAsprintf(&path, "%s/%s", driver->autoDiskLeasePath, - VIR_LOCK_MANAGER_SANLOCK_AUTO_DISK_LOCKSPACE) < 0) { - virReportOOMError(); + VIR_LOCK_MANAGER_SANLOCK_AUTO_DISK_LOCKSPACE) < 0) goto error; - } if (!virStrcpyStatic(ls.name, VIR_LOCK_MANAGER_SANLOCK_AUTO_DISK_LOCKSPACE)) { @@ -395,10 +393,8 @@ static int virLockManagerSanlockInit(unsigned int version, if (driver) return 0; - if (VIR_ALLOC(driver) < 0) { - virReportOOMError(); + if (VIR_ALLOC(driver) < 0) return -1; - } driver->requireLeaseForDisks = true; driver->hostID = 0; @@ -467,10 +463,8 @@ static int virLockManagerSanlockNew(virLockManagerPtr lock, return -1; } - if (VIR_ALLOC(priv) < 0) { - virReportOOMError(); + if (VIR_ALLOC(priv) < 0) return -1; - } priv->flags = flags; @@ -559,10 +553,8 @@ static int virLockManagerSanlockAddLease(virLockManagerPtr lock, struct sanlk_resource *res = NULL; int i; - if (VIR_ALLOC_VAR(res, struct sanlk_disk, 1) < 0) { - virReportOOMError(); + if (VIR_ALLOC_VAR(res, struct sanlk_disk, 1) < 0) goto cleanup; - } res->flags = shared ? SANLK_RES_SHARED : 0; res->num_disks = 1; @@ -624,10 +616,8 @@ static int virLockManagerSanlockAddDisk(virLockManagerPtr lock, return -1; } - if (VIR_ALLOC_VAR(res, struct sanlk_disk, 1) < 0) { - virReportOOMError(); + if (VIR_ALLOC_VAR(res, struct sanlk_disk, 1) < 0) goto cleanup; - } res->flags = shared ? SANLK_RES_SHARED : 0; res->num_disks = 1; @@ -635,10 +625,8 @@ static int virLockManagerSanlockAddDisk(virLockManagerPtr lock, goto cleanup; if (virAsprintf(&path, "%s/%s", - driver->autoDiskLeasePath, res->name) < 0) { - virReportOOMError(); + driver->autoDiskLeasePath, res->name) < 0) goto cleanup; - } if (!virStrcpy(res->disks[0].path, path, SANLK_PATH_LEN)) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Lease path '%s' exceeds %d characters"), @@ -918,10 +906,8 @@ static int virLockManagerSanlockAcquire(virLockManagerPtr lock, return -1; } - if (VIR_ALLOC(opt) < 0) { - virReportOOMError(); + if (VIR_ALLOC(opt) < 0) return -1; - } if (!virStrcpy(opt->owner_name, priv->vm_name, SANLK_NAME_LEN)) { virReportError(VIR_ERR_INTERNAL_ERROR, diff --git a/src/locking/lock_manager.c b/src/locking/lock_manager.c index 7c30c6f..e11c571 100644 --- a/src/locking/lock_manager.c +++ b/src/locking/lock_manager.c @@ -143,10 +143,8 @@ virLockManagerPluginPtr virLockManagerPluginNew(const char *name, name, driverName, configDir, flags); if (virAsprintf(&configFile, "%s/%s-%s.conf", - configDir, driverName, name) < 0) { - virReportOOMError(); + configDir, driverName, name) < 0) return NULL; - } if (STREQ(name, "nop")) { driver = &virLockDriverNop; @@ -156,10 +154,8 @@ virLockManagerPluginPtr virLockManagerPluginNew(const char *name, VIR_DEBUG("Module load %s from %s", name, moddir); - if (virAsprintf(&modfile, "%s/%s.so", moddir, name) < 0) { - virReportOOMError(); + if (virAsprintf(&modfile, "%s/%s.so", moddir, name) < 0) goto cleanup; - } if (access(modfile, R_OK) < 0) { virReportSystemError(errno, @@ -186,10 +182,8 @@ virLockManagerPluginPtr virLockManagerPluginNew(const char *name, if (driver->drvInit(VIR_LOCK_MANAGER_VERSION, configFile, flags) < 0) goto cleanup; - if (VIR_ALLOC(plugin) < 0) { - virReportOOMError(); + if (VIR_ALLOC(plugin) < 0) goto cleanup; - } plugin->driver = driver; plugin->handle = handle; @@ -321,10 +315,8 @@ virLockManagerPtr virLockManagerNew(virLockDriverPtr driver, CHECK_DRIVER(drvNew, NULL); - if (VIR_ALLOC(lock) < 0) { - virReportOOMError(); + if (VIR_ALLOC(lock) < 0) return NULL; - } lock->driver = driver; -- 1.8.1.5

On 07/04/2013 02:06 PM, Michal Privoznik wrote:
--- src/locking/lock_daemon.c | 33 +++++++++------------------------ src/locking/lock_daemon_config.c | 8 ++------ src/locking/lock_driver_lockd.c | 23 ++++++----------------- src/locking/lock_driver_sanlock.c | 28 +++++++--------------------- src/locking/lock_manager.c | 16 ++++------------ 5 files changed, 28 insertions(+), 80 deletions(-)
ACK Jan

--- src/lxc/lxc_cgroup.c | 4 +-- src/lxc/lxc_conf.c | 5 +-- src/lxc/lxc_container.c | 77 ++++++++++------------------------------ src/lxc/lxc_controller.c | 50 +++++++------------------- src/lxc/lxc_driver.c | 92 ++++++++++++------------------------------------ src/lxc/lxc_fuse.c | 12 ++----- src/lxc/lxc_monitor.c | 4 +-- src/lxc/lxc_process.c | 28 ++++----------- 8 files changed, 67 insertions(+), 205 deletions(-) diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c index 4443b83..f3030b1 100644 --- a/src/lxc/lxc_cgroup.c +++ b/src/lxc/lxc_cgroup.c @@ -547,10 +547,8 @@ virCgroupPtr virLXCCgroupCreate(virDomainDefPtr def, bool startup) if (!def->resource && startup) { virDomainResourceDefPtr res; - if (VIR_ALLOC(res) < 0) { - virReportOOMError(); + if (VIR_ALLOC(res) < 0) goto cleanup; - } if (VIR_STRDUP(res->partition, "/machine") < 0) { VIR_FREE(res); diff --git a/src/lxc/lxc_conf.c b/src/lxc/lxc_conf.c index 81a4a33..4e859c5 100644 --- a/src/lxc/lxc_conf.c +++ b/src/lxc/lxc_conf.c @@ -117,7 +117,7 @@ virCapsPtr lxcCapsInit(virLXCDriverPtr driver) if (STRNEQ(model, "none")) { /* Allocate just the primary security driver for LXC. */ if (VIR_ALLOC(caps->host.secModels) < 0) - goto no_memory; + goto error; caps->host.nsecModels = 1; if (VIR_STRDUP(caps->host.secModels[0].model, model) < 0) goto error; @@ -133,9 +133,6 @@ virCapsPtr lxcCapsInit(virLXCDriverPtr driver) return caps; -no_memory: - virReportOOMError(); - error: virObjectUnref(caps); return NULL; diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c index c8420db..6f3792a 100644 --- a/src/lxc/lxc_container.c +++ b/src/lxc/lxc_container.c @@ -158,10 +158,8 @@ int lxcContainerHasReboot(void) VIR_FREE(buf); cmd = v ? LINUX_REBOOT_CMD_CAD_ON : LINUX_REBOOT_CMD_CAD_OFF; - if (VIR_ALLOC_N(stack, getpagesize() * 4) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(stack, getpagesize() * 4) < 0) return -1; - } childStack = stack + (getpagesize() * 4); @@ -383,7 +381,6 @@ static int lxcContainerRenameAndEnableInterfaces(bool privNet, for (i = 0; i < nveths; i++) { if (virAsprintf(&newname, "eth%zu", i) < 0) { - virReportOOMError(); rc = -1; goto error_out; } @@ -467,10 +464,8 @@ static int lxcContainerGetSubtree(const char *prefix, if (!STRPREFIX(mntent.mnt_dir, prefix)) continue; - if (VIR_REALLOC_N(mounts, nmounts+1) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(mounts, nmounts+1) < 0) goto cleanup; - } if (VIR_STRDUP(mounts[nmounts], mntent.mnt_dir) < 0) goto cleanup; nmounts++; @@ -568,10 +563,8 @@ static int lxcContainerPrepareRoot(virDomainDefPtr def, } if (virAsprintf(&dst, "%s/%s.root", - LXC_STATE_DIR, def->name) < 0) { - virReportOOMError(); + LXC_STATE_DIR, def->name) < 0) return -1; - } tmp = root->dst; root->dst = dst; @@ -606,10 +599,8 @@ static int lxcContainerPivotRoot(virDomainFSDefPtr root) goto err; } - if (virAsprintf(&oldroot, "%s/.oldroot", root->src) < 0) { - virReportOOMError(); + if (virAsprintf(&oldroot, "%s/.oldroot", root->src) < 0) goto err; - } if (virFileMakePath(oldroot) < 0) { virReportSystemError(errno, @@ -628,10 +619,8 @@ static int lxcContainerPivotRoot(virDomainFSDefPtr root) } /* Create a directory called 'new' in tmpfs */ - if (virAsprintf(&newroot, "%s/new", oldroot) < 0) { - virReportOOMError(); + if (virAsprintf(&newroot, "%s/new", oldroot) < 0) goto err; - } if (virFileMakePath(newroot) < 0) { virReportSystemError(errno, @@ -893,10 +882,8 @@ static int lxcContainerSetupDevices(char **ttyPaths, size_t nttyPaths) for (i = 0; i < nttyPaths; i++) { char *tty; - if (virAsprintf(&tty, "/dev/tty%zu", i+1) < 0) { - virReportOOMError(); + if (virAsprintf(&tty, "/dev/tty%zu", i+1) < 0) return -1; - } if (symlink(ttyPaths[i], tty) < 0) { VIR_FREE(tty); virReportSystemError(errno, @@ -924,10 +911,8 @@ static int lxcContainerMountFSBind(virDomainFSDefPtr fs, int ret = -1; struct stat st; - if (virAsprintf(&src, "%s%s", srcprefix, fs->src) < 0) { - virReportOOMError(); + if (virAsprintf(&src, "%s%s", srcprefix, fs->src) < 0) goto cleanup; - } if (stat(fs->dst, &st) < 0) { if (errno != ENOENT) { @@ -1097,10 +1082,8 @@ static int lxcContainerMountFSBlockAuto(virDomainFSDefPtr fs, /* First time around we use /etc/filesystems */ retry: if (virAsprintf(&fslist, "/.oldroot%s", - tryProc ? "/proc/filesystems" : "/etc/filesystems") < 0) { - virReportOOMError(); + tryProc ? "/proc/filesystems" : "/etc/filesystems") < 0) goto cleanup; - } VIR_DEBUG("Open fslist %s", fslist); if (!(fp = fopen(fslist, "r"))) { @@ -1254,10 +1237,8 @@ static int lxcContainerMountFSBlock(virDomainFSDefPtr fs, char *src = NULL; int ret = -1; - if (virAsprintf(&src, "%s%s", srcprefix, fs->src) < 0) { - virReportOOMError(); + if (virAsprintf(&src, "%s%s", srcprefix, fs->src) < 0) goto cleanup; - } ret = lxcContainerMountFSBlockHelper(fs, src); @@ -1276,10 +1257,8 @@ static int lxcContainerMountFSTmpfs(virDomainFSDefPtr fs, char *data = NULL; if (virAsprintf(&data, - "size=%lldk%s", fs->usage, sec_mount_options) < 0) { - virReportOOMError(); + "size=%lldk%s", fs->usage, sec_mount_options) < 0) goto cleanup; - } if (virFileMakePath(fs->dst) < 0) { virReportSystemError(errno, @@ -1396,15 +1375,11 @@ static int lxcContainerSetupDisk(virDomainDefPtr vmDef, goto cleanup; } - if (virAsprintf(&src, "/.oldroot/%s", def->src) < 0) { - virReportOOMError(); + if (virAsprintf(&src, "/.oldroot/%s", def->src) < 0) goto cleanup; - } - if (virAsprintf(&dst, "/dev/%s", def->dst) < 0) { - virReportOOMError(); + if (virAsprintf(&dst, "/dev/%s", def->dst) < 0) goto cleanup; - } if (stat(src, &sb) < 0) { virReportSystemError(errno, @@ -1484,22 +1459,16 @@ static int lxcContainerSetupHostdevSubsysUSB(virDomainDefPtr vmDef ATTRIBUTE_UNU mode_t mode; if (virAsprintf(&dstdir, USB_DEVFS "/%03d", - def->source.subsys.u.usb.bus) < 0) { - virReportOOMError(); + def->source.subsys.u.usb.bus) < 0) goto cleanup; - } if (virAsprintf(&dstfile, "%s/%03d", dstdir, - def->source.subsys.u.usb.device) < 0) { - virReportOOMError(); + def->source.subsys.u.usb.device) < 0) goto cleanup; - } - if (virAsprintf(&src, "/.oldroot/%s", dstfile) < 0) { - virReportOOMError(); + if (virAsprintf(&src, "/.oldroot/%s", dstfile) < 0) goto cleanup; - } if (stat(src, &sb) < 0) { virReportSystemError(errno, @@ -1559,10 +1528,8 @@ static int lxcContainerSetupHostdevCapsStorage(virDomainDefPtr vmDef ATTRIBUTE_U goto cleanup; } - if (virAsprintf(&src, "/.oldroot/%s", def->source.caps.u.storage.block) < 0) { - virReportOOMError(); + if (virAsprintf(&src, "/.oldroot/%s", def->source.caps.u.storage.block) < 0) goto cleanup; - } if (stat(src, &sb) < 0) { virReportSystemError(errno, @@ -1616,10 +1583,8 @@ static int lxcContainerSetupHostdevCapsMisc(virDomainDefPtr vmDef ATTRIBUTE_UNUS goto cleanup; } - if (virAsprintf(&src, "/.oldroot/%s", def->source.caps.u.misc.chardev) < 0) { - virReportOOMError(); + if (virAsprintf(&src, "/.oldroot/%s", def->source.caps.u.misc.chardev) < 0) goto cleanup; - } if (stat(src, &sb) < 0) { virReportSystemError(errno, @@ -1962,10 +1927,8 @@ static int lxcContainerChild(void *data) if (STRPREFIX(tty, "/dev/pts/")) tty += strlen("/dev/pts/"); if (virAsprintf(&ttyPath, "%s/%s.devpts/%s", - LXC_STATE_DIR, vmDef->name, tty) < 0) { - virReportOOMError(); + LXC_STATE_DIR, vmDef->name, tty) < 0) goto cleanup; - } } else if (VIR_STRDUP(ttyPath, "/dev/null") < 0) { goto cleanup; } @@ -2116,10 +2079,8 @@ int lxcContainerStart(virDomainDefPtr def, ttyPaths, nttyPaths, handshakefd}; /* allocate a stack for the container */ - if (VIR_ALLOC_N(stack, stacksize) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(stack, stacksize) < 0) return -1; - } stacktop = stack + stacksize; cflags = CLONE_NEWPID|CLONE_NEWNS|CLONE_NEWUTS|CLONE_NEWIPC|SIGCHLD; diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c index 88601f1..a927176 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c @@ -150,10 +150,8 @@ static virLXCControllerPtr virLXCControllerNew(const char *name) virDomainXMLOptionPtr xmlopt = NULL; char *configFile = NULL; - if (VIR_ALLOC(ctrl) < 0) { - virReportOOMError(); + if (VIR_ALLOC(ctrl) < 0) goto error; - } ctrl->timerShutdown = -1; ctrl->firstClient = true; @@ -279,10 +277,8 @@ static void virLXCControllerFree(virLXCControllerPtr ctrl) static int virLXCControllerAddConsole(virLXCControllerPtr ctrl, int hostFd) { - if (VIR_EXPAND_N(ctrl->consoles, ctrl->nconsoles, 1) < 0) { - virReportOOMError(); + if (VIR_EXPAND_N(ctrl->consoles, ctrl->nconsoles, 1) < 0) return -1; - } ctrl->consoles[ctrl->nconsoles-1].server = ctrl->server; ctrl->consoles[ctrl->nconsoles-1].hostFd = hostFd; ctrl->consoles[ctrl->nconsoles-1].hostWatch = -1; @@ -473,7 +469,6 @@ static int virLXCControllerSetupLoopDevices(virLXCControllerPtr ctrl) VIR_DEBUG("Saving loop fd %d", fd); if (VIR_EXPAND_N(ctrl->loopDevFds, ctrl->nloopDevs, 1) < 0) { VIR_FORCE_CLOSE(fd); - virReportOOMError(); goto cleanup; } ctrl->loopDevFds[ctrl->nloopDevs - 1] = fd; @@ -521,7 +516,6 @@ static int virLXCControllerSetupLoopDevices(virLXCControllerPtr ctrl) VIR_DEBUG("Saving loop fd %d", fd); if (VIR_EXPAND_N(ctrl->loopDevFds, ctrl->nloopDevs, 1) < 0) { VIR_FORCE_CLOSE(fd); - virReportOOMError(); goto cleanup; } ctrl->loopDevFds[ctrl->nloopDevs - 1] = fd; @@ -707,10 +701,8 @@ static int virLXCControllerSetupServer(virLXCControllerPtr ctrl) char *sockpath; if (virAsprintf(&sockpath, "%s/%s.sock", - LXC_STATE_DIR, ctrl->name) < 0) { - virReportOOMError(); + LXC_STATE_DIR, ctrl->name) < 0) return -1; - } if (!(ctrl->server = virNetServerNew(0, 0, 0, 1, -1, 0, false, @@ -1228,10 +1220,8 @@ static int virLXCControllerSetupDev(virLXCControllerPtr ctrl) ctrl->def); if (virAsprintf(&dev, "/%s/%s.dev", - LXC_STATE_DIR, ctrl->def->name) < 0) { - virReportOOMError(); + LXC_STATE_DIR, ctrl->def->name) < 0) goto cleanup; - } if (virFileMakePath(dev) < 0) { virReportSystemError(errno, @@ -1245,10 +1235,8 @@ static int virLXCControllerSetupDev(virLXCControllerPtr ctrl) */ if (virAsprintf(&opts, - "mode=755,size=65536%s", mount_options) < 0) { - virReportOOMError(); + "mode=755,size=65536%s", mount_options) < 0) goto cleanup; - } VIR_DEBUG("Mount devfs on %s type=tmpfs flags=%x, opts=%s", dev, MS_NOSUID, opts); @@ -1294,10 +1282,8 @@ static int virLXCControllerPopulateDevices(virLXCControllerPtr ctrl) /* Populate /dev/ with a few important bits */ for (i = 0; i < ARRAY_CARDINALITY(devs); i++) { if (virAsprintf(&path, "/%s/%s.dev/%s", - LXC_STATE_DIR, ctrl->def->name, devs[i].path) < 0) { - virReportOOMError(); + LXC_STATE_DIR, ctrl->def->name, devs[i].path) < 0) goto cleanup; - } dev_t dev = makedev(devs[i].maj, devs[i].min); if (mknod(path, S_IFCHR, dev) < 0 || @@ -1437,11 +1423,9 @@ lxcCreateTty(virLXCControllerPtr ctrl, int *ttymaster, * anything other than 0, but let's play it safe. */ if ((virAsprintf(ttyName, "/dev/pts/%d", ptyno) < 0) || (virAsprintf(ttyHostPath, "/%s/%s.devpts/%d", LXC_STATE_DIR, - ctrl->def->name, ptyno) < 0)) { - virReportOOMError(); + ctrl->def->name, ptyno) < 0)) errno = ENOMEM; goto cleanup; - } ret = 0; @@ -1515,10 +1499,8 @@ virLXCControllerSetupDevPTS(virLXCControllerPtr ctrl) if (virAsprintf(&devpts, "%s/%s.devpts", LXC_STATE_DIR, ctrl->def->name) < 0 || virAsprintf(&ctrl->devptmx, "%s/%s.devpts/ptmx", - LXC_STATE_DIR, ctrl->def->name) < 0) { - virReportOOMError(); + LXC_STATE_DIR, ctrl->def->name) < 0) goto cleanup; - } if (virFileMakePath(devpts) < 0) { virReportSystemError(errno, @@ -1530,10 +1512,8 @@ virLXCControllerSetupDevPTS(virLXCControllerPtr ctrl) /* XXX should we support gid=X for X!=5 for distros which use * a different gid for tty? */ if (virAsprintf(&opts, "newinstance,ptmxmode=0666,mode=0620,gid=5%s", - (mount_options ? mount_options : "")) < 0) { - virReportOOMError(); + (mount_options ? mount_options : "")) < 0) goto cleanup; - } VIR_DEBUG("Mount devpts on %s type=tmpfs flags=%x, opts=%s", devpts, MS_NOSUID, opts); @@ -1708,10 +1688,8 @@ virLXCControllerRun(virLXCControllerPtr ctrl) size_t i; virCgroupPtr cgroup = NULL; - if (VIR_ALLOC_N(containerTTYPaths, ctrl->nconsoles) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(containerTTYPaths, ctrl->nconsoles) < 0) goto cleanup; - } if (socketpair(PF_UNIX, SOCK_STREAM, 0, control) < 0) { virReportSystemError(errno, "%s", @@ -1871,19 +1849,15 @@ int main(int argc, char *argv[]) break; case 'v': - if (VIR_REALLOC_N(veths, nveths+1) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(veths, nveths+1) < 0) goto cleanup; - } if (VIR_STRDUP(veths[nveths++], optarg) < 0) goto cleanup; break; case 'c': - if (VIR_REALLOC_N(ttyFDs, nttyFDs + 1) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(ttyFDs, nttyFDs + 1) < 0) goto cleanup; - } if (virStrToLong_i(optarg, NULL, 10, &ttyFDs[nttyFDs++]) < 0) { fprintf(stderr, "malformed --console argument '%s'", optarg); goto cleanup; diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 1a6d086..aaf25b6 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -2885,10 +2885,8 @@ lxcDomainShutdownFlags(virDomainPtr dom, } if (virAsprintf(&vroot, "/proc/%llu/root", - (unsigned long long)priv->initpid) < 0) { - virReportOOMError(); + (unsigned long long)priv->initpid) < 0) goto cleanup; - } if (flags == 0 || (flags & VIR_DOMAIN_SHUTDOWN_INITCTL)) { @@ -2977,10 +2975,8 @@ lxcDomainReboot(virDomainPtr dom, } if (virAsprintf(&vroot, "/proc/%llu/root", - (unsigned long long)priv->initpid) < 0) { - virReportOOMError(); + (unsigned long long)priv->initpid) < 0) goto cleanup; - } if (flags == 0 || (flags & VIR_DOMAIN_REBOOT_INITCTL)) { @@ -3037,10 +3033,8 @@ lxcDomainAttachDeviceConfig(virDomainDefPtr vmdef, _("target %s already exists."), disk->dst); return -1; } - if (virDomainDiskInsert(vmdef, disk)) { - virReportOOMError(); + if (virDomainDiskInsert(vmdef, disk)) return -1; - } /* vmdef has the pointer. Generic codes for vmdef will do all jobs */ dev->data.disk = NULL; ret = 0; @@ -3048,10 +3042,8 @@ lxcDomainAttachDeviceConfig(virDomainDefPtr vmdef, case VIR_DOMAIN_DEVICE_NET: net = dev->data.net; - if (virDomainNetInsert(vmdef, net) < 0) { - virReportOOMError(); + if (virDomainNetInsert(vmdef, net) < 0) goto cleanup; - } dev->data.net = NULL; ret = 0; break; @@ -3063,10 +3055,8 @@ lxcDomainAttachDeviceConfig(virDomainDefPtr vmdef, _("device is already in the domain configuration")); return -1; } - if (virDomainHostdevInsert(vmdef, hostdev) < 0) { - virReportOOMError(); + if (virDomainHostdevInsert(vmdef, hostdev) < 0) return -1; - } dev->data.hostdev = NULL; ret = 0; break; @@ -3241,15 +3231,11 @@ lxcDomainAttachDeviceDiskLive(virLXCDriverPtr driver, } if (virAsprintf(&dst, "/proc/%llu/root/dev/%s", - (unsigned long long)priv->initpid, def->dst) < 0) { - virReportOOMError(); + (unsigned long long)priv->initpid, def->dst) < 0) goto cleanup; - } - if (VIR_REALLOC_N(vm->def->disks, vm->def->ndisks+1) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(vm->def->disks, vm->def->ndisks+1) < 0) goto cleanup; - } mode = 0700; if (S_ISCHR(sb.st_mode)) @@ -3329,10 +3315,8 @@ lxcDomainAttachDeviceNetLive(virConnectPtr conn, } /* preallocate new slot for device */ - if (VIR_REALLOC_N(vm->def->nets, vm->def->nnets+1) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(vm->def->nets, vm->def->nnets+1) < 0) return -1; - } /* If appropriate, grab a physical device from the configured * network's pool of devices, or resolve bridge device name @@ -3466,31 +3450,23 @@ lxcDomainAttachDeviceHostdevSubsysUSBLive(virLXCDriverPtr driver, } if (virAsprintf(&vroot, "/proc/%llu/root", - (unsigned long long)priv->initpid) < 0) { - virReportOOMError(); + (unsigned long long)priv->initpid) < 0) goto cleanup; - } if (virAsprintf(&dstdir, "%s/dev/bus/%03d", vroot, - def->source.subsys.u.usb.bus) < 0) { - virReportOOMError(); + def->source.subsys.u.usb.bus) < 0) goto cleanup; - } if (virAsprintf(&dstfile, "%s/%03d", dstdir, - def->source.subsys.u.usb.device) < 0) { - virReportOOMError(); + def->source.subsys.u.usb.device) < 0) goto cleanup; - } if (virAsprintf(&src, "/dev/bus/usb/%03d/%03d", def->source.subsys.u.usb.bus, - def->source.subsys.u.usb.device) < 0) { - virReportOOMError(); + def->source.subsys.u.usb.device) < 0) goto cleanup; - } if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICES)) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", @@ -3599,22 +3575,16 @@ lxcDomainAttachDeviceHostdevStorageLive(virLXCDriverPtr driver, } if (virAsprintf(&vroot, "/proc/%llu/root", - (unsigned long long)priv->initpid) < 0) { - virReportOOMError(); + (unsigned long long)priv->initpid) < 0) goto cleanup; - } if (virAsprintf(&dst, "%s/%s", vroot, - def->source.caps.u.storage.block) < 0) { - virReportOOMError(); + def->source.caps.u.storage.block) < 0) goto cleanup; - } - if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs+1) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs+1) < 0) goto cleanup; - } mode = 0700 | S_IFBLK; @@ -3703,22 +3673,16 @@ lxcDomainAttachDeviceHostdevMiscLive(virLXCDriverPtr driver, } if (virAsprintf(&vroot, "/proc/%llu/root", - (unsigned long long)priv->initpid) < 0) { - virReportOOMError(); + (unsigned long long)priv->initpid) < 0) goto cleanup; - } if (virAsprintf(&dst, "%s/%s", vroot, - def->source.caps.u.misc.chardev) < 0) { - virReportOOMError(); + def->source.caps.u.misc.chardev) < 0) goto cleanup; - } - if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs+1) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs+1) < 0) goto cleanup; - } mode = 0700 | S_IFCHR; @@ -3899,10 +3863,8 @@ lxcDomainDetachDeviceDiskLive(virDomainObjPtr vm, def = vm->def->disks[i]; if (virAsprintf(&dst, "/proc/%llu/root/dev/%s", - (unsigned long long)priv->initpid, def->dst) < 0) { - virReportOOMError(); + (unsigned long long)priv->initpid, def->dst) < 0) goto cleanup; - } if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICES)) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", @@ -4021,18 +3983,14 @@ lxcDomainDetachDeviceHostdevUSBLive(virLXCDriverPtr driver, } if (virAsprintf(&vroot, "/proc/%llu/root", - (unsigned long long)priv->initpid) < 0) { - virReportOOMError(); + (unsigned long long)priv->initpid) < 0) goto cleanup; - } if (virAsprintf(&dst, "%s/dev/bus/usb/%03d/%03d", vroot, def->source.subsys.u.usb.bus, - def->source.subsys.u.usb.device) < 0) { - virReportOOMError(); + def->source.subsys.u.usb.device) < 0) goto cleanup; - } if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICES)) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", @@ -4099,10 +4057,8 @@ lxcDomainDetachDeviceHostdevStorageLive(virDomainObjPtr vm, if (virAsprintf(&dst, "/proc/%llu/root/%s", (unsigned long long)priv->initpid, - def->source.caps.u.storage.block) < 0) { - virReportOOMError(); + def->source.caps.u.storage.block) < 0) goto cleanup; - } if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICES)) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", @@ -4160,10 +4116,8 @@ lxcDomainDetachDeviceHostdevMiscLive(virDomainObjPtr vm, if (virAsprintf(&dst, "/proc/%llu/root/%s", (unsigned long long)priv->initpid, - def->source.caps.u.misc.chardev) < 0) { - virReportOOMError(); + def->source.caps.u.misc.chardev) < 0) goto cleanup; - } if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICES)) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", diff --git a/src/lxc/lxc_fuse.c b/src/lxc/lxc_fuse.c index b98a0d9..ea4ab7a 100644 --- a/src/lxc/lxc_fuse.c +++ b/src/lxc/lxc_fuse.c @@ -52,10 +52,8 @@ static int lxcProcGetattr(const char *path, struct stat *stbuf) virDomainDefPtr def = (virDomainDefPtr)context->private_data; memset(stbuf, 0, sizeof(struct stat)); - if (virAsprintf(&mempath, "/proc/%s", path) < 0) { - virReportOOMError(); + if (virAsprintf(&mempath, "/proc/%s", path) < 0) return -errno; - } res = 0; @@ -238,10 +236,8 @@ static int lxcProcRead(const char *path ATTRIBUTE_UNUSED, struct fuse_context *context = NULL; virDomainDefPtr def = NULL; - if (virAsprintf(&hostpath, "/proc/%s", path) < 0) { - virReportOOMError(); + if (virAsprintf(&hostpath, "/proc/%s", path) < 0) return -errno; - } context = fuse_get_context(); def = (virDomainDefPtr)context->private_data; @@ -297,10 +293,8 @@ int lxcSetupFuse(virLXCFusePtr *f, virDomainDefPtr def) goto cleanup2; if (virAsprintf(&fuse->mountpoint, "%s/%s.fuse/", LXC_STATE_DIR, - def->name) < 0) { - virReportOOMError(); + def->name) < 0) goto cleanup1; - } if (virFileMakePath(fuse->mountpoint) < 0) { virReportSystemError(errno, _("Cannot create %s"), diff --git a/src/lxc/lxc_monitor.c b/src/lxc/lxc_monitor.c index a205d69..999039b 100644 --- a/src/lxc/lxc_monitor.c +++ b/src/lxc/lxc_monitor.c @@ -155,7 +155,7 @@ virLXCMonitorPtr virLXCMonitorNew(virDomainObjPtr vm, if (virAsprintf(&sockpath, "%s/%s.sock", socketdir, vm->def->name) < 0) - goto no_memory; + goto error; if (!(mon->client = virNetClientNewUNIX(sockpath, false, NULL))) goto error; @@ -185,8 +185,6 @@ cleanup: VIR_FREE(sockpath); return mon; -no_memory: - virReportOOMError(); error: virObjectUnref(mon); mon = NULL; diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index 01e35c4..6d6a109 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -442,10 +442,8 @@ static int virLXCProcessSetupInterfaces(virConnectPtr conn, if (networkAllocateActualDevice(def->nets[i]) < 0) goto cleanup; - if (VIR_EXPAND_N(*veths, *nveths, 1) < 0) { - virReportOOMError(); + if (VIR_EXPAND_N(*veths, *nveths, 1) < 0) goto cleanup; - } switch (virDomainNetGetActualType(def->nets[i])) { case VIR_DOMAIN_NET_TYPE_NETWORK: { @@ -648,10 +646,8 @@ virLXCProcessGetNsInode(pid_t pid, int ret = -1; if (virAsprintf(&path, "/proc/%llu/ns/%s", - (unsigned long long)pid, nsname) < 0) { - virReportOOMError(); + (unsigned long long)pid, nsname) < 0) goto cleanup; - } if (stat(path, &sb) < 0) { virReportSystemError(errno, @@ -992,7 +988,7 @@ virLXCProcessEnsureRootFS(virDomainObjPtr vm) return 0; if (VIR_ALLOC(root) < 0) - goto no_memory; + goto error; root->type = VIR_DOMAIN_FS_TYPE_MOUNT; @@ -1008,8 +1004,6 @@ virLXCProcessEnsureRootFS(virDomainObjPtr vm) return 0; -no_memory: - virReportOOMError(); error: virDomainFSDefFree(root); return -1; @@ -1084,10 +1078,8 @@ int virLXCProcessStart(virConnectPtr conn, } if (virAsprintf(&logfile, "%s/%s.log", - driver->logDir, vm->def->name) < 0) { - virReportOOMError(); + driver->logDir, vm->def->name) < 0) return -1; - } /* Do this up front, so any part of the startup process can add * runtime state to vm->def that won't be persisted. This let's us @@ -1127,10 +1119,8 @@ int virLXCProcessStart(virConnectPtr conn, * and forward I/O between them. */ nttyFDs = vm->def->nconsoles; - if (VIR_ALLOC_N(ttyFDs, nttyFDs) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(ttyFDs, nttyFDs) < 0) goto cleanup; - } for (i = 0; i < vm->def->nconsoles; i++) ttyFDs[i] = -1; @@ -1170,10 +1160,8 @@ int virLXCProcessStart(virConnectPtr conn, vm->def->consoles[i]->source.data.file.path = ttyPath; VIR_FREE(vm->def->consoles[i]->info.alias); - if (virAsprintf(&vm->def->consoles[i]->info.alias, "console%zu", i) < 0) { - virReportOOMError(); + if (virAsprintf(&vm->def->consoles[i]->info.alias, "console%zu", i) < 0) goto cleanup; - } } if (virLXCProcessSetupInterfaces(conn, vm->def, &nveths, &veths) < 0) @@ -1224,10 +1212,8 @@ int virLXCProcessStart(virConnectPtr conn, } /* Log timestamp */ - if ((timestamp = virTimeStringNow()) == NULL) { - virReportOOMError(); + if ((timestamp = virTimeStringNow()) == NULL) goto cleanup; - } if (safewrite(logfd, timestamp, strlen(timestamp)) < 0 || safewrite(logfd, START_POSTFIX, strlen(START_POSTFIX)) < 0) { VIR_WARN("Unable to write timestamp to logfile: %s", -- 1.8.1.5

On 07/04/13 14:06, Michal Privoznik wrote:
--- src/lxc/lxc_cgroup.c | 4 +-- src/lxc/lxc_conf.c | 5 +-- src/lxc/lxc_container.c | 77 ++++++++++------------------------------ src/lxc/lxc_controller.c | 50 +++++++------------------- src/lxc/lxc_driver.c | 92 ++++++++++++------------------------------------ src/lxc/lxc_fuse.c | 12 ++----- src/lxc/lxc_monitor.c | 4 +-- src/lxc/lxc_process.c | 28 ++++----------- 8 files changed, 67 insertions(+), 205 deletions(-)
...
diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c index 88601f1..a927176 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c
...
@@ -1437,11 +1423,9 @@ lxcCreateTty(virLXCControllerPtr ctrl, int *ttymaster, * anything other than 0, but let's play it safe. */ if ((virAsprintf(ttyName, "/dev/pts/%d", ptyno) < 0) || (virAsprintf(ttyHostPath, "/%s/%s.devpts/%d", LXC_STATE_DIR, - ctrl->def->name, ptyno) < 0)) { - virReportOOMError(); + ctrl->def->name, ptyno) < 0)) errno = ENOMEM; goto cleanup;
This still needs the block around, it contains two statements.
- }
ret = 0;
ACK with the issue above addressed. Peter

--- src/node_device/node_device_driver.c | 4 +--- src/node_device/node_device_udev.c | 18 ++++-------------- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c index 1f7e0fd..bbad113 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -78,10 +78,8 @@ static int update_driver_name(virNodeDeviceObjPtr dev) VIR_FREE(dev->def->driver); - if (virAsprintf(&driver_link, "%s/driver", dev->def->sysfs_path) < 0) { - virReportOOMError(); + if (virAsprintf(&driver_link, "%s/driver", dev->def->sysfs_path) < 0) goto cleanup; - } /* Some devices don't have an explicit driver, so just return without a name */ diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c index 1f2e691..56a0023 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1345,10 +1345,8 @@ static int udevAddOneDevice(struct udev_device *device) virNodeDeviceObjPtr dev = NULL; int ret = -1; - if (VIR_ALLOC(def) != 0) { - virReportOOMError(); + if (VIR_ALLOC(def) != 0) goto out; - } if (VIR_STRDUP(def->sysfs_path, udev_device_get_syspath(device)) < 0) goto out; @@ -1359,10 +1357,8 @@ static int udevAddOneDevice(struct udev_device *device) goto out; } - if (VIR_ALLOC(def->caps) != 0) { - virReportOOMError(); + if (VIR_ALLOC(def->caps) != 0) goto out; - } if (udevGetDeviceType(device, &def->caps->type) != 0) { goto out; @@ -1625,18 +1621,14 @@ static int udevSetupSystemDev(void) virNodeDeviceObjPtr dev = NULL; int ret = -1; - if (VIR_ALLOC(def) != 0) { - virReportOOMError(); + if (VIR_ALLOC(def) != 0) goto out; - } if (VIR_STRDUP(def->name, "computer") < 0) goto out; - if (VIR_ALLOC(def->caps) != 0) { - virReportOOMError(); + if (VIR_ALLOC(def->caps) != 0) goto out; - } #if defined(__x86_64__) || defined(__i386__) || defined(__amd64__) udevGetDMIData(&def->caps->data); @@ -1689,7 +1681,6 @@ static int nodeStateInitialize(bool privileged ATTRIBUTE_UNUSED, #endif if (VIR_ALLOC(priv) < 0) { - virReportOOMError(); ret = -1; goto out; } @@ -1697,7 +1688,6 @@ static int nodeStateInitialize(bool privileged ATTRIBUTE_UNUSED, priv->watch = -1; if (VIR_ALLOC(driverState) < 0) { - virReportOOMError(); VIR_FREE(priv); ret = -1; goto out; -- 1.8.1.5

On 07/04/13 14:06, Michal Privoznik wrote:
--- src/node_device/node_device_driver.c | 4 +--- src/node_device/node_device_udev.c | 18 ++++-------------- 2 files changed, 5 insertions(+), 17 deletions(-)
ACK, Peter

--- src/network/bridge_driver.c | 138 +++++++++++++------------------------------- 1 file changed, 40 insertions(+), 98 deletions(-) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index d7e90ac..6fae832 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -192,17 +192,17 @@ networkRemoveInactive(struct network_driver *driver, goto cleanup; if (!(radvdconfigfile = networkRadvdConfigFileName(def->name))) - goto no_memory; + goto cleanup; if (!(radvdpidbase = networkRadvdPidfileBasename(def->name))) - goto no_memory; + goto cleanup; if (!(configfile = networkDnsmasqConfigFileName(def->name))) - goto no_memory; + goto cleanup; if (!(statusfile = virNetworkConfigFile(driverState->stateDir, def->name))) - goto no_memory; + goto cleanup; /* dnsmasq */ dnsmasqDelete(dctx); @@ -229,10 +229,6 @@ cleanup: VIR_FREE(statusfile); dnsmasqContextFree(dctx); return ret; - -no_memory: - virReportOOMError(); - goto cleanup; } static char * @@ -282,10 +278,8 @@ networkFindActiveConfigs(struct network_driver *driver) &obj->dnsmasqPid, dnsmasqCapsGetBinaryPath(driver->dnsmasqCaps))); - if (!(radvdpidbase = networkRadvdPidfileBasename(obj->def->name))) { - virReportOOMError(); + if (!(radvdpidbase = networkRadvdPidfileBasename(obj->def->name))) goto cleanup; - } ignore_value(virPidFileReadIfAlive(driverState->pidDir, radvdpidbase, &obj->radvdPid, RADVD)); VIR_FREE(radvdpidbase); @@ -415,7 +409,7 @@ networkStateInitialize(bool privileged, "%s/dnsmasq/lib", rundir) < 0) || (virAsprintf(&driverState->radvdStateDir, "%s/radvd/lib", rundir) < 0)) { - goto out_of_memory; + goto error; } } @@ -470,8 +464,6 @@ cleanup: VIR_FREE(rundir); return ret; -out_of_memory: - virReportOOMError(); error: if (driverState) networkDriverUnlock(driverState); @@ -784,24 +776,15 @@ networkDnsmasqConfContents(virNetworkObjPtr network, for (ii = 0; ii < dns->nsrvs; ii++) { if (dns->srvs[ii].service && dns->srvs[ii].protocol) { - if (dns->srvs[ii].port) { - if (virAsprintf(&recordPort, "%d", dns->srvs[ii].port) < 0) { - virReportOOMError(); - goto cleanup; - } - } - if (dns->srvs[ii].priority) { - if (virAsprintf(&recordPriority, "%d", dns->srvs[ii].priority) < 0) { - virReportOOMError(); - goto cleanup; - } - } - if (dns->srvs[ii].weight) { - if (virAsprintf(&recordWeight, "%d", dns->srvs[ii].weight) < 0) { - virReportOOMError(); - goto cleanup; - } - } + if (dns->srvs[ii].port && + virAsprintf(&recordPort, "%d", dns->srvs[ii].port) < 0) + goto cleanup; + if (dns->srvs[ii].priority && + virAsprintf(&recordPriority, "%d", dns->srvs[ii].priority) < 0) + goto cleanup; + if (dns->srvs[ii].weight && + virAsprintf(&recordWeight, "%d", dns->srvs[ii].weight) < 0) + goto cleanup; if (virAsprintf(&record, "%s.%s.%s,%s,%s,%s,%s", dns->srvs[ii].service, @@ -810,10 +793,8 @@ networkDnsmasqConfContents(virNetworkObjPtr network, dns->srvs[ii].target ? dns->srvs[ii].target : "", recordPort ? recordPort : "", recordPriority ? recordPriority : "", - recordWeight ? recordWeight : "") < 0) { - virReportOOMError(); + recordWeight ? recordWeight : "") < 0) goto cleanup; - } virBufferAsprintf(&configbuf, "srv-host=%s\n", record); VIR_FREE(record); @@ -929,10 +910,8 @@ networkDnsmasqConfContents(virNetworkObjPtr network, if (VIR_SOCKET_ADDR_VALID(&ipdef->bootserver)) { char *bootserver = virSocketAddrFormat(&ipdef->bootserver); - if (!bootserver) { - virReportOOMError(); + if (!bootserver) goto cleanup; - } virBufferAsprintf(&configbuf, "dhcp-boot=%s%s%s\n", ipdef->bootfile, ",,", bootserver); VIR_FREE(bootserver); @@ -946,10 +925,8 @@ networkDnsmasqConfContents(virNetworkObjPtr network, if (nbleases > 0) { char *leasefile = networkDnsmasqLeaseFileName(network->def->name); - if (!leasefile) { - virReportOOMError(); + if (!leasefile) goto cleanup; - } virBufferAsprintf(&configbuf, "dhcp-leasefile=%s\n", leasefile); VIR_FREE(leasefile); virBufferAsprintf(&configbuf, "dhcp-lease-max=%d\n", nbleases); @@ -1027,10 +1004,8 @@ networkBuildDhcpDaemonCommandLine(virNetworkObjPtr network, goto cleanup; /* construct the filename */ - if (!(configfile = networkDnsmasqConfigFileName(network->def->name))) { - virReportOOMError(); + if (!(configfile = networkDnsmasqConfigFileName(network->def->name))) goto cleanup; - } /* Write the file */ if (virFileWriteStr(configfile, configstr, 0600) < 0) { @@ -1077,10 +1052,8 @@ networkStartDhcpDaemon(struct network_driver *driver, } if (!(pidfile = virPidFileBuildPath(driverState->pidDir, - network->def->name))) { - virReportOOMError(); + network->def->name))) goto cleanup; - } if (virFileMakePath(driverState->dnsmasqStateDir) < 0) { virReportSystemError(errno, @@ -1330,10 +1303,8 @@ networkRadvdConfWrite(virNetworkObjPtr network, char **configFile) } /* construct the filename */ - if (!(*configFile = networkRadvdConfigFileName(network->def->name))) { - virReportOOMError(); + if (!(*configFile = networkRadvdConfigFileName(network->def->name))) goto cleanup; - } /* write the file */ if (virFileWriteStr(*configFile, configStr, 0600) < 0) { virReportSystemError(errno, @@ -1395,14 +1366,10 @@ networkStartRadvd(struct network_driver *driver ATTRIBUTE_UNUSED, } /* construct pidfile name */ - if (!(radvdpidbase = networkRadvdPidfileBasename(network->def->name))) { - virReportOOMError(); + if (!(radvdpidbase = networkRadvdPidfileBasename(network->def->name))) goto cleanup; - } - if (!(pidfile = virPidFileBuildPath(driverState->pidDir, radvdpidbase))) { - virReportOOMError(); + if (!(pidfile = virPidFileBuildPath(driverState->pidDir, radvdpidbase))) goto cleanup; - } if (networkRadvdConfWrite(network, &configfile) < 0) goto cleanup; @@ -2178,10 +2145,8 @@ networkSetIPv6Sysctls(virNetworkObjPtr network) * the network. */ if (virAsprintf(&field, SYSCTL_PATH "/net/ipv6/conf/%s/disable_ipv6", - network->def->bridge) < 0) { - virReportOOMError(); + network->def->bridge) < 0) goto cleanup; - } if (access(field, W_OK) < 0 && errno == ENOENT) { VIR_DEBUG("ipv6 appears to already be disabled on %s", @@ -2207,10 +2172,8 @@ networkSetIPv6Sysctls(virNetworkObjPtr network) * their own router advertisements. */ if (virAsprintf(&field, SYSCTL_PATH "/net/ipv6/conf/%s/accept_ra", - network->def->bridge) < 0) { - virReportOOMError(); + network->def->bridge) < 0) goto cleanup; - } if (virFileWriteStr(field, "0", 0) < 0) { virReportSystemError(errno, @@ -2223,10 +2186,8 @@ networkSetIPv6Sysctls(virNetworkObjPtr network) * definition), must always have autoconf=0. */ if (virAsprintf(&field, SYSCTL_PATH "/net/ipv6/conf/%s/autoconf", - network->def->bridge) < 0) { - virReportOOMError(); + network->def->bridge) < 0) goto cleanup; - } if (virFileWriteStr(field, "0", 0) < 0) { virReportSystemError(errno, @@ -2435,10 +2396,8 @@ networkStartNetworkVirtual(struct network_driver *driver, * address. */ macTapIfName = networkBridgeDummyNicName(network->def->bridge); - if (!macTapIfName) { - virReportOOMError(); + if (!macTapIfName) goto err0; - } /* Keep tun fd open and interface up to allow for IPv6 DAD to happen */ if (virNetDevTapCreateInBridgePort(network->def->bridge, &macTapIfName, &network->def->mac, @@ -2599,9 +2558,7 @@ static int networkShutdownNetworkVirtual(struct network_driver *driver ATTRIBUTE kill(network->radvdPid, SIGTERM); /* attempt to delete the pidfile we created */ - if (!(radvdpidbase = networkRadvdPidfileBasename(network->def->name))) { - virReportOOMError(); - } else { + if ((radvdpidbase = networkRadvdPidfileBasename(network->def->name))) { virPidFileDelete(driverState->pidDir, radvdpidbase); VIR_FREE(radvdpidbase); } @@ -2612,9 +2569,7 @@ static int networkShutdownNetworkVirtual(struct network_driver *driver ATTRIBUTE if (network->def->mac_specified) { char *macTapIfName = networkBridgeDummyNicName(network->def->bridge); - if (!macTapIfName) { - virReportOOMError(); - } else { + if (macTapIfName) { ignore_value(virNetDevTapDelete(macTapIfName)); VIR_FREE(macTapIfName); } @@ -3774,10 +3729,8 @@ networkCreateInterfacePool(virNetworkDefPtr netdef) { goto finish; } - if ((VIR_ALLOC_N(netdef->forward.ifs, num_virt_fns)) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(netdef->forward.ifs, num_virt_fns) < 0) goto finish; - } netdef->forward.nifs = num_virt_fns; @@ -3877,12 +3830,9 @@ networkAllocateActualDevice(virDomainNetDefPtr iface) bandwidth = portgroup->bandwidth; if (bandwidth) { - if (!iface->data.network.actual - && (VIR_ALLOC(iface->data.network.actual) < 0)) { - virReportOOMError(); + if (!iface->data.network.actual && + VIR_ALLOC(iface->data.network.actual) < 0) goto error; - } - if (virNetDevBandwidthCopy(&iface->data.network.actual->bandwidth, bandwidth) < 0) goto error; @@ -3897,11 +3847,9 @@ networkAllocateActualDevice(virDomainNetDefPtr iface) vlan = &netdef->vlan; if (vlan) { - if (!iface->data.network.actual - && (VIR_ALLOC(iface->data.network.actual) < 0)) { - virReportOOMError(); + if (!iface->data.network.actual && + VIR_ALLOC(iface->data.network.actual) < 0) goto error; - } if (virNetDevVlanCopy(&iface->data.network.actual->vlan, vlan) < 0) goto error; } @@ -3926,11 +3874,9 @@ networkAllocateActualDevice(virDomainNetDefPtr iface) * is VIR_DOMAIN_NET_TYPE_BRIDGE */ - if (!iface->data.network.actual - && (VIR_ALLOC(iface->data.network.actual) < 0)) { - virReportOOMError(); + if (!iface->data.network.actual && + VIR_ALLOC(iface->data.network.actual) < 0) goto error; - } iface->data.network.actual->type = actualType = VIR_DOMAIN_NET_TYPE_BRIDGE; if (VIR_STRDUP(iface->data.network.actual->data.bridge.brname, @@ -3964,11 +3910,9 @@ networkAllocateActualDevice(virDomainNetDefPtr iface) virDomainHostdevSubsysPciBackendType backend; - if (!iface->data.network.actual - && (VIR_ALLOC(iface->data.network.actual) < 0)) { - virReportOOMError(); + if (!iface->data.network.actual && + VIR_ALLOC(iface->data.network.actual) < 0) goto error; - } iface->data.network.actual->type = actualType = VIR_DOMAIN_NET_TYPE_HOSTDEV; if (netdef->forward.npfs > 0 && netdef->forward.nifs <= 0 && @@ -4053,11 +3997,9 @@ networkAllocateActualDevice(virDomainNetDefPtr iface) * VIR_DOMAIN_NET_TYPE_DIRECT. */ - if (!iface->data.network.actual - && (VIR_ALLOC(iface->data.network.actual) < 0)) { - virReportOOMError(); + if (!iface->data.network.actual && + VIR_ALLOC(iface->data.network.actual) < 0) goto error; - } /* Set type=direct and appropriate <source mode='xxx'/> */ iface->data.network.actual->type = actualType = VIR_DOMAIN_NET_TYPE_DIRECT; -- 1.8.1.5

On 07/04/13 14:06, Michal Privoznik wrote:
--- src/network/bridge_driver.c | 138 +++++++++++++------------------------------- 1 file changed, 40 insertions(+), 98 deletions(-)
ACK, Peter

--- src/nwfilter/nwfilter_dhcpsnoop.c | 29 +++++-------------- src/nwfilter/nwfilter_driver.c | 13 ++------- src/nwfilter/nwfilter_ebiptables_driver.c | 46 ++++++++++--------------------- src/nwfilter/nwfilter_gentech_driver.c | 24 ++++------------ src/nwfilter/nwfilter_learnipaddr.c | 12 ++------ 5 files changed, 33 insertions(+), 91 deletions(-) diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c b/src/nwfilter/nwfilter_dhcpsnoop.c index 708e67f..d21d6ef 100644 --- a/src/nwfilter/nwfilter_dhcpsnoop.c +++ b/src/nwfilter/nwfilter_dhcpsnoop.c @@ -303,10 +303,8 @@ virNWFilterSnoopActivate(virNWFilterSnoopReqPtr req) { char *key; - if (virAsprintf(&key, "%p-%d", req, req->ifindex) < 0) { - virReportOOMError(); + if (virAsprintf(&key, "%p-%d", req, req->ifindex) < 0) return NULL; - } virNWFilterSnoopActiveLock(); @@ -583,10 +581,8 @@ virNWFilterSnoopReqNew(const char *ifkey) return NULL; } - if (VIR_ALLOC(req) < 0) { - virReportOOMError(); + if (VIR_ALLOC(req) < 0) return NULL; - } req->threadStatus = THREAD_STATUS_NONE; @@ -762,10 +758,8 @@ virNWFilterSnoopReqLeaseAdd(virNWFilterSnoopReqPtr req, virNWFilterSnoopReqUnlock(req); - if (VIR_ALLOC(pl) < 0) { - virReportOOMError(); + if (VIR_ALLOC(pl) < 0) return -1; - } *pl = *plnew; /* protect req->threadkey */ @@ -1091,10 +1085,8 @@ virNWFilterSnoopDHCPOpen(const char *ifname, virMacAddr *mac, * more unlikely parameters first, then go for the MAC */ if (virAsprintf(&ext_filter, - "%s and ether src %s", filter, macaddr) < 0) { - virReportOOMError(); + "%s and ether src %s", filter, macaddr) < 0) return NULL; - } } else { /* * Some DHCP servers respond via MAC broadcast; we rely on later @@ -1195,10 +1187,8 @@ virNWFilterSnoopDHCPDecodeJobSubmit(virThreadPoolPtr pool, if (len <= MIN_VALID_DHCP_PKT_SIZE || len > sizeof(job->packet)) return 0; - if (VIR_ALLOC(job) < 0) { - virReportOOMError(); + if (VIR_ALLOC(job) < 0) return -1; - } memcpy(job->packet, pep, len); job->caplen = len; @@ -1633,10 +1623,8 @@ virNWFilterDHCPSnoopReq(virNWFilterTechDriverPtr techdriver, VIR_STRDUP(req->linkdev, linkdev) < 0) goto exit_snoopreqput; - if (!req->vars || tmp < 0) { - virReportOOMError(); + if (!req->vars || tmp < 0) goto exit_snoopreqput; - } /* check that all tools are available for applying the filters (late) */ if (!techdriver->canApplyBasicRules()) { @@ -1781,7 +1769,6 @@ virNWFilterSnoopLeaseFileWrite(int lfd, const char *ifkey, ifkey, ipstr, dhcpstr); if (len < 0) { - virReportOOMError(); ret = -1; goto cleanup; } @@ -2089,10 +2076,8 @@ virNWFilterDHCPSnoopInit(void) if (!virNWFilterSnoopState.ifnameToKey || !virNWFilterSnoopState.snoopReqs || - !virNWFilterSnoopState.active) { - virReportOOMError(); + !virNWFilterSnoopState.active) goto err_exit; - } virNWFilterSnoopLeaseFileLoad(); virNWFilterSnoopLeaseFileOpen(); diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c index 0fbc940..e264ef9 100644 --- a/src/nwfilter/nwfilter_driver.c +++ b/src/nwfilter/nwfilter_driver.c @@ -178,10 +178,8 @@ nwfilterStateInitialize(bool privileged, sysbus = virDBusGetSystemBus(); #endif /* WITH_DBUS */ - if (VIR_ALLOC(driverState) < 0) { - virReportOOMError(); + if (VIR_ALLOC(driverState) < 0) return -1; - } if (virMutexInit(&driverState->lock) < 0) goto err_free_driverstate; @@ -227,7 +225,7 @@ nwfilterStateInitialize(bool privileged, if (virAsprintf(&driverState->configDir, "%s/nwfilter", base) == -1) - goto out_of_memory; + goto error; VIR_FREE(base); @@ -240,9 +238,6 @@ nwfilterStateInitialize(bool privileged, return 0; -out_of_memory: - virReportOOMError(); - error: VIR_FREE(base); nwfilterDriverUnlock(driverState); @@ -518,10 +513,8 @@ nwfilterConnectListAllNWFilters(virConnectPtr conn, goto cleanup; } - if (VIR_ALLOC_N(tmp_filters, driver->nwfilters.count + 1) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(tmp_filters, driver->nwfilters.count + 1) < 0) goto cleanup; - } for (i = 0; i < driver->nwfilters.count; i++) { obj = driver->nwfilters.objs[i]; diff --git a/src/nwfilter/nwfilter_ebiptables_driver.c b/src/nwfilter/nwfilter_ebiptables_driver.c index 9a54de4..ab9e20f 100644 --- a/src/nwfilter/nwfilter_ebiptables_driver.c +++ b/src/nwfilter/nwfilter_ebiptables_driver.c @@ -494,10 +494,8 @@ ebiptablesAddRuleInst(virNWFilterRuleInstPtr res, { ebiptablesRuleInstPtr inst; - if (VIR_ALLOC(inst) < 0) { - virReportOOMError(); + if (VIR_ALLOC(inst) < 0) return -1; - } inst->commandTemplate = commandTemplate; inst->neededProtocolChain = neededChain; @@ -3016,10 +3014,8 @@ ebtablesCreateTmpSubChain(ebiptablesRuleInstPtr *inst, break; } - if (!protostr) { - virReportOOMError(); + if (!protostr) return -1; - } virBufferAsprintf(&buf, CMD_DEF("$EBT -t nat -F %s") CMD_SEPARATOR @@ -3393,10 +3389,8 @@ ebtablesApplyDHCPOnlyRules(const char *ifname, dhcpserver = virNWFilterVarValueGetNthValue(dhcpsrvrs, idx); - if (virAsprintf(&srcIPParam, "--ip-src %s", dhcpserver) < 0) { - virReportOOMError(); + if (virAsprintf(&srcIPParam, "--ip-src %s", dhcpserver) < 0) goto tear_down_tmpebchains; - } } /* @@ -3720,10 +3714,8 @@ ebiptablesApplyNewRules(const char *ifname, if (inst == NULL) nruleInstances = 0; - if (!chains_in_set || !chains_out_set) { - virReportOOMError(); + if (!chains_in_set || !chains_out_set) goto exit_free_sets; - } if (nruleInstances > 1 && inst) qsort(inst, nruleInstances, sizeof(inst[0]), @@ -3736,16 +3728,12 @@ ebiptablesApplyNewRules(const char *ifname, const char *name = inst[i]->neededProtocolChain; if (inst[i]->chainprefix == CHAINPREFIX_HOST_IN_TEMP) { if (virHashUpdateEntry(chains_in_set, name, - &inst[i]->chainPriority) < 0) { - virReportOOMError(); + &inst[i]->chainPriority) < 0) goto exit_free_sets; - } } else { if (virHashUpdateEntry(chains_out_set, name, - &inst[i]->chainPriority) < 0) { - virReportOOMError(); + &inst[i]->chainPriority) < 0) goto exit_free_sets; - } } } } @@ -4210,19 +4198,15 @@ ebiptablesDriverInitWithFirewallD(void) } else { VIR_INFO("firewalld support enabled for nwfilter"); - ignore_value(virAsprintf(&ebtables_cmd_path, - "%s --direct --passthrough eb", - firewall_cmd_path)); - ignore_value(virAsprintf(&iptables_cmd_path, - "%s --direct --passthrough ipv4", - firewall_cmd_path)); - ignore_value(virAsprintf(&ip6tables_cmd_path, - "%s --direct --passthrough ipv6", - firewall_cmd_path)); - - if (!ebtables_cmd_path || !iptables_cmd_path || - !ip6tables_cmd_path) { - virReportOOMError(); + if (virAsprintf(&ebtables_cmd_path, + "%s --direct --passthrough eb", + firewall_cmd_path) < 0 || + virAsprintf(&iptables_cmd_path, + "%s --direct --passthrough ipv4", + firewall_cmd_path) < 0 || + virAsprintf(&ip6tables_cmd_path, + "%s --direct --passthrough ipv6", + firewall_cmd_path) < 0) { VIR_FREE(ebtables_cmd_path); VIR_FREE(iptables_cmd_path); VIR_FREE(ip6tables_cmd_path); diff --git a/src/nwfilter/nwfilter_gentech_driver.c b/src/nwfilter/nwfilter_gentech_driver.c index 4180505..47f6dfb 100644 --- a/src/nwfilter/nwfilter_gentech_driver.c +++ b/src/nwfilter/nwfilter_gentech_driver.c @@ -110,10 +110,8 @@ int virNWFilterRuleInstAddData(virNWFilterRuleInstPtr res, void *data) { - if (VIR_REALLOC_N(res->data, res->ndata+1) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(res->data, res->ndata+1) < 0) return -1; - } res->data[res->ndata++] = data; return 0; } @@ -201,10 +199,8 @@ virNWFilterHashTablePtr virNWFilterCreateVarHashmap(char *macaddr, const virNWFilterVarValuePtr ipaddr) { virNWFilterHashTablePtr table = virNWFilterHashTableCreate(0); - if (!table) { - virReportOOMError(); + if (!table) return NULL; - } if (virNWFilterVarHashmapAddStdValues(table, macaddr, ipaddr) < 0) { virNWFilterHashTableFree(table); @@ -303,10 +299,8 @@ virNWFilterRuleInstantiate(virNWFilterTechDriverPtr techdriver, int i; virNWFilterRuleInstPtr ret; - if (VIR_ALLOC(ret) < 0) { - virReportOOMError(); + if (VIR_ALLOC(ret) < 0) return NULL; - } ret->techdriver = techdriver; @@ -340,10 +334,8 @@ virNWFilterCreateVarsFrom(virNWFilterHashTablePtr vars1, virNWFilterHashTablePtr vars2) { virNWFilterHashTablePtr res = virNWFilterHashTableCreate(0); - if (!res) { - virReportOOMError(); + if (!res) return NULL; - } if (virNWFilterHashTablePutAll(vars1, res) < 0) goto err_exit; @@ -415,7 +407,6 @@ _virNWFilterInstantiateRec(virNWFilterTechDriverPtr techdriver, } if (VIR_REALLOC_N(*insts, (*nEntries)+1) < 0) { - virReportOOMError(); rc = -1; break; } @@ -441,7 +432,6 @@ _virNWFilterInstantiateRec(virNWFilterTechDriverPtr techdriver, virNWFilterCreateVarsFrom(inc->params, vars); if (!tmpvars) { - virReportOOMError(); rc = -1; virNWFilterObjUnlock(obj); break; @@ -553,7 +543,6 @@ virNWFilterDetermineMissingVarsRec(virNWFilterDefPtr filter, virNWFilterCreateVarsFrom(inc->params, vars); if (!tmpvars) { - virReportOOMError(); rc = -1; virNWFilterObjUnlock(obj); break; @@ -611,10 +600,8 @@ virNWFilterRuleInstancesToArray(int nEntries, if ((*nptrs) == 0) return 0; - if (VIR_ALLOC_N((*ptrs), (*nptrs)) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N((*ptrs), (*nptrs)) < 0) return -1; - } (*nptrs) = 0; @@ -674,7 +661,6 @@ virNWFilterInstantiate(const unsigned char *vmuuid ATTRIBUTE_UNUSED, virNWFilterHashTablePtr missing_vars = virNWFilterHashTableCreate(0); if (!missing_vars) { - virReportOOMError(); rc = -1; goto err_exit; } diff --git a/src/nwfilter/nwfilter_learnipaddr.c b/src/nwfilter/nwfilter_learnipaddr.c index eabcf94..7e67203 100644 --- a/src/nwfilter/nwfilter_learnipaddr.c +++ b/src/nwfilter/nwfilter_learnipaddr.c @@ -143,10 +143,8 @@ virNWFilterLockIface(const char *ifname) { ifaceLock = virHashLookup(ifaceLockMap, ifname); if (!ifaceLock) { - if (VIR_ALLOC(ifaceLock) < 0) { - virReportOOMError(); + if (VIR_ALLOC(ifaceLock) < 0) goto err_exit; - } if (virMutexInitRecursive(&ifaceLock->lock) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -699,16 +697,12 @@ virNWFilterLearnIPAddress(virNWFilterTechDriverPtr techdriver, return -1; } - if (VIR_ALLOC(req) < 0) { - virReportOOMError(); + if (VIR_ALLOC(req) < 0) goto err_no_req; - } ht = virNWFilterHashTableCreate(0); - if (ht == NULL) { - virReportOOMError(); + if (ht == NULL) goto err_free_req; - } if (virNWFilterHashTablePutAll(filterparams, ht) < 0) goto err_free_ht; -- 1.8.1.5

On 07/04/13 14:06, Michal Privoznik wrote:
--- src/nwfilter/nwfilter_dhcpsnoop.c | 29 +++++-------------- src/nwfilter/nwfilter_driver.c | 13 ++------- src/nwfilter/nwfilter_ebiptables_driver.c | 46 ++++++++++--------------------- src/nwfilter/nwfilter_gentech_driver.c | 24 ++++------------ src/nwfilter/nwfilter_learnipaddr.c | 12 ++------ 5 files changed, 33 insertions(+), 91 deletions(-)
ACK. Peter

--- src/openvz/openvz_conf.c | 42 ++++++++++++++++-------------------------- src/openvz/openvz_driver.c | 10 +++------- 2 files changed, 19 insertions(+), 33 deletions(-) diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c index 90b4483..93f2377 100644 --- a/src/openvz/openvz_conf.c +++ b/src/openvz/openvz_conf.c @@ -225,14 +225,14 @@ openvzReadNetworkConf(virDomainDefPtr def, token = strtok_r(temp, " ", &saveptr); while (token != NULL) { if (VIR_ALLOC(net) < 0) - goto no_memory; + goto error; net->type = VIR_DOMAIN_NET_TYPE_ETHERNET; if (VIR_STRDUP(net->data.ethernet.ipaddr, token) < 0) goto error; if (VIR_REALLOC_N(def->nets, def->nnets + 1) < 0) - goto no_memory; + goto error; def->nets[def->nnets++] = net; net = NULL; @@ -256,7 +256,7 @@ openvzReadNetworkConf(virDomainDefPtr def, while (token != NULL) { /*add new device to list*/ if (VIR_ALLOC(net) < 0) - goto no_memory; + goto error; net->type = VIR_DOMAIN_NET_TYPE_BRIDGE; @@ -279,7 +279,7 @@ openvzReadNetworkConf(virDomainDefPtr def, } if (VIR_ALLOC_N(net->ifname, len+1) < 0) - goto no_memory; + goto error; if (virStrncpy(net->ifname, p, len, len+1) == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -296,7 +296,7 @@ openvzReadNetworkConf(virDomainDefPtr def, } if (VIR_ALLOC_N(net->data.bridge.brname, len+1) < 0) - goto no_memory; + goto error; if (virStrncpy(net->data.bridge.brname, p, len, len+1) == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -326,7 +326,7 @@ openvzReadNetworkConf(virDomainDefPtr def, } while (p < token + strlen(token)); if (VIR_REALLOC_N(def->nets, def->nnets + 1) < 0) - goto no_memory; + goto error; def->nets[def->nnets++] = net; net = NULL; @@ -337,8 +337,7 @@ openvzReadNetworkConf(virDomainDefPtr def, VIR_FREE(temp); return 0; -no_memory: - virReportOOMError(); + error: VIR_FREE(temp); virDomainNetDefFree(net); @@ -398,7 +397,7 @@ openvzReadFSConf(virDomainDefPtr def, goto error; } else if (ret > 0) { if (VIR_ALLOC(fs) < 0) - goto no_memory; + goto error; fs->type = VIR_DOMAIN_FS_TYPE_TEMPLATE; if (VIR_STRDUP(fs->src, temp) < 0) @@ -414,10 +413,10 @@ openvzReadFSConf(virDomainDefPtr def, } if (VIR_ALLOC(fs) < 0) - goto no_memory; + goto error; if (virAsprintf(&veid_str, "%d", veid) < 0) - goto no_memory; + goto error; fs->type = VIR_DOMAIN_FS_TYPE_MOUNT; if (!(fs->src = openvz_replace(temp, "$VEID", veid_str))) @@ -451,7 +450,7 @@ openvzReadFSConf(virDomainDefPtr def, } if (VIR_REALLOC_N(def->fss, def->nfss + 1) < 0) - goto no_memory; + goto error; def->fss[def->nfss++] = fs; fs = NULL; @@ -583,7 +582,7 @@ int openvzLoadDomains(struct openvz_driver *driver) { *line++ = '\0'; if (VIR_ALLOC(def) < 0) - goto no_memory; + goto cleanup; def->virtType = VIR_DOMAIN_VIRT_OPENVZ; @@ -592,7 +591,7 @@ int openvzLoadDomains(struct openvz_driver *driver) { else def->id = veid; if (virAsprintf(&def->name, "%i", veid) < 0) - goto no_memory; + goto cleanup; openvzGetVPSUUID(veid, uuidstr, sizeof(uuidstr)); ret = virUUIDParse(uuidstr, def->uuid); @@ -663,9 +662,6 @@ int openvzLoadDomains(struct openvz_driver *driver) { return 0; - no_memory: - virReportOOMError(); - cleanup: virCommandFree(cmd); VIR_FREE(temp); @@ -695,10 +691,8 @@ openvzWriteConfigParam(const char * conf_file, const char *param, const char *va char *line = NULL; size_t line_size = 0; - if (virAsprintf(&temp_file, "%s.tmp", conf_file)<0) { - virReportOOMError(); + if (virAsprintf(&temp_file, "%s.tmp", conf_file)<0) return -1; - } fp = fopen(conf_file, "r"); if (fp == NULL) @@ -899,10 +893,8 @@ openvzCopyDefaultConfig(int vpsid) goto cleanup; if (virAsprintf(&default_conf_file, "%s/ve-%s.conf-sample", confdir, - configfile_value) < 0) { - virReportOOMError(); + configfile_value) < 0) goto cleanup; - } if (openvzLocateConfFile(vpsid, &conf_file, "conf") < 0) goto cleanup; @@ -933,10 +925,8 @@ openvzLocateConfFileDefault(int vpsid, char **conffile, const char *ext) return -1; if (virAsprintf(conffile, "%s/%d.%s", confdir, vpsid, - ext ? ext : "conf") < 0) { - virReportOOMError(); + ext ? ext : "conf") < 0) ret = -1; - } VIR_FREE(confdir); return ret; diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index 7af0349..772e796 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -767,8 +767,7 @@ openvzGenerateVethName(int veid, char *dev_name_ve) if (sscanf(dev_name_ve, "%*[^0-9]%d", &ifNo) != 1) return NULL; - if (virAsprintf(&ret, "veth%d.%d.", veid, ifNo) < 0) - virReportOOMError(); + ignore_value(virAsprintf(&ret, "veth%d.%d.", veid, ifNo)); return ret; } @@ -795,8 +794,7 @@ openvzGenerateContainerVethName(int veid) } /* set new name */ - if (virAsprintf(&name, "eth%d", max + 1) < 0) - virReportOOMError(); + ignore_value(virAsprintf(&name, "eth%d", max + 1)); } VIR_FREE(temp); @@ -1448,10 +1446,8 @@ static virDrvOpenStatus openvzConnectOpen(virConnectPtr conn, /* We now know the URI is definitely for this driver, so beyond * here, don't return DECLINED, always use ERROR */ - if (VIR_ALLOC(driver) < 0) { - virReportOOMError(); + if (VIR_ALLOC(driver) < 0) return VIR_DRV_OPEN_ERROR; - } if (!(driver->domains = virDomainObjListNew())) goto cleanup; -- 1.8.1.5

On 07/04/2013 02:06 PM, Michal Privoznik wrote:
--- src/openvz/openvz_conf.c | 42 ++++++++++++++++-------------------------- src/openvz/openvz_driver.c | 10 +++------- 2 files changed, 19 insertions(+), 33 deletions(-)
ACK Jan

--- src/parallels/parallels_driver.c | 65 +++++++++++++++------------------------ src/parallels/parallels_network.c | 24 ++++----------- src/parallels/parallels_storage.c | 50 +++++++++--------------------- src/parallels/parallels_utils.c | 4 +-- 4 files changed, 46 insertions(+), 97 deletions(-) diff --git a/src/parallels/parallels_driver.c b/src/parallels/parallels_driver.c index d5e0ea3..dd4b13f 100644 --- a/src/parallels/parallels_driver.c +++ b/src/parallels/parallels_driver.c @@ -118,35 +118,34 @@ parallelsBuildCapabilities(void) if ((caps = virCapabilitiesNew(virArchFromHost(), 0, 0)) == NULL) - goto no_memory; + return NULL; if (nodeCapsInitNUMA(caps) < 0) - goto no_memory; + goto error; if ((guest = virCapabilitiesAddGuest(caps, "hvm", VIR_ARCH_X86_64, "parallels", NULL, 0, NULL)) == NULL) - goto no_memory; + goto error; if (virCapabilitiesAddGuestDomain(guest, "parallels", NULL, NULL, 0, NULL) == NULL) - goto no_memory; + goto error; if ((guest = virCapabilitiesAddGuest(caps, "exe", VIR_ARCH_X86_64, "parallels", NULL, 0, NULL)) == NULL) - goto no_memory; + goto error; if (virCapabilitiesAddGuestDomain(guest, "parallels", NULL, NULL, 0, NULL) == NULL) - goto no_memory; + goto error; return caps; - no_memory: - virReportOOMError(); + error: virObjectUnref(caps); return NULL; } @@ -227,20 +226,18 @@ parallelsAddSerialInfo(virDomainChrDefPtr **serials, size_t *nserials, virDomainChrDefPtr chr = NULL; if (!(chr = virDomainChrDefNew())) - goto no_memory; + goto cleanup; if (parallelsGetSerialInfo(chr, key, value)) goto cleanup; if (VIR_REALLOC_N(*serials, *nserials + 1) < 0) - goto no_memory; + goto cleanup; (*serials)[(*nserials)++] = chr; return 0; - no_memory: - virReportOOMError(); cleanup: virDomainChrDefFree(chr); return -1; @@ -271,13 +268,13 @@ parallelsAddVideoInfo(virDomainDefPtr def, virJSONValuePtr value) } if (VIR_ALLOC(video) < 0) - goto no_memory; + goto error; if (VIR_ALLOC(accel) < 0) - goto no_memory; + goto error; if (VIR_REALLOC_N(def->videos, def->nvideos + 1) < 0) - goto no_memory; + goto error; def->videos[def->nvideos++] = video; @@ -288,11 +285,9 @@ parallelsAddVideoInfo(virDomainDefPtr def, virJSONValuePtr value) return 0; -no_memory: - virReportOOMError(); +error: VIR_FREE(accel); virDomainVideoDefFree(video); -error: return -1; } @@ -386,20 +381,18 @@ parallelsAddHddInfo(virDomainDefPtr def, const char *key, virJSONValuePtr value) virDomainDiskDefPtr disk = NULL; if (VIR_ALLOC(disk) < 0) - goto no_memory; + goto error; if (parallelsGetHddInfo(def, disk, key, value)) goto error; if (VIR_REALLOC_N(def->disks, def->ndisks + 1) < 0) - goto no_memory; + goto error; def->disks[def->ndisks++] = disk; return 0; -no_memory: - virReportOOMError(); error: virDomainDiskDefFree(disk); return -1; @@ -508,20 +501,18 @@ parallelsAddNetInfo(virDomainDefPtr def, const char *key, virJSONValuePtr value) virDomainNetDefPtr net = NULL; if (VIR_ALLOC(net) < 0) - goto no_memory; + goto error; if (parallelsGetNetInfo(net, key, value)) goto error; if (VIR_EXPAND_N(def->nets, def->nnets, 1) < 0) - goto no_memory; + goto error; def->nets[def->nnets - 1] = net; return 0; -no_memory: - virReportOOMError(); error: virDomainNetDefFree(net); return -1; @@ -597,7 +588,7 @@ parallelsAddVNCInfo(virDomainDefPtr def, virJSONValuePtr jobj_root) } if (VIR_ALLOC(gr) < 0) - goto no_memory; + goto cleanup; if (STREQ(tmp, "auto")) { if (virJSONValueObjectGetNumberUint(jobj, "port", &port) < 0) @@ -625,7 +616,7 @@ parallelsAddVNCInfo(virDomainDefPtr def, virJSONValuePtr jobj_root) } if (VIR_ALLOC(gr->listens) < 0) - goto no_memory; + goto cleanup; gr->nListens = 1; @@ -635,13 +626,11 @@ 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) - goto no_memory; + goto cleanup; def->graphics[def->ngraphics++] = gr; return 0; - no_memory: - virReportOOMError(); cleanup: virDomainGraphicsDefFree(gr); return ret; @@ -665,7 +654,7 @@ parallelsLoadDomain(parallelsConnPtr privconn, virJSONValuePtr jobj) const char *state; if (VIR_ALLOC(def) < 0) - goto no_memory; + goto cleanup; def->virtType = VIR_DOMAIN_VIRT_PARALLELS; def->id = -1; @@ -771,7 +760,7 @@ parallelsLoadDomain(parallelsConnPtr privconn, virJSONValuePtr jobj) def->os.arch = VIR_ARCH_X86_64; if (VIR_ALLOC(pdom) < 0) - goto no_memory; + goto cleanup; if (virJSONValueObjectGetNumberUint(jobj, "EnvID", &x) < 0) goto cleanup; @@ -833,8 +822,6 @@ parallelsLoadDomain(parallelsConnPtr privconn, virJSONValuePtr jobj) return dom; - no_memory: - virReportOOMError(); cleanup: virDomainDefFree(def); parallelsDomObjFreePrivate(pdom); @@ -899,10 +886,8 @@ parallelsOpenDefault(virConnectPtr conn) { parallelsConnPtr privconn; - if (VIR_ALLOC(privconn) < 0) { - virReportOOMError(); + if (VIR_ALLOC(privconn) < 0) return VIR_DRV_OPEN_ERROR; - } if (virMutexInit(&privconn->lock) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot initialize mutex")); @@ -1800,10 +1785,8 @@ static int parallelsApplyIfaceParams(parallelsDomObjPtr pdom, if (!oldnet) { create = true; - if (VIR_ALLOC(oldnet) < 0) { - virReportOOMError(); + if (VIR_ALLOC(oldnet) < 0) return -1; - } } if (!create && oldnet->type != newnet->type) { diff --git a/src/parallels/parallels_network.c b/src/parallels/parallels_network.c index 26a3f13..6edd0f8 100644 --- a/src/parallels/parallels_network.c +++ b/src/parallels/parallels_network.c @@ -57,10 +57,8 @@ static int parallelsGetBridgedNetInfo(virNetworkDefPtr def, virJSONValuePtr jobj } if (virAsprintf(&bridgeLink, "%s/%s/brport/bridge", - SYSFS_NET_DIR, ifname) < 0) { - virReportOOMError(); + SYSFS_NET_DIR, ifname) < 0) goto cleanup; - } if (virFileResolveLink(bridgeLink, &bridgePath) < 0) { virReportSystemError(errno, _("cannot read link '%s'"), bridgeLink); @@ -71,10 +69,8 @@ static int parallelsGetBridgedNetInfo(virNetworkDefPtr def, virJSONValuePtr jobj goto cleanup; if (virAsprintf(&bridgeAddressPath, "%s/%s/brport/bridge/address", - SYSFS_NET_DIR, ifname) < 0) { - virReportOOMError(); + SYSFS_NET_DIR, ifname) < 0) goto cleanup; - } if ((len = virFileReadAll(bridgeAddressPath, 18, &bridgeAddress)) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -112,10 +108,8 @@ static int parallelsGetHostOnlyNetInfo(virNetworkDefPtr def, const char *name) virJSONValuePtr jobj = NULL, jobj2; int ret = -1; - if (VIR_EXPAND_N(def->ips, def->nips, 1) < 0) { - virReportOOMError(); + if (VIR_EXPAND_N(def->ips, def->nips, 1) < 0) goto cleanup; - } jobj = parallelsParseOutput("prlsrvctl", "net", "info", "-j", name, NULL); @@ -157,10 +151,8 @@ static int parallelsGetHostOnlyNetInfo(virNetworkDefPtr def, const char *name) goto cleanup; } - if (VIR_EXPAND_N(def->ips[0].ranges, def->ips[0].nranges, 1) < 0) { - virReportOOMError(); + if (VIR_EXPAND_N(def->ips[0].ranges, def->ips[0].nranges, 1) < 0) goto cleanup; - } if (!(tmp = virJSONValueObjectGetString(jobj2, "IP scope start address"))) { parallelsParseError(); @@ -198,7 +190,7 @@ parallelsLoadNetwork(parallelsConnPtr privconn, virJSONValuePtr jobj) unsigned char md5[MD5_DIGEST_SIZE]; if (VIR_ALLOC(def) < 0) - goto no_memory; + goto cleanup; if (!(tmp = virJSONValueObjectGetString(jobj, "Network ID"))) { parallelsParseError(); @@ -244,8 +236,6 @@ parallelsLoadNetwork(parallelsConnPtr privconn, virJSONValuePtr jobj) virNetworkObjUnlock(net); return net; -no_memory: - virReportOOMError(); cleanup: virNetworkDefFree(def); return NULL; @@ -258,7 +248,7 @@ parallelsAddRoutedNetwork(parallelsConnPtr privconn) virNetworkDefPtr def; if (VIR_ALLOC(def) < 0) - goto no_memory; + goto cleanup; def->forward.type = VIR_NETWORK_FORWARD_ROUTE; @@ -283,8 +273,6 @@ parallelsAddRoutedNetwork(parallelsConnPtr privconn) return net; -no_memory: - virReportOOMError(); cleanup: virNetworkDefFree(def); return NULL; diff --git a/src/parallels/parallels_storage.c b/src/parallels/parallels_storage.c index 3d55e82..2d52d92 100644 --- a/src/parallels/parallels_storage.c +++ b/src/parallels/parallels_storage.c @@ -106,10 +106,8 @@ parallelsFindVolumes(virStoragePoolObjPtr pool) continue; if (!(path = virFileBuildPath(pool->def->target.path, - ent->d_name, NULL))) { - virReportOOMError(); + ent->d_name, NULL))) goto cleanup; - } if (!parallelsStorageVolDefineXML(pool, NULL, path, false)) goto cleanup; @@ -170,13 +168,13 @@ parallelsPoolCreateByPath(virConnectPtr conn, const char *path) virStoragePoolObjPtr pool = NULL; if (VIR_ALLOC(def) < 0) - goto no_memory; + goto error; if (!(def->name = parallelsMakePoolName(conn, path))) goto error; if (VIR_ALLOC_N(def->uuid, VIR_UUID_BUFLEN)) - goto no_memory; + goto error; if (virUUIDGenerate(def->uuid)) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -199,8 +197,6 @@ parallelsPoolCreateByPath(virConnectPtr conn, const char *path) virStoragePoolObjUnlock(pool); return pool; -no_memory: - virReportOOMError(); error: virStoragePoolDefFree(def); if (pool) @@ -302,10 +298,10 @@ static int parallelsAddDiskVolume(virStoragePoolObjPtr pool, virStorageVolDefPtr def = NULL; if (VIR_ALLOC(def)) - goto no_memory; + goto error; if (virAsprintf(&def->name, "%s-%s", dom->def->name, diskName) < 0) - goto no_memory; + goto error; def->type = VIR_STORAGE_VOL_FILE; @@ -319,7 +315,7 @@ static int parallelsAddDiskVolume(virStoragePoolObjPtr pool, goto error; if (VIR_REALLOC_N(pool->volumes.objs, pool->volumes.count + 1) < 0) - goto no_memory; + goto error; pool->volumes.objs[pool->volumes.count++] = def; @@ -352,10 +348,8 @@ static int parallelsFindVmVolumes(virStoragePoolObjPtr pool, VIR_FREE(diskPath); VIR_FREE(diskDescPath); - if (!(diskPath = virFileBuildPath(pdom->home, ent->d_name, NULL))) { - virReportOOMError(); + if (!(diskPath = virFileBuildPath(pdom->home, ent->d_name, NULL))) goto cleanup; - } if (lstat(diskPath, &sb) < 0) { virReportSystemError(errno, @@ -368,10 +362,8 @@ static int parallelsFindVmVolumes(virStoragePoolObjPtr pool, continue; if (!(diskDescPath = virFileBuildPath(diskPath, - "DiskDescriptor", ".xml"))) { - virReportOOMError(); + "DiskDescriptor", ".xml"))) goto cleanup; - } if (access(diskDescPath, F_OK)) continue; @@ -422,11 +414,11 @@ static int parallelsLoadPools(virConnectPtr conn) /* Configuration path is /etc/libvirt/parallels-storage/... . */ if (virAsprintf(&storageState->configDir, "%s/parallels-storage", base) == -1) - goto out_of_memory; + goto error; if (virAsprintf(&storageState->autostartDir, "%s/parallels-storage/autostart", base) == -1) - goto out_of_memory; + goto error; VIR_FREE(base); @@ -459,8 +451,6 @@ static int parallelsLoadPools(virConnectPtr conn) return 0; -out_of_memory: - virReportOOMError(); error: VIR_FREE(base); return -1; @@ -477,10 +467,8 @@ parallelsStorageOpen(virConnectPtr conn, if (STRNEQ(conn->driver->name, "Parallels")) return VIR_DRV_OPEN_DECLINED; - if (VIR_ALLOC(storageState) < 0) { - virReportOOMError(); + if (VIR_ALLOC(storageState) < 0) return VIR_DRV_OPEN_ERROR; - } if (virMutexInit(&storageState->lock) < 0) { VIR_FREE(storageState); @@ -1244,16 +1232,12 @@ parallelsStorageVolDefineXML(virStoragePoolObjPtr pool, } } - if (VIR_REALLOC_N(pool->volumes.objs, pool->volumes.count + 1) < 0) { - virReportOOMError(); + 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) { - virReportOOMError(); + pool->def->target.path, privvol->name) < 0) goto cleanup; - } if (VIR_STRDUP(privvol->key, privvol->target.path) < 0) goto cleanup; @@ -1382,16 +1366,12 @@ parallelsStorageVolCreateXMLFrom(virStoragePoolPtr pool, privpool->def->allocation); if (VIR_REALLOC_N(privpool->volumes.objs, - privpool->volumes.count + 1) < 0) { - virReportOOMError(); + privpool->volumes.count + 1) < 0) goto cleanup; - } if (virAsprintf(&privvol->target.path, "%s/%s", - privpool->def->target.path, privvol->name) == -1) { - virReportOOMError(); + privpool->def->target.path, privvol->name) == -1) goto cleanup; - } if (VIR_STRDUP(privvol->key, privvol->target.path) < 0) goto cleanup; diff --git a/src/parallels/parallels_utils.c b/src/parallels/parallels_utils.c index 4236ed5..2f0bee5 100644 --- a/src/parallels/parallels_utils.c +++ b/src/parallels/parallels_utils.c @@ -130,10 +130,8 @@ parallelsAddFileExt(const char *path, const char *ext) char *new_path = NULL; size_t len = strlen(path) + strlen(ext) + 1; - if (VIR_ALLOC_N(new_path, len) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(new_path, len) < 0) return NULL; - } if (!virStrcpy(new_path, path, len)) { VIR_FREE(new_path); -- 1.8.1.5

On 07/04/2013 02:06 PM, Michal Privoznik wrote:
--- src/parallels/parallels_driver.c | 65 +++++++++++++++------------------------ src/parallels/parallels_network.c | 24 ++++----------- src/parallels/parallels_storage.c | 50 +++++++++--------------------- src/parallels/parallels_utils.c | 4 +-- 4 files changed, 46 insertions(+), 97 deletions(-)
diff --git a/src/parallels/parallels_driver.c b/src/parallels/parallels_driver.c index d5e0ea3..dd4b13f 100644 --- a/src/parallels/parallels_driver.c +++ b/src/parallels/parallels_driver.c @@ -118,35 +118,34 @@ parallelsBuildCapabilities(void)
if ((caps = virCapabilitiesNew(virArchFromHost(), 0, 0)) == NULL) - goto no_memory; + return NULL;
if (nodeCapsInitNUMA(caps) < 0) - goto no_memory; + goto error;
Call to virBitmapSetBit() needs to be adapted in nodeCapsInitNUMAFake() due to this hunk. ACK with that fixed. Martin

--- src/phyp/phyp_driver.c | 95 +++++++++++++------------------------------------- 1 file changed, 24 insertions(+), 71 deletions(-) diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index cae3b59..c515f3e 100644 --- a/src/phyp/phyp_driver.c +++ b/src/phyp/phyp_driver.c @@ -110,10 +110,8 @@ phypExec(LIBSSH2_SESSION *session, const char *cmd, int *exit_status, int sock = connection_data->sock; int rc = 0; - if (VIR_ALLOC_N(buffer, buffer_size) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(buffer, buffer_size) < 0) return NULL; - } /* Exec non-blocking on the remove host */ while ((channel = libssh2_channel_open_session(session)) == NULL && @@ -476,10 +474,8 @@ phypUUIDTable_Push(virConnectPtr conn) int ret = -1; if (virAsprintf(&remote_file, "/home/%s/libvirt_uuid_table", - NULLSTR(conn->uri->user)) < 0) { - virReportOOMError(); + NULLSTR(conn->uri->user)) < 0) goto cleanup; - } if (stat(local_file, &local_fileinfo) == -1) { VIR_WARN("Unable to stat local file."); @@ -580,15 +576,11 @@ phypUUIDTable_AddLpar(virConnectPtr conn, unsigned char *uuid, int id) unsigned int i = uuid_table->nlpars; i--; - if (VIR_REALLOC_N(uuid_table->lpars, uuid_table->nlpars) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(uuid_table->lpars, uuid_table->nlpars) < 0) goto err; - } - if (VIR_ALLOC(uuid_table->lpars[i]) < 0) { - virReportOOMError(); + if (VIR_ALLOC(uuid_table->lpars[i]) < 0) goto err; - } uuid_table->lpars[i]->id = id; memcpy(uuid_table->lpars[i]->uuid, uuid, VIR_UUID_BUFLEN); @@ -627,10 +619,8 @@ phypUUIDTable_ReadFile(virConnectPtr conn) rc = read(fd, &id, sizeof(int)); if (rc == sizeof(int)) { - if (VIR_ALLOC(uuid_table->lpars[i]) < 0) { - virReportOOMError(); + if (VIR_ALLOC(uuid_table->lpars[i]) < 0) goto err; - } uuid_table->lpars[i]->id = id; } else { VIR_WARN @@ -644,8 +634,7 @@ phypUUIDTable_ReadFile(virConnectPtr conn) goto err; } } - } else - virReportOOMError(); + } VIR_FORCE_CLOSE(fd); return 0; @@ -674,10 +663,8 @@ phypUUIDTable_Pull(virConnectPtr conn) int ret = -1; if (virAsprintf(&remote_file, "/home/%s/libvirt_uuid_table", - NULLSTR(conn->uri->user)) < 0) { - virReportOOMError(); + NULLSTR(conn->uri->user)) < 0) goto cleanup; - } /* Trying to stat the remote file. */ do { @@ -771,10 +758,8 @@ phypUUIDTable_Init(virConnectPtr conn) if ((nids_numdomains = phypConnectNumOfDomainsGeneric(conn, 2)) < 0) goto cleanup; - if (VIR_ALLOC_N(ids, nids_numdomains) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(ids, nids_numdomains) < 0) goto cleanup; - } if ((nids_listdomains = phypConnectListDomainsGeneric(conn, ids, nids_numdomains, 1)) < 0) @@ -800,20 +785,16 @@ phypUUIDTable_Init(virConnectPtr conn) table_created = true; if (VIR_ALLOC_N(uuid_table->lpars, uuid_table->nlpars) >= 0) { for (i = 0; i < uuid_table->nlpars; i++) { - if (VIR_ALLOC(uuid_table->lpars[i]) < 0) { - virReportOOMError(); + if (VIR_ALLOC(uuid_table->lpars[i]) < 0) goto cleanup; - } uuid_table->lpars[i]->id = ids[i]; if (virUUIDGenerate(uuid_table->lpars[i]->uuid) < 0) VIR_WARN("Unable to generate UUID for domain %d", ids[i]); } - } else { - virReportOOMError(); + } else goto cleanup; - } if (phypUUIDTable_WriteFile(conn) == -1) goto cleanup; @@ -890,10 +871,8 @@ escape_specialcharacters(const char *src) if (len == 0) return NULL; - if (VIR_ALLOC_N(dst, len + 1) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(dst, len + 1) < 0) return NULL; - } for (i = 0; i < len; i++) { switch (src[i]) { @@ -931,15 +910,11 @@ openSSHSession(virConnectPtr conn, virConnectAuthPtr auth, if (userhome == NULL) goto err; - if (virAsprintf(&pubkey, "%s/.ssh/id_rsa.pub", userhome) < 0) { - virReportOOMError(); + if (virAsprintf(&pubkey, "%s/.ssh/id_rsa.pub", userhome) < 0) goto err; - } - if (virAsprintf(&pvtkey, "%s/.ssh/id_rsa", userhome) < 0) { - virReportOOMError(); + if (virAsprintf(&pvtkey, "%s/.ssh/id_rsa", userhome) < 0) goto err; - } if (conn->uri->user != NULL) { if (VIR_STRDUP(username, conn->uri->user) < 0) @@ -1107,20 +1082,14 @@ phypConnectOpen(virConnectPtr conn, return VIR_DRV_OPEN_ERROR; } - if (VIR_ALLOC(phyp_driver) < 0) { - virReportOOMError(); + if (VIR_ALLOC(phyp_driver) < 0) goto failure; - } - if (VIR_ALLOC(uuid_table) < 0) { - virReportOOMError(); + if (VIR_ALLOC(uuid_table) < 0) goto failure; - } - if (VIR_ALLOC(connection_data) < 0) { - virReportOOMError(); + if (VIR_ALLOC(connection_data) < 0) goto failure; - } connection_data->sock = -1; if (conn->uri->path) { @@ -1161,10 +1130,8 @@ phypConnectOpen(virConnectPtr conn, phyp_driver->managed_system = managed_system; phyp_driver->uuid_table = uuid_table; - if ((phyp_driver->caps = phypCapsInit()) == NULL) { - virReportOOMError(); + if ((phyp_driver->caps = phypCapsInit()) == NULL) goto failure; - } if (!(phyp_driver->xmlopt = virDomainXMLOptionNew(NULL, NULL, NULL))) goto failure; @@ -1694,10 +1661,8 @@ phypDomainAttachDevice(virDomainPtr domain, const char *xml) virBuffer buf = VIR_BUFFER_INITIALIZER; char *domain_name = NULL; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) goto cleanup; - } domain_name = escape_specialcharacters(domain->name); @@ -1984,10 +1949,8 @@ phypStorageVolCreateXML(virStoragePoolPtr pool, virStorageVolPtr dup_vol = NULL; char *key = NULL; - if (VIR_ALLOC(spdef) < 0) { - virReportOOMError(); + if (VIR_ALLOC(spdef) < 0) return NULL; - } /* Filling spdef manually * */ @@ -2310,10 +2273,8 @@ phypStorageVolGetPath(virStorageVolPtr vol) if (!pv) goto cleanup; - if (virAsprintf(&path, "/%s/%s/%s", pv, ret, vol->name) < 0) { - virReportOOMError(); + if (virAsprintf(&path, "/%s/%s/%s", pv, ret, vol->name) < 0) goto cleanup; - } cleanup: VIR_FREE(ret); @@ -2597,25 +2558,17 @@ phypStoragePoolLookupByUUID(virConnectPtr conn, unsigned int i = 0; unsigned char *local_uuid = NULL; - if (VIR_ALLOC_N(local_uuid, VIR_UUID_BUFLEN) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(local_uuid, VIR_UUID_BUFLEN) < 0) goto err; - } - if ((npools = phypConnectNumOfStoragePools(conn)) == -1) { - virReportOOMError(); + if ((npools = phypConnectNumOfStoragePools(conn)) == -1) goto err; - } - if (VIR_ALLOC_N(pools, npools) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(pools, npools) < 0) goto err; - } - if ((gotpools = phypConnectListStoragePools(conn, pools, npools)) == -1) { - virReportOOMError(); + if ((gotpools = phypConnectListStoragePools(conn, pools, npools)) == -1) goto err; - } if (gotpools != npools) { virReportOOMError(); -- 1.8.1.5

On 07/04/2013 02:06 PM, Michal Privoznik wrote:
--- src/phyp/phyp_driver.c | 95 +++++++++++++------------------------------------- 1 file changed, 24 insertions(+), 71 deletions(-)
ACK, Martin

--- src/qemu/qemu_agent.c | 42 ++--- src/qemu/qemu_capabilities.c | 69 +++------ src/qemu/qemu_cgroup.c | 4 +- src/qemu/qemu_command.c | 355 +++++++++++++++---------------------------- src/qemu/qemu_conf.c | 88 ++++------- src/qemu/qemu_domain.c | 50 ++---- src/qemu/qemu_driver.c | 124 ++++----------- src/qemu/qemu_hotplug.c | 84 +++------- src/qemu/qemu_migration.c | 94 +++--------- src/qemu/qemu_monitor.c | 33 +--- src/qemu/qemu_monitor_json.c | 118 +++++--------- src/qemu/qemu_monitor_text.c | 233 +++++++--------------------- src/qemu/qemu_process.c | 70 +++------ 13 files changed, 395 insertions(+), 969 deletions(-) diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index 9914521..80cccf9 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -514,10 +514,8 @@ qemuAgentIORead(qemuAgentPtr mon) if (avail < 1024) { if (VIR_REALLOC_N(mon->buffer, - mon->bufferLength + 1024) < 0) { - virReportOOMError(); + mon->bufferLength + 1024) < 0) return -1; - } mon->bufferLength += 1024; avail += 1024; } @@ -919,10 +917,8 @@ qemuAgentGuestSync(qemuAgentPtr mon) if (virAsprintf(&sync_msg.txBuffer, "{\"execute\":\"guest-sync\", " - "\"arguments\":{\"id\":%llu}}", id) < 0) { - virReportOOMError(); + "\"arguments\":{\"id\":%llu}}", id) < 0) return -1; - } sync_msg.txLength = strlen(sync_msg.txBuffer); @@ -988,10 +984,8 @@ qemuAgentCommand(qemuAgentPtr mon, if (!(cmdstr = virJSONValueToString(cmd, false))) goto cleanup; - if (virAsprintf(&msg.txBuffer, "%s" LINE_ENDING, cmdstr) < 0) { - virReportOOMError(); + if (virAsprintf(&msg.txBuffer, "%s" LINE_ENDING, cmdstr) < 0) goto cleanup; - } msg.txLength = strlen(msg.txBuffer); VIR_DEBUG("Send command '%s' for write, seconds = %d", cmdstr, seconds); @@ -1147,10 +1141,10 @@ qemuAgentMakeCommand(const char *cmdname, va_start(args, cmdname); if (!(obj = virJSONValueNewObject())) - goto no_memory; + goto error; if (virJSONValueObjectAppendString(obj, "execute", cmdname) < 0) - goto no_memory; + goto error; while ((key = va_arg(args, char *)) != NULL) { int ret; @@ -1169,7 +1163,7 @@ qemuAgentMakeCommand(const char *cmdname, if (!jargs && !(jargs = virJSONValueNewObject())) - goto no_memory; + goto error; /* This doesn't support maps/arrays. This hasn't * proved to be a problem..... yet :-) */ @@ -1220,19 +1214,17 @@ qemuAgentMakeCommand(const char *cmdname, goto error; } if (ret < 0) - goto no_memory; + goto error; } if (jargs && virJSONValueObjectAppend(obj, "arguments", jargs) < 0) - goto no_memory; + goto error; va_end(args); return obj; -no_memory: - virReportOOMError(); error: virJSONValueFree(obj); virJSONValueFree(jargs); @@ -1497,10 +1489,8 @@ qemuAgentGetVCPUs(qemuAgentPtr mon, ndata = virJSONValueArraySize(data); - if (VIR_ALLOC_N(*info, ndata) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(*info, ndata) < 0) goto cleanup; - } for (i = 0; i < ndata; i++) { virJSONValuePtr entry = virJSONValueArrayGet(data, i); @@ -1562,23 +1552,23 @@ qemuAgentSetVCPUs(qemuAgentPtr mon, /* create the key data array */ if (!(cpus = virJSONValueNewArray())) - goto no_memory; + goto cleanup; for (i = 0; i < ninfo; i++) { qemuAgentCPUInfoPtr in = &info[i]; /* create single cpu object */ if (!(cpu = virJSONValueNewObject())) - goto no_memory; + goto cleanup; if (virJSONValueObjectAppendNumberInt(cpu, "logical-id", in->id) < 0) - goto no_memory; + goto cleanup; if (virJSONValueObjectAppendBoolean(cpu, "online", in->online) < 0) - goto no_memory; + goto cleanup; if (virJSONValueArrayAppend(cpus, cpu) < 0) - goto no_memory; + goto cleanup; cpu = NULL; } @@ -1606,8 +1596,4 @@ cleanup: virJSONValueFree(cpu); virJSONValueFree(cpus); return ret; - -no_memory: - virReportOOMError(); - goto cleanup; } diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 969b001..594ef97 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -400,7 +400,6 @@ virQEMUCapsParseMachineTypesStr(const char *output, VIR_REALLOC_N(qemuCaps->machineMaxCpus, qemuCaps->nmachineTypes + 1) < 0) { VIR_FREE(name); VIR_FREE(canonical); - virReportOOMError(); return -1; } qemuCaps->nmachineTypes++; @@ -499,10 +498,8 @@ virQEMUCapsParseX86Models(const char *output, if (*p == '\0' || *p == '\n') continue; - if (VIR_EXPAND_N(qemuCaps->cpuDefinitions, qemuCaps->ncpuDefinitions, 1) < 0) { - virReportOOMError(); + if (VIR_EXPAND_N(qemuCaps->cpuDefinitions, qemuCaps->ncpuDefinitions, 1) < 0) goto cleanup; - } if (next) len = next - p - 1; @@ -558,10 +555,8 @@ virQEMUCapsParsePPCModels(const char *output, if (*p == '\n') continue; - if (VIR_EXPAND_N(qemuCaps->cpuDefinitions, qemuCaps->ncpuDefinitions, 1) < 0) { - virReportOOMError(); + if (VIR_EXPAND_N(qemuCaps->cpuDefinitions, qemuCaps->ncpuDefinitions, 1) < 0) goto cleanup; - } len = t - p - 1; @@ -622,10 +617,8 @@ virQEMUCapsFindBinaryForArch(virArch hostarch, const char *archstr = virQEMUCapsArchToString(guestarch); char *binary; - if (virAsprintf(&binary, "qemu-system-%s", archstr) < 0) { - virReportOOMError(); + if (virAsprintf(&binary, "qemu-system-%s", archstr) < 0) return NULL; - } ret = virFindFileInPath(binary); VIR_FREE(binary); @@ -842,10 +835,8 @@ virQEMUCapsInitCPU(virCapsPtr caps, virNodeInfo nodeinfo; int ret = -1; - if (VIR_ALLOC(cpu) < 0) { - virReportOOMError(); + if (VIR_ALLOC(cpu) < 0) goto error; - } cpu->arch = arch; @@ -1536,10 +1527,8 @@ virQEMUCapsParseDeviceStrObjectTypes(const char *str, goto cleanup; } - if (VIR_EXPAND_N(typelist, ntypelist, 1) < 0) { - virReportOOMError(); + if (VIR_EXPAND_N(typelist, ntypelist, 1) < 0) goto cleanup; - } if (VIR_STRNDUP(typelist[ntypelist - 1], tmp, end-tmp) < 0) goto cleanup; } @@ -1591,10 +1580,8 @@ virQEMUCapsParseDeviceStrObjectProps(const char *str, _("Malformed QEMU device list string, missing '='")); goto cleanup; } - if (VIR_EXPAND_N(proplist, nproplist, 1) < 0) { - virReportOOMError(); + if (VIR_EXPAND_N(proplist, nproplist, 1) < 0) goto cleanup; - } if (VIR_STRNDUP(proplist[nproplist - 1], tmp, end-tmp) < 0) goto cleanup; } @@ -1735,12 +1722,11 @@ virQEMUCapsNew(void) return NULL; if (!(qemuCaps->flags = virBitmapNew(QEMU_CAPS_LAST))) - goto no_memory; + goto error; return qemuCaps; -no_memory: - virReportOOMError(); +error: virObjectUnref(qemuCaps); return NULL; } @@ -1762,7 +1748,7 @@ virQEMUCapsPtr virQEMUCapsNewCopy(virQEMUCapsPtr qemuCaps) ret->arch = qemuCaps->arch; if (VIR_ALLOC_N(ret->cpuDefinitions, qemuCaps->ncpuDefinitions) < 0) - goto no_memory; + goto error; ret->ncpuDefinitions = qemuCaps->ncpuDefinitions; for (i = 0; i < qemuCaps->ncpuDefinitions; i++) { if (VIR_STRDUP(ret->cpuDefinitions[i], qemuCaps->cpuDefinitions[i]) < 0) @@ -1770,11 +1756,11 @@ virQEMUCapsPtr virQEMUCapsNewCopy(virQEMUCapsPtr qemuCaps) } if (VIR_ALLOC_N(ret->machineTypes, qemuCaps->nmachineTypes) < 0) - goto no_memory; + goto error; if (VIR_ALLOC_N(ret->machineAliases, qemuCaps->nmachineTypes) < 0) - goto no_memory; + goto error; if (VIR_ALLOC_N(ret->machineMaxCpus, qemuCaps->nmachineTypes) < 0) - goto no_memory; + goto error; ret->nmachineTypes = qemuCaps->nmachineTypes; for (i = 0; i < qemuCaps->nmachineTypes; i++) { if (VIR_STRDUP(ret->machineTypes[i], qemuCaps->machineTypes[i]) < 0 || @@ -1785,8 +1771,6 @@ virQEMUCapsPtr virQEMUCapsNewCopy(virQEMUCapsPtr qemuCaps) return ret; -no_memory: - virReportOOMError(); error: virObjectUnref(ret); return NULL; @@ -1896,7 +1880,6 @@ int virQEMUCapsAddCPUDefinition(virQEMUCapsPtr qemuCaps, return -1; if (VIR_EXPAND_N(qemuCaps->cpuDefinitions, qemuCaps->ncpuDefinitions, 1) < 0) { VIR_FREE(tmp); - virReportOOMError(); return -1; } qemuCaps->cpuDefinitions[qemuCaps->ncpuDefinitions-1] = tmp; @@ -2108,18 +2091,12 @@ virQEMUCapsProbeQMPMachineTypes(virQEMUCapsPtr qemuCaps, if ((nmachines = qemuMonitorGetMachines(mon, &machines)) < 0) goto cleanup; - if (VIR_ALLOC_N(qemuCaps->machineTypes, nmachines) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(qemuCaps->machineTypes, nmachines) < 0) goto cleanup; - } - if (VIR_ALLOC_N(qemuCaps->machineAliases, nmachines) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(qemuCaps->machineAliases, nmachines) < 0) goto cleanup; - } - if (VIR_ALLOC_N(qemuCaps->machineMaxCpus, nmachines) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(qemuCaps->machineMaxCpus, nmachines) < 0) goto cleanup; - } for (i = 0; i < nmachines; i++) { if (VIR_STRDUP(qemuCaps->machineAliases[i], machines[i]->alias) < 0 || @@ -2506,14 +2483,10 @@ virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps, /* the ".sock" sufix is important to avoid a possible clash with a qemu * domain called "capabilities" */ - if (virAsprintf(&monpath, "%s/%s", libDir, "capabilities.monitor.sock") < 0) { - virReportOOMError(); + if (virAsprintf(&monpath, "%s/%s", libDir, "capabilities.monitor.sock") < 0) goto cleanup; - } - if (virAsprintf(&monarg, "unix:%s,server,nowait", monpath) < 0) { - virReportOOMError(); + if (virAsprintf(&monarg, "unix:%s,server,nowait", monpath) < 0) goto cleanup; - } /* ".pidfile" suffix is used rather than ".pid" to avoid a possible clash * with a qemu domain called "capabilities" @@ -2521,10 +2494,8 @@ virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps, * -daemonize we need QEMU to be allowed to create them, rather * than libvirtd. So we're using libDir which QEMU can write to */ - if (virAsprintf(&pidfile, "%s/%s", libDir, "capabilities.pidfile") < 0) { - virReportOOMError(); + if (virAsprintf(&pidfile, "%s/%s", libDir, "capabilities.pidfile") < 0) goto cleanup; - } memset(&config, 0, sizeof(config)); config.type = VIR_DOMAIN_CHR_TYPE_UNIX; @@ -2744,10 +2715,8 @@ virQEMUCapsCacheNew(const char *libDir, { virQEMUCapsCachePtr cache; - if (VIR_ALLOC(cache) < 0) { - virReportOOMError(); + if (VIR_ALLOC(cache) < 0) return NULL; - } if (virMutexInit(&cache->lock) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index 5f54ca6..06d0970 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -723,10 +723,8 @@ int qemuInitCgroup(virQEMUDriverPtr driver, if (!vm->def->resource && startup) { virDomainResourceDefPtr res; - if (VIR_ALLOC(res) < 0) { - virReportOOMError(); + if (VIR_ALLOC(res) < 0) goto cleanup; - } if (VIR_STRDUP(res->partition, "/machine") < 0) { VIR_FREE(res); diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index ba93233..7288ce7 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -545,10 +545,8 @@ qemuNetworkPrepareDevices(virDomainDefPtr def) def->name); goto cleanup; } - if (virDomainHostdevInsert(def, hostdev) < 0) { - virReportOOMError(); + if (virDomainHostdevInsert(def, hostdev) < 0) goto cleanup; - } } } ret = 0; @@ -599,10 +597,8 @@ char *qemuDeviceDriveHostAlias(virDomainDiskDefPtr disk, char *ret; if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE)) { - if (virAsprintf(&ret, "%s%s", QEMU_DRIVE_HOST_PREFIX, disk->info.alias) < 0) { - virReportOOMError(); - return NULL; - } + ignore_value(virAsprintf(&ret, "%s%s", QEMU_DRIVE_HOST_PREFIX, + disk->info.alias)); } else { ignore_value(VIR_STRDUP(ret, disk->info.alias)); } @@ -653,10 +649,8 @@ static int qemuAssignDeviceDiskAliasFixed(virDomainDiskDefPtr disk) return -1; } - if (ret == -1) { - virReportOOMError(); + if (ret == -1) return -1; - } disk->info.alias = dev_name; @@ -744,26 +738,22 @@ qemuAssignDeviceDiskAliasCustom(virDomainDefPtr def, disk->info.addr.drive.controller, disk->info.addr.drive.bus, disk->info.addr.drive.unit) < 0) - goto no_memory; + return -1; } else { if (virAsprintf(&disk->info.alias, "%s%d-%d-%d-%d", prefix, disk->info.addr.drive.controller, disk->info.addr.drive.bus, disk->info.addr.drive.target, disk->info.addr.drive.unit) < 0) - goto no_memory; + return -1; } } else { int idx = virDiskNameToIndex(disk->dst); if (virAsprintf(&disk->info.alias, "%s-disk%d", prefix, idx) < 0) - goto no_memory; + return -1; } return 0; - -no_memory: - virReportOOMError(); - return -1; } @@ -806,12 +796,7 @@ qemuAssignDeviceNetAlias(virDomainDefPtr def, virDomainNetDefPtr net, int idx) } } - if (virAsprintf(&net->info.alias, "net%d", idx) < 0) { - virReportOOMError(); - return -1; - } - - return 0; + return virAsprintf(&net->info.alias, "net%d", idx); } @@ -838,12 +823,9 @@ qemuAssignDeviceHostdevAlias(virDomainDefPtr def, virDomainHostdevDefPtr hostdev hostdev->source.subsys.u.scsi.adapter, hostdev->source.subsys.u.scsi.bus, hostdev->source.subsys.u.scsi.target, - hostdev->source.subsys.u.scsi.unit) < 0) { - virReportOOMError(); + hostdev->source.subsys.u.scsi.unit) < 0) return -1; - } } else if (virAsprintf(&hostdev->info->alias, "hostdev%d", idx) < 0) { - virReportOOMError(); return -1; } @@ -869,12 +851,7 @@ qemuAssignDeviceRedirdevAlias(virDomainDefPtr def, virDomainRedirdevDefPtr redir } } - if (virAsprintf(&redirdev->info.alias, "redir%d", idx) < 0) { - virReportOOMError(); - return -1; - } - - return 0; + return virAsprintf(&redirdev->info.alias, "redir%d", idx); } @@ -883,13 +860,7 @@ qemuAssignDeviceControllerAlias(virDomainControllerDefPtr controller) { const char *prefix = virDomainControllerTypeToString(controller->type); - if (virAsprintf(&controller->info.alias, "%s%d", prefix, - controller->idx) < 0) { - virReportOOMError(); - return -1; - } - - return 0; + return virAsprintf(&controller->info.alias, "%s%d", prefix, controller->idx); } @@ -920,11 +891,11 @@ qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps) for (i = 0; i < def->nfss; i++) { if (virAsprintf(&def->fss[i]->info.alias, "fs%d", i) < 0) - goto no_memory; + return -1; } for (i = 0; i < def->nsounds; i++) { if (virAsprintf(&def->sounds[i]->info.alias, "sound%d", i) < 0) - goto no_memory; + return -1; } for (i = 0; i < def->nhostdevs; i++) { if (qemuAssignDeviceHostdevAlias(def, def->hostdevs[i], i) < 0) @@ -936,7 +907,7 @@ qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps) } for (i = 0; i < def->nvideos; i++) { if (virAsprintf(&def->videos[i]->info.alias, "video%d", i) < 0) - goto no_memory; + return -1; } for (i = 0; i < def->ncontrollers; i++) { if (qemuAssignDeviceControllerAlias(def->controllers[i]) < 0) @@ -944,54 +915,50 @@ qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps) } for (i = 0; i < def->ninputs; i++) { if (virAsprintf(&def->inputs[i]->info.alias, "input%d", i) < 0) - goto no_memory; + return -1; } for (i = 0; i < def->nparallels; i++) { if (virAsprintf(&def->parallels[i]->info.alias, "parallel%d", i) < 0) - goto no_memory; + return -1; } for (i = 0; i < def->nserials; i++) { if (virAsprintf(&def->serials[i]->info.alias, "serial%d", i) < 0) - goto no_memory; + return -1; } for (i = 0; i < def->nchannels; i++) { if (virAsprintf(&def->channels[i]->info.alias, "channel%d", i) < 0) - goto no_memory; + return -1; } for (i = 0; i < def->nconsoles; i++) { if (virAsprintf(&def->consoles[i]->info.alias, "console%d", i) < 0) - goto no_memory; + return -1; } for (i = 0; i < def->nhubs; i++) { if (virAsprintf(&def->hubs[i]->info.alias, "hub%d", i) < 0) - goto no_memory; + return -1; } for (i = 0; i < def->nsmartcards; i++) { if (virAsprintf(&def->smartcards[i]->info.alias, "smartcard%d", i) < 0) - goto no_memory; + return -1; } if (def->watchdog) { if (virAsprintf(&def->watchdog->info.alias, "watchdog%d", 0) < 0) - goto no_memory; + return -1; } if (def->memballoon) { if (virAsprintf(&def->memballoon->info.alias, "balloon%d", 0) < 0) - goto no_memory; + return -1; } if (def->rng) { if (virAsprintf(&def->rng->info.alias, "rng%d", 0) < 0) - goto no_memory; + return -1; } if (def->tpm) { if (virAsprintf(&def->tpm->info.alias, "tpm%d", 0) < 0) - goto no_memory; + return -1; } return 0; - -no_memory: - virReportOOMError(); - return -1; } /* S390 ccw bus support */ @@ -1006,14 +973,10 @@ qemuCCWAddressAsString(virDomainDeviceCCWAddressPtr addr) { char *addrstr = NULL; - if (virAsprintf(&addrstr, "%x.%x.%04x", - addr->cssid, - addr->ssid, - addr->devno) < 0) { - virReportOOMError(); - return NULL; - } - + ignore_value(virAsprintf(&addrstr, "%x.%x.%04x", + addr->cssid, + addr->ssid, + addr->devno)); return addrstr; } @@ -1189,7 +1152,7 @@ qemuDomainCCWAddressSetCreate(void) qemuDomainCCWAddressSetPtr addrs = NULL; if (VIR_ALLOC(addrs) < 0) - goto no_memory; + goto cleanup; if (!(addrs->defined = virHashCreate(10, qemuDomainCCWAddressSetFreeEntry))) goto cleanup; @@ -1201,8 +1164,6 @@ qemuDomainCCWAddressSetCreate(void) addrs->next.assigned = 0; return addrs; -no_memory: - virReportOOMError(); cleanup: qemuDomainCCWAddressSetFree(addrs); return addrs; @@ -1456,10 +1417,8 @@ qemuDomainPCIAddressSetGrow(qemuDomainPCIAddressSetPtr addrs, i = addrs->nbuses; if (add <= 0) return 0; - if (VIR_EXPAND_N(addrs->used, addrs->nbuses, add) < 0) { - virReportOOMError(); + if (VIR_EXPAND_N(addrs->used, addrs->nbuses, add) < 0) return -1; - } /* reserve slot 0 on the new buses */ for (; i < addrs->nbuses; i++) addrs->used[i][0] = 0xFF; @@ -1471,14 +1430,11 @@ static char *qemuPCIAddressAsString(virDevicePCIAddressPtr addr) { char *str; - if (virAsprintf(&str, "%.4x:%.2x:%.2x.%.1x", - addr->domain, - addr->bus, - addr->slot, - addr->function) < 0) { - virReportOOMError(); - return NULL; - } + ignore_value(virAsprintf(&str, "%.4x:%.2x:%.2x.%.1x", + addr->domain, + addr->bus, + addr->slot, + addr->function)); return str; } @@ -1677,10 +1633,10 @@ qemuDomainPCIAddressSetPtr qemuDomainPCIAddressSetCreate(virDomainDefPtr def, int i; if (VIR_ALLOC(addrs) < 0) - goto no_memory; + goto error; if (VIR_ALLOC_N(addrs->used, nbuses) < 0) - goto no_memory; + goto error; addrs->nbuses = nbuses; addrs->dryRun = dryRun; @@ -1695,8 +1651,6 @@ qemuDomainPCIAddressSetPtr qemuDomainPCIAddressSetCreate(virDomainDefPtr def, return addrs; -no_memory: - virReportOOMError(); error: qemuDomainPCIAddressSetFree(addrs); return NULL; @@ -2508,7 +2462,7 @@ static int qemuAddRBDHost(virDomainDiskDefPtr disk, char *hostport) disk->nhosts++; if (VIR_REALLOC_N(disk->hosts, disk->nhosts) < 0) - goto no_memory; + goto error; if ((port = strchr(hostport, ']'))) { /* ipv6, strip brackets */ @@ -2531,19 +2485,17 @@ static int qemuAddRBDHost(virDomainDiskDefPtr disk, char *hostport) parts = virStringSplit(hostport, "\\:", 0); if (!parts) - goto no_memory; + goto error; disk->hosts[disk->nhosts-1].name = virStringJoin((const char **)parts, ":"); virStringFreeList(parts); if (!disk->hosts[disk->nhosts-1].name) - goto no_memory; + goto error; disk->hosts[disk->nhosts-1].transport = VIR_DOMAIN_DISK_PROTO_TRANS_TCP; disk->hosts[disk->nhosts-1].socket = NULL; return 0; -no_memory: - virReportOOMError(); error: VIR_FREE(disk->hosts[disk->nhosts-1].port); VIR_FREE(disk->hosts[disk->nhosts-1].name); @@ -2629,7 +2581,7 @@ qemuParseDriveURIString(virDomainDiskDefPtr def, virURIPtr uri, char *secret = NULL; if (VIR_ALLOC(def->hosts) < 0) - goto no_memory; + goto error; transp = strchr(uri->scheme, '+'); if (transp) @@ -2658,7 +2610,7 @@ qemuParseDriveURIString(virDomainDiskDefPtr def, virURIPtr uri, goto error; if (virAsprintf(&def->hosts->port, "%d", uri->port) < 0) - goto no_memory; + goto error; } else { def->hosts->name = NULL; def->hosts->port = 0; @@ -2701,8 +2653,6 @@ cleanup: return ret; -no_memory: - virReportOOMError(); error: virDomainDiskHostDefFree(def->hosts); VIR_FREE(def->hosts); @@ -2761,7 +2711,7 @@ qemuParseNBDString(virDomainDiskDefPtr disk) } if (VIR_ALLOC(h) < 0) - goto no_memory; + goto error; host = disk->src + strlen("nbd:"); if (STRPREFIX(host, "unix:/")) { @@ -2805,8 +2755,6 @@ qemuParseNBDString(virDomainDiskDefPtr disk) disk->hosts = h; return 0; -no_memory: - virReportOOMError(); error: virDomainDiskHostDefFree(h); VIR_FREE(h); @@ -2848,11 +2796,11 @@ qemuBuildDriveURIString(virConnectPtr conn, goto cleanup; } else { if (virAsprintf(&tmpscheme, "%s+%s", scheme, transp) < 0) - goto no_memory; + goto cleanup; } if (disk->src && virAsprintf(&volimg, "/%s", disk->src) < 0) - goto no_memory; + goto cleanup; if (disk->hosts->port) { port = atoi(disk->hosts->port); @@ -2860,7 +2808,7 @@ qemuBuildDriveURIString(virConnectPtr conn, if (disk->hosts->socket && virAsprintf(&sock, "socket=%s", disk->hosts->socket) < 0) - goto no_memory; + goto cleanup; if (disk->auth.username && secretType != VIR_SECRET_USAGE_TYPE_NONE) { /* look up secret */ @@ -2886,7 +2834,7 @@ qemuBuildDriveURIString(virConnectPtr conn, goto cleanup; } if (virAsprintf(&user, "%s:%s", disk->auth.username, secret) < 0) - goto no_memory; + goto cleanup; } else { virReportError(VIR_ERR_INTERNAL_ERROR, _("%s username '%s' specified but secret not found"), @@ -2917,10 +2865,6 @@ cleanup: VIR_FREE(user); return ret; - -no_memory: - virReportOOMError(); - goto cleanup; } static int @@ -4025,19 +3969,15 @@ qemuBuildNicStr(virDomainNetDefPtr net, char *str; char macaddr[VIR_MAC_STRING_BUFLEN]; - if (virAsprintf(&str, - "%smacaddr=%s,vlan=%d%s%s%s%s", - prefix ? prefix : "", - virMacAddrFormat(&net->mac, macaddr), - vlan, - (net->model ? ",model=" : ""), - (net->model ? net->model : ""), - (net->info.alias ? ",name=" : ""), - (net->info.alias ? net->info.alias : "")) < 0) { - virReportOOMError(); - return NULL; - } - + ignore_value(virAsprintf(&str, + "%smacaddr=%s,vlan=%d%s%s%s%s", + prefix ? prefix : "", + virMacAddrFormat(&net->mac, macaddr), + vlan, + (net->model ? ",model=" : ""), + (net->model ? net->model : ""), + (net->info.alias ? ",name=" : ""), + (net->info.alias ? net->info.alias : ""))); return str; } @@ -4540,10 +4480,8 @@ qemuOpenPCIConfig(virDomainHostdevDefPtr dev) dev->source.subsys.u.pci.addr.domain, dev->source.subsys.u.pci.addr.bus, dev->source.subsys.u.pci.addr.slot, - dev->source.subsys.u.pci.addr.function) < 0) { - virReportOOMError(); + dev->source.subsys.u.pci.addr.function) < 0) return -1; - } configfd = open(path, O_RDWR, 0); @@ -4599,12 +4537,10 @@ qemuBuildPCIHostdevPCIDevStr(virDomainHostdevDefPtr dev) { char *ret = NULL; - if (virAsprintf(&ret, "host=%.2x:%.2x.%.1x", - dev->source.subsys.u.pci.addr.bus, - dev->source.subsys.u.pci.addr.slot, - dev->source.subsys.u.pci.addr.function) < 0) - virReportOOMError(); - + ignore_value(virAsprintf(&ret, "host=%.2x:%.2x.%.1x", + dev->source.subsys.u.pci.addr.bus, + dev->source.subsys.u.pci.addr.slot, + dev->source.subsys.u.pci.addr.function)); return ret; } @@ -4794,11 +4730,9 @@ qemuBuildUSBHostdevUsbDevStr(virDomainHostdevDefPtr dev) return NULL; } - if (virAsprintf(&ret, "host:%d.%d", - dev->source.subsys.u.usb.bus, - dev->source.subsys.u.usb.device) < 0) - virReportOOMError(); - + ignore_value(virAsprintf(&ret, "host:%d.%d", + dev->source.subsys.u.usb.bus, + dev->source.subsys.u.usb.device)); return ret; } @@ -5693,10 +5627,8 @@ qemuBuildCpuArgStr(const virQEMUDriverPtr driver, } virBufferAddLit(&buf, "host"); } else { - if (VIR_ALLOC(guest) < 0) { - virReportOOMError(); + if (VIR_ALLOC(guest) < 0) goto cleanup; - } if (VIR_STRDUP(guest->vendor_id, cpu->vendor_id) < 0) goto cleanup; @@ -6092,7 +6024,7 @@ qemuBuildGraphicsVNCCommandLine(virQEMUDriverConfigPtr cfg, if (!graphics->data.vnc.socket && virAsprintf(&graphics->data.vnc.socket, "%s/%s.vnc", cfg->libDir, def->name) == -1) - goto no_memory; + goto error; virBufferAsprintf(&opt, "unix:%s", graphics->data.vnc.socket); @@ -6207,8 +6139,6 @@ qemuBuildGraphicsVNCCommandLine(virQEMUDriverConfigPtr cfg, return 0; -no_memory: - virReportOOMError(); error: VIR_FREE(netAddr); virBufferFreeAndReset(&opt); @@ -6526,19 +6456,15 @@ qemuBuildInterfaceCommandLine(virCommandPtr cmd, tapfdSize = 1; if (VIR_ALLOC_N(tapfd, tapfdSize) < 0 || - VIR_ALLOC_N(tapfdName, tapfdSize) < 0) { - virReportOOMError(); + VIR_ALLOC_N(tapfdName, tapfdSize) < 0) goto cleanup; - } if (qemuNetworkIfaceConnect(def, conn, driver, net, qemuCaps, tapfd, &tapfdSize) < 0) goto cleanup; } else if (actualType == VIR_DOMAIN_NET_TYPE_DIRECT) { - if (VIR_ALLOC(tapfd) < 0 || VIR_ALLOC(tapfdName) < 0) { - virReportOOMError(); + if (VIR_ALLOC(tapfd) < 0 || VIR_ALLOC(tapfdName) < 0) goto cleanup; - } tapfdSize = 1; tapfd[0] = qemuPhysIfaceConnect(def, driver, net, qemuCaps, vmop); @@ -6557,10 +6483,8 @@ qemuBuildInterfaceCommandLine(virCommandPtr cmd, vhostfdSize = 1; if (VIR_ALLOC_N(vhostfd, vhostfdSize) < 0 || - VIR_ALLOC_N(vhostfdName, vhostfdSize)) { - virReportOOMError(); + VIR_ALLOC_N(vhostfdName, vhostfdSize)) goto cleanup; - } if (qemuOpenVhostNet(def, net, qemuCaps, vhostfd, &vhostfdSize) < 0) goto cleanup; @@ -6568,18 +6492,14 @@ qemuBuildInterfaceCommandLine(virCommandPtr cmd, for (i = 0; i < tapfdSize; i++) { virCommandTransferFD(cmd, tapfd[i]); - if (virAsprintf(&tapfdName[i], "%d", tapfd[i]) < 0) { - virReportOOMError(); + if (virAsprintf(&tapfdName[i], "%d", tapfd[i]) < 0) goto cleanup; - } } for (i = 0; i < vhostfdSize; i++) { virCommandTransferFD(cmd, vhostfd[i]); - if (virAsprintf(&vhostfdName[i], "%d", vhostfd[i]) < 0) { - virReportOOMError(); + if (virAsprintf(&vhostfdName[i], "%d", vhostfd[i]) < 0) goto cleanup; - } } /* Possible combinations: @@ -7512,10 +7432,8 @@ qemuBuildCommandLine(virConnectPtr conn, else fmt = "fat:%s"; - if (virAsprintf(&file, fmt, disk->src) < 0) { - virReportOOMError(); + if (virAsprintf(&file, fmt, disk->src) < 0) goto error; - } } else if (disk->type == VIR_DOMAIN_DISK_TYPE_NETWORK) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("network disks are only supported with -drive")); @@ -8165,10 +8083,8 @@ qemuBuildCommandLine(virConnectPtr conn, } else { int size = 100; char *modstr; - if (VIR_ALLOC_N(modstr, size+1) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(modstr, size+1) < 0) goto error; - } for (i = 0; i < def->nsounds && size > 0; i++) { virDomainSoundDefPtr sound = def->sounds[i]; @@ -8365,7 +8281,6 @@ qemuBuildCommandLine(virConnectPtr conn, if (configfd >= 0) { if (virAsprintf(&configfd_name, "%d", configfd) < 0) { VIR_FORCE_CLOSE(configfd); - virReportOOMError(); goto error; } @@ -8696,7 +8611,7 @@ static int qemuStringToArgvEnv(const char *args, if (argalloc == argcount) { if (VIR_REALLOC_N(arglist, argalloc+10) < 0) { VIR_FREE(arg); - goto no_memory; + goto error; } argalloc+=10; } @@ -8719,7 +8634,7 @@ static int qemuStringToArgvEnv(const char *args, /* Copy the list of env vars */ if (envend > 0) { if (VIR_REALLOC_N(progenv, envend+1) < 0) - goto no_memory; + goto error; for (i = 0; i < envend; i++) { progenv[i] = arglist[i]; arglist[i] = NULL; @@ -8729,7 +8644,7 @@ static int qemuStringToArgvEnv(const char *args, /* Copy the list of argv */ if (VIR_REALLOC_N(progargv, argcount-envend + 1) < 0) - goto no_memory; + goto error; for (i = envend; i < argcount; i++) progargv[i-envend] = arglist[i]; progargv[i-envend] = NULL; @@ -8741,8 +8656,6 @@ static int qemuStringToArgvEnv(const char *args, return 0; -no_memory: - virReportOOMError(); error: for (i = 0; progenv && progenv[i]; i++) VIR_FREE(progenv[i]); @@ -8849,7 +8762,7 @@ qemuParseKeywords(const char *str, VIR_REALLOC_N(values, keywordAlloc + 10) < 0) { VIR_FREE(keyword); VIR_FREE(value); - goto no_memory; + goto error; } keywordAlloc += 10; } @@ -8866,8 +8779,6 @@ qemuParseKeywords(const char *str, return keywordCount; -no_memory: - virReportOOMError(); error: for (i = 0; i < keywordCount; i++) { VIR_FREE(keywords[i]); @@ -8906,10 +8817,8 @@ qemuParseCommandLineDisk(virDomainXMLOptionPtr xmlopt, &values, 0)) < 0) return NULL; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) goto cleanup; - } def->bus = VIR_DOMAIN_DISK_BUS_IDE; def->device = VIR_DOMAIN_DISK_DEVICE_DISK; @@ -8974,10 +8883,8 @@ qemuParseCommandLineDisk(virDomainXMLOptionPtr xmlopt, goto error; } *vdi++ = '\0'; - if (VIR_ALLOC(def->hosts) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def->hosts) < 0) goto error; - } def->nhosts = 1; def->hosts->name = def->src; if (VIR_STRDUP(def->hosts->port, port) < 0) @@ -9261,10 +9168,8 @@ qemuParseCommandLineNet(virDomainXMLOptionPtr xmlopt, nkeywords = 0; } - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) goto cleanup; - } /* 'tap' could turn into libvirt type=ethernet, type=bridge or * type=network, but we can't tell, so use the generic config */ @@ -9546,7 +9451,7 @@ qemuParseCommandLineChr(virDomainChrSourceDefPtr source, host2++; if (svc2 && svc2 != host2 && VIR_STRNDUP(source->data.udp.bindHost, host2, svc2 - host2) < 0) - goto no_memory; + goto error; } if (svc2) { @@ -9601,8 +9506,6 @@ qemuParseCommandLineChr(virDomainChrSourceDefPtr source, return 0; -no_memory: - virReportOOMError(); error: return -1; } @@ -9614,10 +9517,8 @@ qemuInitGuestCPU(virDomainDefPtr dom) if (!dom->cpu) { virCPUDefPtr cpu; - if (VIR_ALLOC(cpu) < 0) { - virReportOOMError(); + if (VIR_ALLOC(cpu) < 0) return NULL; - } cpu->type = VIR_CPU_TYPE_GUEST; cpu->match = VIR_CPU_MATCH_EXACT; @@ -9684,7 +9585,7 @@ qemuParseCommandLineCPU(virDomainDefPtr dom, if (j == dom->clock.ntimers) { if (VIR_REALLOC_N(dom->clock.timers, j + 1) < 0 || VIR_ALLOC(dom->clock.timers[j]) < 0) - goto no_memory; + goto cleanup; dom->clock.timers[j]->name = VIR_DOMAIN_TIMER_NAME_KVMCLOCK; dom->clock.timers[j]->present = present; dom->clock.timers[j]->tickpolicy = -1; @@ -9808,10 +9709,6 @@ syntax: virReportError(VIR_ERR_INTERNAL_ERROR, _("unknown CPU syntax '%s'"), val); goto cleanup; - -no_memory: - virReportOOMError(); - goto cleanup; } @@ -9951,11 +9848,11 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, } if (VIR_ALLOC(def) < 0) - goto no_memory; + goto error; /* allocate the cmdlinedef up-front; if it's unused, we'll free it later */ if (VIR_ALLOC(cmd) < 0) - goto no_memory; + goto error; if (virUUIDGenerate(def->uuid) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -10028,7 +9925,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, WANT_VALUE(); if (STRPREFIX(val, "nic")) { if (VIR_REALLOC_N(nics, nnics+1) < 0) - goto no_memory; + goto error; nics[nnics++] = val; } } @@ -10047,7 +9944,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, char *tmp; WANT_VALUE(); if (VIR_ALLOC(vnc) < 0) - goto no_memory; + goto error; vnc->type = VIR_DOMAIN_GRAPHICS_TYPE_VNC; if (STRPREFIX(val, "unix:")) { @@ -10090,7 +9987,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, val, tmp-val, true); if (!virDomainGraphicsListenGetAddress(vnc, 0)) { virDomainGraphicsDefFree(vnc); - goto no_memory; + goto error; } if (*opts == ',') { @@ -10166,7 +10063,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, if (VIR_REALLOC_N(def->graphics, def->ngraphics+1) < 0) { virDomainGraphicsDefFree(vnc); - goto no_memory; + goto error; } def->graphics[def->ngraphics++] = vnc; } else if (STREQ(arg, "-m")) { @@ -10195,7 +10092,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, STREQ(arg, "-cdrom")) { WANT_VALUE(); if (VIR_ALLOC(disk) < 0) - goto no_memory; + goto error; if (STRPREFIX(val, "/dev/")) disk->type = VIR_DOMAIN_DISK_TYPE_BLOCK; @@ -10265,7 +10162,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, } *vdi++ = '\0'; if (VIR_ALLOC(disk->hosts) < 0) - goto no_memory; + goto error; disk->nhosts = 1; disk->hosts->name = disk->src; if (VIR_STRDUP(disk->hosts->port, port) < 0) @@ -10289,7 +10186,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, if (!(disk->src || disk->nhosts > 0) || !disk->dst) - goto no_memory; + goto error; if (virDomainDiskDefAssignAddress(xmlopt, disk) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -10299,7 +10196,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, } if (VIR_REALLOC_N(def->disks, def->ndisks+1) < 0) - goto no_memory; + goto error; def->disks[def->ndisks++] = disk; disk = NULL; } else if (STREQ(arg, "-no-acpi")) { @@ -10432,7 +10329,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, } if (VIR_REALLOC_N(def->serials, def->nserials+1) < 0) { virDomainChrDefFree(chr); - goto no_memory; + goto error; } chr->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL; chr->target.port = def->nserials; @@ -10452,7 +10349,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, } if (VIR_REALLOC_N(def->parallels, def->nparallels+1) < 0) { virDomainChrDefFree(chr); - goto no_memory; + goto error; } chr->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL; chr->target.port = def->nparallels; @@ -10464,7 +10361,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, STREQ(val, "mouse")) { virDomainInputDefPtr input; if (VIR_ALLOC(input) < 0) - goto no_memory; + goto error; input->bus = VIR_DOMAIN_INPUT_BUS_USB; if (STREQ(val, "tablet")) input->type = VIR_DOMAIN_INPUT_TYPE_TABLET; @@ -10472,12 +10369,12 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, input->type = VIR_DOMAIN_INPUT_TYPE_MOUSE; if (VIR_REALLOC_N(def->inputs, def->ninputs+1) < 0) { virDomainInputDefFree(input); - goto no_memory; + goto error; } def->inputs[def->ninputs++] = input; } else if (STRPREFIX(val, "disk:")) { if (VIR_ALLOC(disk) < 0) - goto no_memory; + goto error; if (VIR_STRDUP(disk->src, val + strlen("disk:")) < 0) goto error; if (STRPREFIX(disk->src, "/dev/")) @@ -10489,7 +10386,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, if (VIR_STRDUP(disk->dst, "sda") < 0) goto error; if (VIR_REALLOC_N(def->disks, def->ndisks+1) < 0) - goto no_memory; + goto error; def->disks[def->ndisks++] = disk; disk = NULL; } else { @@ -10498,7 +10395,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, goto error; if (VIR_REALLOC_N(def->hostdevs, def->nhostdevs+1) < 0) { virDomainHostdevDefFree(hostdev); - goto no_memory; + goto error; } def->hostdevs[def->nhostdevs++] = hostdev; } @@ -10510,7 +10407,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, goto error; if (VIR_REALLOC_N(def->nets, def->nnets+1) < 0) { virDomainNetDefFree(net); - goto no_memory; + goto error; } def->nets[def->nnets++] = net; } @@ -10521,7 +10418,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, ceph_args != NULL))) goto error; if (VIR_REALLOC_N(def->disks, def->ndisks+1) < 0) - goto no_memory; + goto error; if (disk->bus == VIR_DOMAIN_DISK_BUS_VIRTIO) nvirtiodisk++; @@ -10534,7 +10431,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, goto error; if (VIR_REALLOC_N(def->hostdevs, def->nhostdevs+1) < 0) { virDomainHostdevDefFree(hostdev); - goto no_memory; + goto error; } def->hostdevs[def->nhostdevs++] = hostdev; } else if (STREQ(arg, "-soundhw")) { @@ -10559,11 +10456,11 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, if (type != -1) { virDomainSoundDefPtr snd; if (VIR_ALLOC(snd) < 0) - goto no_memory; + goto error; snd->model = type; if (VIR_REALLOC_N(def->sounds, def->nsounds+1) < 0) { VIR_FREE(snd); - goto no_memory; + goto error; } def->sounds[def->nsounds++] = snd; } @@ -10577,7 +10474,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, if (model != -1) { virDomainWatchdogDefPtr wd; if (VIR_ALLOC(wd) < 0) - goto no_memory; + goto error; wd->model = model; wd->action = VIR_DOMAIN_WATCHDOG_ACTION_RESET; def->watchdog = wd; @@ -10616,7 +10513,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, } else if (STREQ(arg, "-usb")) { virDomainControllerDefPtr ctldef; if (VIR_ALLOC(ctldef) < 0) - goto no_memory; + goto error; ctldef->type = VIR_DOMAIN_CONTROLLER_TYPE_USB; ctldef->idx = 0; ctldef->model = -1; @@ -10635,7 +10532,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, virDomainChrSourceDefPtr chr; if (VIR_ALLOC(chr) < 0) - goto no_memory; + goto error; if (qemuParseCommandLineChr(chr, val) < 0) { virDomainChrSourceDefFree(chr); @@ -10685,7 +10582,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, WANT_VALUE(); if (VIR_ALLOC(def->nvram) < 0) - goto no_memory; + goto error; def->nvram->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO; def->nvram->info.addr.spaprvio.has_reg = true; @@ -10706,7 +10603,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, VIR_WARN("unknown QEMU argument '%s', adding to the qemu namespace", arg); if (VIR_REALLOC_N(cmd->args, cmd->num_args+1) < 0) - goto no_memory; + goto error; if (VIR_STRDUP(cmd->args[cmd->num_args], arg) < 0) goto error; cmd->num_args++; @@ -10744,7 +10641,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, while (token != NULL) { if (VIR_REALLOC_N(first_rbd_disk->hosts, first_rbd_disk->nhosts + 1) < 0) { VIR_FREE(hosts); - goto no_memory; + goto error; } port = strchr(token, ':'); if (port) { @@ -10791,7 +10688,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, const char *display = qemuFindEnv(progenv, "DISPLAY"); const char *xauth = qemuFindEnv(progenv, "XAUTHORITY"); if (VIR_ALLOC(sdl) < 0) - goto no_memory; + goto error; sdl->type = VIR_DOMAIN_GRAPHICS_TYPE_SDL; sdl->data.sdl.fullscreen = fullscreen; if (VIR_STRDUP(sdl->data.sdl.display, display) < 0) { @@ -10805,7 +10702,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, if (VIR_REALLOC_N(def->graphics, def->ngraphics+1) < 0) { virDomainGraphicsDefFree(sdl); - goto no_memory; + goto error; } def->graphics[def->ngraphics++] = sdl; } @@ -10813,7 +10710,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, if (def->ngraphics) { virDomainVideoDefPtr vid; if (VIR_ALLOC(vid) < 0) - goto no_memory; + goto error; if (def->virtType == VIR_DOMAIN_VIRT_XEN) vid->type = VIR_DOMAIN_VIDEO_TYPE_XEN; else @@ -10825,7 +10722,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, if (VIR_REALLOC_N(def->videos, def->nvideos+1) < 0) { virDomainVideoDefFree(vid); - goto no_memory; + goto error; } def->videos[def->nvideos++] = vid; } @@ -10836,7 +10733,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, if (!def->memballoon) { virDomainMemballoonDefPtr memballoon; if (VIR_ALLOC(memballoon) < 0) - goto no_memory; + goto error; memballoon->model = VIR_DOMAIN_MEMBALLOON_MODEL_VIRTIO; def->memballoon = memballoon; @@ -10859,8 +10756,6 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, return def; -no_memory: - virReportOOMError(); error: virDomainDiskDefFree(disk); VIR_FREE(cmd); @@ -10920,20 +10815,16 @@ static int qemuParseProcFileStrings(int pid_value, char **str = NULL; int i; - if (virAsprintf(&path, "/proc/%d/%s", pid_value, name) < 0) { - virReportOOMError(); + if (virAsprintf(&path, "/proc/%d/%s", pid_value, name) < 0) goto cleanup; - } if ((len = virFileReadAll(path, 1024*128, &data)) < 0) goto cleanup; tmp = data; while (tmp < (data + len)) { - if (VIR_EXPAND_N(str, nstr, 1) < 0) { - virReportOOMError(); + if (VIR_EXPAND_N(str, nstr, 1) < 0) goto cleanup; - } if (VIR_STRDUP(str[nstr-1], tmp) < 0) goto cleanup; @@ -10943,10 +10834,8 @@ static int qemuParseProcFileStrings(int pid_value, tmp++; } - if (VIR_EXPAND_N(str, nstr, 1) < 0) { - virReportOOMError(); + if (VIR_EXPAND_N(str, nstr, 1) < 0) goto cleanup; - } str[nstr-1] = NULL; @@ -10989,10 +10878,8 @@ virDomainDefPtr qemuParseCommandLinePid(virCapsPtr qemuCaps, pidfile, monConfig, monJSON))) goto cleanup; - if (virAsprintf(&exepath, "/proc/%d/exe", (int) pid) < 0) { - virReportOOMError(); + if (virAsprintf(&exepath, "/proc/%d/exe", (int) pid) < 0) goto cleanup; - } if (virFileResolveLink(exepath, &emulator) < 0) { virReportSystemError(errno, diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 094f9f7..26aab5c 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -138,31 +138,31 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged) if (privileged) { if (virAsprintf(&cfg->logDir, "%s/log/libvirt/qemu", LOCALSTATEDIR) < 0) - goto no_memory; + goto error; if (VIR_STRDUP(cfg->configBaseDir, SYSCONFDIR "/libvirt") < 0) goto error; if (virAsprintf(&cfg->stateDir, "%s/run/libvirt/qemu", LOCALSTATEDIR) < 0) - goto no_memory; + goto error; if (virAsprintf(&cfg->libDir, "%s/lib/libvirt/qemu", LOCALSTATEDIR) < 0) - goto no_memory; + goto error; if (virAsprintf(&cfg->cacheDir, "%s/cache/libvirt/qemu", LOCALSTATEDIR) < 0) - goto no_memory; + goto error; if (virAsprintf(&cfg->saveDir, "%s/lib/libvirt/qemu/save", LOCALSTATEDIR) < 0) - goto no_memory; + goto error; if (virAsprintf(&cfg->snapshotDir, "%s/lib/libvirt/qemu/snapshot", LOCALSTATEDIR) < 0) - goto no_memory; + goto error; if (virAsprintf(&cfg->autoDumpPath, "%s/lib/libvirt/qemu/dump", LOCALSTATEDIR) < 0) - goto no_memory; + goto error; } else { char *rundir; char *cachedir; @@ -174,11 +174,11 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged) if (virAsprintf(&cfg->logDir, "%s/qemu/log", cachedir) < 0) { VIR_FREE(cachedir); - goto no_memory; + goto error; } if (virAsprintf(&cfg->cacheDir, "%s/qemu/cache", cachedir) < 0) { VIR_FREE(cachedir); - goto no_memory; + goto error; } VIR_FREE(cachedir); @@ -187,7 +187,7 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged) goto error; if (virAsprintf(&cfg->stateDir, "%s/qemu/run", rundir) < 0) { VIR_FREE(rundir); - goto no_memory; + goto error; } VIR_FREE(rundir); @@ -195,19 +195,19 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged) goto error; if (virAsprintf(&cfg->libDir, "%s/qemu/lib", cfg->configBaseDir) < 0) - goto no_memory; + goto error; if (virAsprintf(&cfg->saveDir, "%s/qemu/save", cfg->configBaseDir) < 0) - goto no_memory; + goto error; if (virAsprintf(&cfg->snapshotDir, "%s/qemu/snapshot", cfg->configBaseDir) < 0) - goto no_memory; + goto error; if (virAsprintf(&cfg->autoDumpPath, "%s/qemu/dump", cfg->configBaseDir) < 0) - goto no_memory; + goto error; } if (virAsprintf(&cfg->configDir, "%s/qemu", cfg->configBaseDir) < 0) - goto no_memory; + goto error; if (virAsprintf(&cfg->autostartDir, "%s/qemu/autostart", cfg->configBaseDir) < 0) - goto no_memory; + goto error; if (VIR_STRDUP(cfg->vncListen, "127.0.0.1") < 0) @@ -255,8 +255,6 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged) return cfg; -no_memory: - virReportOOMError(); error: virObjectUnref(cfg); return NULL; @@ -377,7 +375,7 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg, } if (VIR_ALLOC_N(cfg->securityDriverNames, len + 1) < 0) - goto no_memory; + goto cleanup; for (i = 0, pp = p->list; pp; i++, pp = pp->next) { if (VIR_STRDUP(cfg->securityDriverNames[i], pp->str) < 0) @@ -388,7 +386,7 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg, CHECK_TYPE("security_driver", VIR_CONF_STRING); if (p && p->str) { if (VIR_ALLOC_N(cfg->securityDriverNames, 2) < 0) - goto no_memory; + goto cleanup; if (VIR_STRDUP(cfg->securityDriverNames[0], p->str) < 0) goto cleanup; @@ -508,7 +506,7 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg, for (pp = p->list; pp; pp = pp->next) len++; if (VIR_ALLOC_N(cfg->cgroupDeviceACL, 1+len) < 0) - goto no_memory; + goto cleanup; for (i = 0, pp = p->list; pp; ++i, pp = pp->next) { if (pp->type != VIR_CONF_STRING) { @@ -555,10 +553,6 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg, cleanup: virConfFree(conf); return ret; - -no_memory: - virReportOOMError(); - goto cleanup; } #undef GET_VALUE_BOOL #undef GET_VALUE_LONG @@ -594,7 +588,7 @@ virCapsPtr virQEMUDriverCreateCapabilities(virQEMUDriverPtr driver) /* Basic host arch / guest machine capabilities */ if (!(caps = virQEMUCapsInit(driver->qemuCapsCache))) - goto no_memory; + goto error; if (virGetHostUUID(caps->host.host_uuid)) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -612,7 +606,7 @@ virCapsPtr virQEMUDriverCreateCapabilities(virQEMUDriverPtr driver) caps->host.nsecModels = i; if (VIR_ALLOC_N(caps->host.secModels, caps->host.nsecModels) < 0) - goto no_memory; + goto error; for (i = 0; sec_managers[i]; i++) { doi = virSecurityManagerGetDOI(sec_managers[i]); @@ -628,8 +622,6 @@ virCapsPtr virQEMUDriverCreateCapabilities(virQEMUDriverPtr driver) virObjectUnref(cfg); return caps; -no_memory: - virReportOOMError(); error: VIR_FREE(sec_managers); virObjectUnref(caps); @@ -740,10 +732,8 @@ virQEMUCloseCallbacksSet(virQEMUCloseCallbacksPtr closeCallbacks, closeDef->cb = cb; } else { - if (VIR_ALLOC(closeDef) < 0) { - virReportOOMError(); + if (VIR_ALLOC(closeDef) < 0) goto cleanup; - } closeDef->conn = conn; closeDef->cb = cb; @@ -878,10 +868,8 @@ virQEMUCloseCallbacksGetForConn(virQEMUCloseCallbacksPtr closeCallbacks, virQEMUCloseCallbacksListPtr list = NULL; struct virQEMUCloseCallbacksData data; - if (VIR_ALLOC(list) < 0) { - virReportOOMError(); + if (VIR_ALLOC(list) < 0) return NULL; - } data.conn = conn; data.list = list; @@ -965,10 +953,8 @@ qemuGetSharedDeviceKey(const char *device_path) return NULL; } - if (virAsprintf(&key, "%d:%d", maj, min) < 0) { - virReportOOMError(); + if (virAsprintf(&key, "%d:%d", maj, min) < 0) return NULL; - } return key; } @@ -1013,10 +999,8 @@ qemuCheckSharedDevice(virHashTablePtr sharedDevices, hostdev->source.subsys.u.scsi.unit))) goto cleanup; - if (virAsprintf(&hostdev_path, "/dev/%s", hostdev_name) < 0) { - virReportOOMError(); + if (virAsprintf(&hostdev_path, "/dev/%s", hostdev_name) < 0) goto cleanup; - } device_path = hostdev_path; } else { @@ -1127,15 +1111,11 @@ qemuSharedDeviceEntryCopy(const qemuSharedDeviceEntryPtr entry) qemuSharedDeviceEntryPtr ret = NULL; size_t i; - if (VIR_ALLOC(ret) < 0) { - virReportOOMError(); + if (VIR_ALLOC(ret) < 0) return NULL; - } - if (VIR_ALLOC_N(ret->domains, entry->ref) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(ret->domains, entry->ref) < 0) goto cleanup; - } for (i = 0; i < entry->ref; i++) { if (VIR_STRDUP(ret->domains[i], entry->domains[i]) < 0) @@ -1212,10 +1192,8 @@ qemuAddSharedDevice(virQEMUDriverPtr driver, hostdev->source.subsys.u.scsi.unit))) goto cleanup; - if (virAsprintf(&dev_path, "/dev/%s", dev_name) < 0) { - virReportOOMError(); + if (virAsprintf(&dev_path, "/dev/%s", dev_name) < 0) goto cleanup; - } if (!(key = qemuGetSharedDeviceKey(dev_path))) goto cleanup; @@ -1236,7 +1214,6 @@ qemuAddSharedDevice(virQEMUDriverPtr driver, if (VIR_EXPAND_N(new_entry->domains, new_entry->ref, 1) < 0 || VIR_STRDUP(new_entry->domains[new_entry->ref - 1], name) < 0) { qemuSharedDeviceEntryFree(new_entry, NULL); - virReportOOMError(); goto cleanup; } @@ -1249,7 +1226,6 @@ qemuAddSharedDevice(virQEMUDriverPtr driver, VIR_ALLOC_N(entry->domains, 1) < 0 || VIR_STRDUP(entry->domains[0], name) < 0) { qemuSharedDeviceEntryFree(entry, NULL); - virReportOOMError(); goto cleanup; } @@ -1325,10 +1301,8 @@ qemuRemoveSharedDevice(virQEMUDriverPtr driver, hostdev->source.subsys.u.scsi.unit))) goto cleanup; - if (virAsprintf(&dev_path, "/dev/%s", dev_name) < 0) { - virReportOOMError(); + if (virAsprintf(&dev_path, "/dev/%s", dev_name) < 0) goto cleanup; - } if (!(key = qemuGetSharedDeviceKey(dev_path))) goto cleanup; @@ -1415,10 +1389,8 @@ qemuSetUnprivSGIO(virDomainDeviceDefPtr dev) hostdev->source.subsys.u.scsi.unit))) goto cleanup; - if (virAsprintf(&hostdev_path, "/dev/%s", hostdev_name) < 0) { - virReportOOMError(); + if (virAsprintf(&hostdev_path, "/dev/%s", hostdev_name) < 0) goto cleanup; - } path = hostdev_path; } else { diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 8d79066..104a6d0 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -345,10 +345,8 @@ qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt, void *data) xmlNodePtr *nodes = NULL; virQEMUCapsPtr qemuCaps = NULL; - if (VIR_ALLOC(priv->monConfig) < 0) { - virReportOOMError(); + if (VIR_ALLOC(priv->monConfig) < 0) goto error; - } if (!(monitorpath = virXPathString("string(./monitor[1]/@path)", ctxt))) { @@ -387,10 +385,8 @@ qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt, void *data) goto error; if (n) { priv->nvcpupids = n; - if (VIR_REALLOC_N(priv->vcpupids, priv->nvcpupids) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(priv->vcpupids, priv->nvcpupids) < 0) goto error; - } for (i = 0; i < n; i++) { char *pidstr = virXMLPropString(nodes[i], "pid"); @@ -533,10 +529,8 @@ qemuDomainDefNamespaceParse(xmlDocPtr xml ATTRIBUTE_UNUSED, return -1; } - if (VIR_ALLOC(cmd) < 0) { - virReportOOMError(); + if (VIR_ALLOC(cmd) < 0) return -1; - } /* first handle the extra command-line arguments */ n = virXPathNodeSet("./qemu:commandline/qemu:arg", ctxt, &nodes); @@ -545,7 +539,7 @@ qemuDomainDefNamespaceParse(xmlDocPtr xml ATTRIBUTE_UNUSED, uses_qemu_ns |= n > 0; if (n && VIR_ALLOC_N(cmd->args, n) < 0) - goto no_memory; + goto error; for (i = 0; i < n; i++) { cmd->args[cmd->num_args] = virXMLPropString(nodes[i], "value"); @@ -566,10 +560,10 @@ qemuDomainDefNamespaceParse(xmlDocPtr xml ATTRIBUTE_UNUSED, uses_qemu_ns |= n > 0; if (n && VIR_ALLOC_N(cmd->env_name, n) < 0) - goto no_memory; + goto error; if (n && VIR_ALLOC_N(cmd->env_value, n) < 0) - goto no_memory; + goto error; for (i = 0; i < n; i++) { char *tmp; @@ -612,9 +606,6 @@ qemuDomainDefNamespaceParse(xmlDocPtr xml ATTRIBUTE_UNUSED, return 0; -no_memory: - virReportOOMError(); - error: VIR_FREE(nodes); qemuDomainDefNamespaceFree(cmd); @@ -797,10 +788,8 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, if (virAsprintf(&dev->data.chr->source.data.nix.path, "%s/channel/target/%s.%s", cfg->libDir, def->name, - dev->data.chr->target.name) < 0) { - virReportOOMError(); + dev->data.chr->target.name) < 0) goto cleanup; - } dev->data.chr->source.data.nix.listen = true; } @@ -1390,7 +1379,6 @@ qemuDomainDefFormatBuf(virQEMUDriverPtr driver, ncontrollers = def->ncontrollers; if (VIR_ALLOC_N(def->controllers, ncontrollers - toremove) < 0) { controllers = NULL; - virReportOOMError(); goto cleanup; } @@ -1578,10 +1566,8 @@ qemuDomainOpenLogHelper(virQEMUDriverConfigPtr cfg, int fd = -1; bool trunc = false; - if (virAsprintf(&logfile, "%s/%s.log", cfg->logDir, vm->def->name) < 0) { - virReportOOMError(); + if (virAsprintf(&logfile, "%s/%s.log", cfg->logDir, vm->def->name) < 0) return -1; - } /* To make SELinux happy we always need to open in append mode. * So we fake O_TRUNC by calling ftruncate after open instead @@ -1691,10 +1677,8 @@ int qemuDomainAppendLog(virQEMUDriverPtr driver, (fd = qemuDomainCreateLog(driver, obj, true)) < 0) goto cleanup; - if (virVasprintf(&message, fmt, argptr) < 0) { - virReportOOMError(); + if (virVasprintf(&message, fmt, argptr) < 0) goto cleanup; - } if (safewrite(fd, message, strlen(message)) < 0) { virReportSystemError(errno, _("Unable to write to domain logfile %s"), obj->def->name); @@ -1741,20 +1725,16 @@ qemuDomainSnapshotWriteMetadata(virDomainObjPtr vm, if (newxml == NULL) return -1; - if (virAsprintf(&snapDir, "%s/%s", snapshotDir, vm->def->name) < 0) { - virReportOOMError(); + if (virAsprintf(&snapDir, "%s/%s", snapshotDir, vm->def->name) < 0) goto cleanup; - } if (virFileMakePath(snapDir) < 0) { virReportSystemError(errno, _("cannot create snapshot directory '%s'"), snapDir); goto cleanup; } - if (virAsprintf(&snapFile, "%s/%s.xml", snapDir, snapshot->def->name) < 0) { - virReportOOMError(); + if (virAsprintf(&snapFile, "%s/%s.xml", snapDir, snapshot->def->name) < 0) goto cleanup; - } ret = virXMLSaveFile(snapFile, NULL, "snapshot-edit", newxml); @@ -1886,10 +1866,8 @@ qemuDomainSnapshotDiscard(virQEMUDriverPtr driver, } if (virAsprintf(&snapFile, "%s/%s/%s.xml", cfg->snapshotDir, - vm->def->name, snap->def->name) < 0) { - virReportOOMError(); + vm->def->name, snap->def->name) < 0) goto cleanup; - } if (snap == vm->current_snapshot) { if (update_current && snap->def->parent) { @@ -2098,10 +2076,8 @@ qemuDomainCleanupAdd(virDomainObjPtr vm, if (VIR_RESIZE_N(priv->cleanupCallbacks, priv->ncleanupCallbacks_max, - priv->ncleanupCallbacks, 1) < 0) { - virReportOOMError(); + priv->ncleanupCallbacks, 1) < 0) return -1; - } priv->cleanupCallbacks[priv->ncleanupCallbacks++] = cb; return 0; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 94cebe8..51a5a84 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -600,7 +600,7 @@ qemuStateInitialize(bool privileged, goto error; if (virAsprintf(&driverConf, "%s/qemu.conf", cfg->configBaseDir) < 0) - goto out_of_memory; + goto error; if (virQEMUDriverConfigLoadFile(cfg, driverConf) < 0) goto error; @@ -753,7 +753,7 @@ qemuStateInitialize(bool privileged, if (virAsprintf(&membase, "%s/libvirt", cfg->hugetlbfsMount) < 0 || virAsprintf(&mempath, "%s/qemu", membase) < 0) - goto out_of_memory; + goto error; if (virFileMakePath(mempath) < 0) { virReportSystemError(errno, @@ -835,8 +835,6 @@ qemuStateInitialize(bool privileged, virNWFilterRegisterCallbackDriver(&qemuCallbackDriver); return 0; -out_of_memory: - virReportOOMError(); error: if (conn) virConnectClose(conn); @@ -917,10 +915,8 @@ qemuStateStop(void) { VIR_CONNECT_LIST_DOMAINS_ACTIVE)) < 0) goto cleanup; - if (VIR_ALLOC_N(flags, numDomains) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(flags, numDomains) < 0) goto cleanup; - } /* First we pause all VMs to make them stop dirtying pages, etc. We remember if any VMs were paused so @@ -2825,10 +2821,8 @@ qemuDomainSaveMemory(virQEMUDriverPtr driver, pad = 1024; pad += (QEMU_MONITOR_MIGRATE_TO_FILE_BS - ((offset + pad) % QEMU_MONITOR_MIGRATE_TO_FILE_BS)); - if (VIR_ALLOC_N(xml, len + pad) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(xml, len + pad) < 0) goto cleanup; - } strcpy(xml, domXML); offset += pad; @@ -3112,7 +3106,6 @@ qemuDomainManagedSavePath(virQEMUDriverPtr driver, virDomainObjPtr vm) virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); if (virAsprintf(&ret, "%s/%s.save", cfg->saveDir, vm->def->name) < 0) { - virReportOOMError(); virObjectUnref(cfg); return NULL; } @@ -3522,10 +3515,8 @@ qemuDomainScreenshot(virDomainPtr dom, goto endjob; } - if (virAsprintf(&tmp, "%s/qemu.screendump.XXXXXX", cfg->cacheDir) < 0) { - virReportOOMError(); + if (virAsprintf(&tmp, "%s/qemu.screendump.XXXXXX", cfg->cacheDir) < 0) goto endjob; - } if ((tmp_fd = mkostemp(tmp, O_CLOEXEC)) == -1) { virReportSystemError(errno, _("mkostemp(\"%s\") failed"), tmp); @@ -3585,10 +3576,8 @@ static void processWatchdogEvent(virQEMUDriverPtr driver, virDomainObjPtr vm, in if (virAsprintf(&dumpfile, "%s/%s-%u", cfg->autoDumpPath, vm->def->name, - (unsigned int)time(NULL)) < 0) { - virReportOOMError(); + (unsigned int)time(NULL)) < 0) goto cleanup; - } if (qemuDomainObjBeginAsyncJob(driver, vm, QEMU_ASYNC_JOB_DUMP) < 0) { @@ -3653,10 +3642,8 @@ doCoreDumpToAutoDumpPath(virQEMUDriverPtr driver, if (virAsprintf(&dumpfile, "%s/%s-%s", cfg->autoDumpPath, vm->def->name, - timestr) < 0) { - virReportOOMError(); + timestr) < 0) goto cleanup; - } if (qemuDomainObjBeginAsyncJob(driver, vm, QEMU_ASYNC_JOB_DUMP) < 0) { @@ -3916,15 +3903,11 @@ static int qemuDomainHotplugVcpus(virQEMUDriverPtr driver, virDomainVcpuPinDefPtr vcpupin = NULL; if (VIR_REALLOC_N(vm->def->cputune.vcpupin, - vm->def->cputune.nvcpupin + 1) < 0) { - virReportOOMError(); + vm->def->cputune.nvcpupin + 1) < 0) goto cleanup; - } - if (VIR_ALLOC(vcpupin) < 0) { - virReportOOMError(); + if (VIR_ALLOC(vcpupin) < 0) goto cleanup; - } vcpupin->cpumask = virBitmapNew(VIR_DOMAIN_CPUMASK_LEN); virBitmapCopy(vcpupin->cpumask, vm->def->cpumask); @@ -4283,10 +4266,8 @@ qemuDomainPinVcpuFlags(virDomainPtr dom, newVcpuPinNum = vm->def->cputune.nvcpupin; } else { - if (VIR_ALLOC(newVcpuPin) < 0) { - virReportOOMError(); + if (VIR_ALLOC(newVcpuPin) < 0) goto cleanup; - } newVcpuPinNum = 0; } @@ -4349,10 +4330,8 @@ qemuDomainPinVcpuFlags(virDomainPtr dom, } } else { if (!persistentDef->cputune.vcpupin) { - if (VIR_ALLOC(persistentDef->cputune.vcpupin) < 0) { - virReportOOMError(); + if (VIR_ALLOC(persistentDef->cputune.vcpupin) < 0) goto cleanup; - } persistentDef->cputune.nvcpupin = 0; } if (virDomainVcpuPinAdd(&persistentDef->cputune.vcpupin, @@ -4549,10 +4528,8 @@ qemuDomainPinEmulator(virDomainPtr dom, if (flags & VIR_DOMAIN_AFFECT_LIVE) { if (priv->vcpupids != NULL) { - if (VIR_ALLOC(newVcpuPin) < 0) { - virReportOOMError(); + if (VIR_ALLOC(newVcpuPin) < 0) goto cleanup; - } if (virDomainVcpuPinAdd(&newVcpuPin, &newVcpuPinNum, cpumap, maplen, -1) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -5002,7 +4979,6 @@ static int qemuDomainGetSecurityLabelList(virDomainPtr dom, len++; if (VIR_ALLOC_N((*seclabels), len) < 0) { - virReportOOMError(); VIR_FREE(mgrs); goto cleanup; } @@ -5170,10 +5146,8 @@ qemuDomainSaveImageOpen(virQEMUDriverPtr driver, goto error; } - if (VIR_ALLOC_N(xml, header.xml_len) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(xml, header.xml_len) < 0) goto error; - } if (saferead(fd, xml, header.xml_len) != header.xml_len) { virReportError(VIR_ERR_OPERATION_FAILED, @@ -5500,10 +5474,8 @@ qemuDomainSaveImageDefineXML(virConnectPtr conn, const char *path, _("new xml too large to fit in file")); goto cleanup; } - if (VIR_EXPAND_N(xml, len, header.xml_len - len) < 0) { - virReportOOMError(); + if (VIR_EXPAND_N(xml, len, header.xml_len - len) < 0) goto cleanup; - } if (lseek(fd, 0, SEEK_SET) != 0) { virReportSystemError(errno, _("cannot seek in '%s'"), path); @@ -6642,10 +6614,8 @@ qemuDomainAttachDeviceConfig(virQEMUCapsPtr qemuCaps, _("target %s already exists"), disk->dst); return -1; } - if (virDomainDiskInsert(vmdef, disk)) { - virReportOOMError(); + if (virDomainDiskInsert(vmdef, disk)) return -1; - } /* vmdef has the pointer. Generic codes for vmdef will do all jobs */ dev->data.disk = NULL; if (disk->bus != VIR_DOMAIN_DISK_BUS_VIRTIO) @@ -6657,10 +6627,8 @@ qemuDomainAttachDeviceConfig(virQEMUCapsPtr qemuCaps, case VIR_DOMAIN_DEVICE_NET: net = dev->data.net; - if (virDomainNetInsert(vmdef, net)) { - virReportOOMError(); + if (virDomainNetInsert(vmdef, net)) return -1; - } dev->data.net = NULL; if (qemuDomainAssignAddresses(vmdef, qemuCaps, NULL) < 0) return -1; @@ -6673,10 +6641,8 @@ qemuDomainAttachDeviceConfig(virQEMUCapsPtr qemuCaps, _("device is already in the domain configuration")); return -1; } - if (virDomainHostdevInsert(vmdef, hostdev)) { - virReportOOMError(); + if (virDomainHostdevInsert(vmdef, hostdev)) return -1; - } dev->data.hostdev = NULL; if (qemuDomainAssignAddresses(vmdef, qemuCaps, NULL) < 0) return -1; @@ -7511,10 +7477,8 @@ qemuDomainParseDeviceWeightStr(char *deviceWeightStr, ndevices = (nsep + 1) / 2; - if (VIR_ALLOC_N(result, ndevices) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(result, ndevices) < 0) return -1; - } i = 0; temp = deviceWeightStr; @@ -7587,10 +7551,8 @@ qemuDomainMergeDeviceWeights(virBlkioDeviceWeightPtr *dest_array, if (!found) { if (!src->weight) continue; - if (VIR_EXPAND_N(*dest_array, *dest_size, 1) < 0) { - virReportOOMError(); + if (VIR_EXPAND_N(*dest_array, *dest_size, 1) < 0) return -1; - } dest = &(*dest_array)[*dest_size - 1]; dest->path = src->path; dest->weight = src->weight; @@ -9051,10 +9013,8 @@ qemuDomainBlockResize(virDomainPtr dom, disk = vm->def->disks[i]; if (virAsprintf(&device, "%s%s", QEMU_DRIVE_HOST_PREFIX, - disk->info.alias) < 0) { - virReportOOMError(); + disk->info.alias) < 0) goto endjob; - } qemuDomainObjEnterMonitor(driver, vm); if (qemuMonitorBlockResize(priv->mon, device, size) < 0) { @@ -9440,10 +9400,8 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom, if ((VIR_ALLOC(bandwidth) < 0) || (VIR_ALLOC(bandwidth->in) < 0) || - (VIR_ALLOC(bandwidth->out) < 0)) { - virReportOOMError(); + (VIR_ALLOC(bandwidth->out) < 0)) goto cleanup; - } for (i = 0; i < nparams; i++) { virTypedParameterPtr param = ¶ms[i]; @@ -9474,20 +9432,16 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom, } if (flags & VIR_DOMAIN_AFFECT_LIVE) { - if (VIR_ALLOC(newBandwidth) < 0) { - virReportOOMError(); + if (VIR_ALLOC(newBandwidth) < 0) goto cleanup; - } /* virNetDevBandwidthSet() will clear any previous value of * bandwidth parameters, so merge with old bandwidth parameters * here to prevent them from being lost. */ if (bandwidth->in || (net->bandwidth && net->bandwidth->in)) { - if (VIR_ALLOC(newBandwidth->in) < 0) { - virReportOOMError(); + if (VIR_ALLOC(newBandwidth->in) < 0) goto cleanup; - } memcpy(newBandwidth->in, bandwidth->in ? bandwidth->in : net->bandwidth->in, @@ -9495,10 +9449,8 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom, } if (bandwidth->out || (net->bandwidth && net->bandwidth->out)) { - if (VIR_ALLOC(newBandwidth->out) < 0) { - virReportOOMError(); + if (VIR_ALLOC(newBandwidth->out) < 0) goto cleanup; - } memcpy(newBandwidth->out, bandwidth->out ? bandwidth->out : net->bandwidth->out, @@ -9819,10 +9771,8 @@ qemuDomainMemoryPeek(virDomainPtr dom, goto endjob; } - if (virAsprintf(&tmp, "%s/qemu.mem.XXXXXX", cfg->cacheDir) < 0) { - virReportOOMError(); + if (virAsprintf(&tmp, "%s/qemu.mem.XXXXXX", cfg->cacheDir) < 0) goto endjob; - } /* Create a temporary filename. */ if ((fd = mkostemp(tmp, O_CLOEXEC)) == -1) { @@ -11695,10 +11645,8 @@ qemuDomainSnapshotCreateInactiveExternal(virQEMUDriverPtr driver, if (!(qemuImgPath = qemuFindQemuImgBinary(driver))) goto cleanup; - if (!(created = virBitmapNew(snap->def->ndisks))) { - virReportOOMError(); + if (!(created = virBitmapNew(snap->def->ndisks))) goto cleanup; - } /* If reuse is true, then qemuDomainSnapshotPrepare already * ensured that the new files exist, and it was up to the user to @@ -12051,10 +11999,8 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver, if (virAsprintf(&device, "drive-%s", disk->info.alias) < 0 || VIR_STRDUP(source, snap->file) < 0 || - (persistDisk && VIR_STRDUP(persistSource, source) < 0)) { - virReportOOMError(); + (persistDisk && VIR_STRDUP(persistSource, source) < 0)) goto cleanup; - } /* create the stub file and set selinux labels; manipulate disk in * place, in a way that can be reverted on failure. */ @@ -12178,10 +12124,8 @@ qemuDomainSnapshotCreateDiskActive(virQEMUDriverPtr driver, } if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_TRANSACTION)) { - if (!(actions = virJSONValueNewArray())) { - virReportOOMError(); + if (!(actions = virJSONValueNewArray())) goto cleanup; - } } else if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DISK_SNAPSHOT)) { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", _("live disk snapshot not supported with this " @@ -13771,10 +13715,8 @@ static virDomainPtr qemuDomainQemuAttach(virConnectPtr conn, } if (!(def->name) && - virAsprintf(&def->name, "attach-pid-%u", pid_value) < 0) { - virReportOOMError(); + virAsprintf(&def->name, "attach-pid-%u", pid_value) < 0) goto cleanup; - } if (!(qemuCaps = virQEMUCapsCacheLookup(driver->qemuCapsCache, def->emulator))) goto cleanup; @@ -13999,10 +13941,8 @@ qemuDiskPathToAlias(virDomainObjPtr vm, const char *path, int *idx) *idx = i; if (disk->src) { - if (virAsprintf(&ret, "drive-%s", disk->info.alias) < 0) { - virReportOOMError(); + if (virAsprintf(&ret, "drive-%s", disk->info.alias) < 0) return NULL; - } } cleanup: @@ -15550,10 +15490,8 @@ qemuDomainGetPercpuStats(virDomainObjPtr vm, goto cleanup; } - if (VIR_ALLOC_N(sum_cpu_time, n) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(sum_cpu_time, n) < 0) goto cleanup; - } if (getSumVcpuPercpuStats(vm, sum_cpu_time, n) < 0) goto cleanup; diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 46875ad..31ed9af 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -277,10 +277,8 @@ int qemuDomainAttachVirtioDiskDevice(virConnectPtr conn, goto error; } - if (VIR_REALLOC_N(vm->def->disks, vm->def->ndisks+1) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(vm->def->disks, vm->def->ndisks+1) < 0) goto error; - } qemuDomainObjEnterMonitor(driver, vm); if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE)) { @@ -387,10 +385,8 @@ int qemuDomainAttachPciControllerDevice(virQEMUDriverPtr driver, } } - if (VIR_REALLOC_N(vm->def->controllers, vm->def->ncontrollers+1) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(vm->def->controllers, vm->def->ncontrollers+1) < 0) goto cleanup; - } qemuDomainObjEnterMonitor(driver, vm); if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE)) { @@ -440,10 +436,8 @@ qemuDomainFindOrCreateSCSIDiskController(virQEMUDriverPtr driver, /* No SCSI controller present, for backward compatibility we * now hotplug a controller */ - if (VIR_ALLOC(cont) < 0) { - virReportOOMError(); + if (VIR_ALLOC(cont) < 0) return NULL; - } cont->type = VIR_DOMAIN_CONTROLLER_TYPE_SCSI; cont->idx = controller; cont->model = -1; @@ -534,10 +528,8 @@ int qemuDomainAttachSCSIDisk(virConnectPtr conn, goto error; } - if (VIR_REALLOC_N(vm->def->disks, vm->def->ndisks+1) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(vm->def->disks, vm->def->ndisks+1) < 0) goto error; - } qemuDomainObjEnterMonitor(driver, vm); if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE)) { @@ -638,10 +630,8 @@ int qemuDomainAttachUsbMassstorageDevice(virConnectPtr conn, goto error; } - if (VIR_REALLOC_N(vm->def->disks, vm->def->ndisks+1) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(vm->def->disks, vm->def->ndisks+1) < 0) goto error; - } qemuDomainObjEnterMonitor(driver, vm); if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE)) { @@ -711,10 +701,8 @@ int qemuDomainAttachNetDevice(virConnectPtr conn, int i; /* preallocate new slot for device */ - if (VIR_REALLOC_N(vm->def->nets, vm->def->nnets+1) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(vm->def->nets, vm->def->nnets+1) < 0) goto cleanup; - } /* If appropriate, grab a physical device from the configured * network's pool of devices, or resolve bridge device name @@ -758,10 +746,8 @@ int qemuDomainAttachNetDevice(virConnectPtr conn, if (!tapfdSize) tapfdSize = vhostfdSize = 1; if (VIR_ALLOC_N(tapfd, tapfdSize) < 0 || - VIR_ALLOC_N(vhostfd, vhostfdSize) < 0) { - virReportOOMError(); + VIR_ALLOC_N(vhostfd, vhostfdSize) < 0) goto cleanup; - } if (qemuNetworkIfaceConnect(vm->def, conn, driver, net, priv->qemuCaps, tapfd, &tapfdSize) < 0) goto cleanup; @@ -770,10 +756,8 @@ int qemuDomainAttachNetDevice(virConnectPtr conn, goto cleanup; } else if (actualType == VIR_DOMAIN_NET_TYPE_DIRECT) { tapfdSize = vhostfdSize = 1; - if (VIR_ALLOC(tapfd) < 0 || VIR_ALLOC(vhostfd) < 0) { - virReportOOMError(); + if (VIR_ALLOC(tapfd) < 0 || VIR_ALLOC(vhostfd) < 0) goto cleanup; - } if ((tapfd[0] = qemuPhysIfaceConnect(vm->def, driver, net, priv->qemuCaps, VIR_NETDEV_VPORT_PROFILE_OP_CREATE)) < 0) @@ -783,10 +767,8 @@ int qemuDomainAttachNetDevice(virConnectPtr conn, goto cleanup; } else if (actualType == VIR_DOMAIN_NET_TYPE_ETHERNET) { vhostfdSize = 1; - if (VIR_ALLOC(vhostfd) < 0) { - virReportOOMError(); + if (VIR_ALLOC(vhostfd) < 0) goto cleanup; - } if (qemuOpenVhostNet(vm->def, net, priv->qemuCaps, vhostfd, &vhostfdSize) < 0) goto cleanup; } @@ -826,19 +808,17 @@ int qemuDomainAttachNetDevice(virConnectPtr conn, } if (VIR_ALLOC_N(tapfdName, tapfdSize) < 0 || - VIR_ALLOC_N(vhostfdName, vhostfdSize) < 0) { - virReportOOMError(); + VIR_ALLOC_N(vhostfdName, vhostfdSize) < 0) goto cleanup; - } for (i = 0; i < tapfdSize; i++) { if (virAsprintf(&tapfdName[i], "fd-%s%d", net->info.alias, i) < 0) - goto no_memory; + goto cleanup; } for (i = 0; i < vhostfdSize; i++) { if (virAsprintf(&vhostfdName[i], "vhostfd-%s%d", net->info.alias, i) < 0) - goto no_memory; + goto cleanup; } if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_NETDEV) && @@ -1003,7 +983,7 @@ try_remove: virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE)) { char *netdev_name; if (virAsprintf(&netdev_name, "host%s", net->info.alias) < 0) - goto no_memory; + goto cleanup; qemuDomainObjEnterMonitor(driver, vm); if (qemuMonitorRemoveNetdev(priv->mon, netdev_name) < 0) VIR_WARN("Failed to remove network backend for netdev %s", @@ -1016,7 +996,7 @@ try_remove: } else { char *hostnet_name; if (virAsprintf(&hostnet_name, "host%s", net->info.alias) < 0) - goto no_memory; + goto cleanup; qemuDomainObjEnterMonitor(driver, vm); if (qemuMonitorRemoveHostNetwork(priv->mon, vlan, hostnet_name) < 0) VIR_WARN("Failed to remove network backend for vlan %d, net %s", @@ -1025,10 +1005,6 @@ try_remove: VIR_FREE(hostnet_name); } goto cleanup; - -no_memory: - virReportOOMError(); - goto cleanup; } @@ -1043,10 +1019,8 @@ int qemuDomainAttachHostPciDevice(virQEMUDriverPtr driver, char *configfd_name = NULL; bool releaseaddr = false; - if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs+1) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs+1) < 0) return -1; - } if (qemuPrepareHostdevPCIDevices(driver, vm->def->name, vm->def->uuid, &hostdev, 1) < 0) @@ -1085,10 +1059,8 @@ int qemuDomainAttachHostPciDevice(virQEMUDriverPtr driver, configfd = qemuOpenPCIConfig(hostdev); if (configfd >= 0) { if (virAsprintf(&configfd_name, "fd-%s", - hostdev->info->alias) < 0) { - virReportOOMError(); + hostdev->info->alias) < 0) goto error; - } } } @@ -1164,10 +1136,8 @@ int qemuDomainAttachRedirdevDevice(virQEMUDriverPtr driver, goto error; } - if (VIR_REALLOC_N(vm->def->redirdevs, vm->def->nredirdevs+1) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(vm->def->redirdevs, vm->def->nredirdevs+1) < 0) goto error; - } qemuDomainObjEnterMonitor(driver, vm); if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE)) @@ -1225,10 +1195,8 @@ int qemuDomainAttachHostUsbDevice(virQEMUDriverPtr driver, goto cleanup; } - if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs+1) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs+1) < 0) goto cleanup; - } qemuDomainObjEnterMonitor(driver, vm); if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE)) @@ -1293,10 +1261,8 @@ qemuDomainAttachHostScsiDevice(virQEMUDriverPtr driver, if (!(devstr = qemuBuildSCSIHostdevDevStr(vm->def, hostdev, priv->qemuCaps))) goto cleanup; - if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs + 1) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs + 1) < 0) goto cleanup; - } qemuDomainObjEnterMonitor(driver, vm); if ((ret = qemuMonitorAddDrive(priv->mon, drvstr)) == 0) { @@ -2210,10 +2176,8 @@ int qemuDomainDetachVirtioDiskDevice(virQEMUDriverPtr driver, /* build the actual drive id string as the disk->info.alias doesn't * contain the QEMU_DRIVE_HOST_PREFIX that is passed to qemu */ if (virAsprintf(&drivestr, "%s%s", - QEMU_DRIVE_HOST_PREFIX, detach->info.alias) < 0) { - virReportOOMError(); + QEMU_DRIVE_HOST_PREFIX, detach->info.alias) < 0) goto cleanup; - } qemuDomainObjEnterMonitor(driver, vm); if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE)) { @@ -2309,10 +2273,8 @@ int qemuDomainDetachDiskDevice(virQEMUDriverPtr driver, /* build the actual drive id string as the disk->info.alias doesn't * contain the QEMU_DRIVE_HOST_PREFIX that is passed to qemu */ if (virAsprintf(&drivestr, "%s%s", - QEMU_DRIVE_HOST_PREFIX, detach->info.alias) < 0) { - virReportOOMError(); + QEMU_DRIVE_HOST_PREFIX, detach->info.alias) < 0) goto cleanup; - } qemuDomainObjEnterMonitor(driver, vm); if (qemuMonitorDelDevice(priv->mon, detach->info.alias) < 0) { @@ -2831,10 +2793,8 @@ qemuDomainDetachNetDevice(virQEMUDriverPtr driver, goto cleanup; } - if (virAsprintf(&hostnet_name, "host%s", detach->info.alias) < 0) { - virReportOOMError(); + if (virAsprintf(&hostnet_name, "host%s", detach->info.alias) < 0) goto cleanup; - } qemuDomainObjEnterMonitor(driver, vm); if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE)) { diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 49e9e65..bf8c92f 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -231,7 +231,7 @@ qemuDomainExtractTLSSubject(const char *certdir) size_t subjectlen; if (virAsprintf(&certfile, "%s/server-cert.pem", certdir) < 0) - goto no_memory; + goto error; if (virFileReadAll(certfile, 8192, &pemdata) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -260,7 +260,7 @@ qemuDomainExtractTLSSubject(const char *certdir) subjectlen = 1024; if (VIR_ALLOC_N(subject, subjectlen+1) < 0) - goto no_memory; + goto error; gnutls_x509_crt_get_dn(cert, subject, &subjectlen); subject[subjectlen] = '\0'; @@ -270,8 +270,6 @@ qemuDomainExtractTLSSubject(const char *certdir) return subject; -no_memory: - virReportOOMError(); error: VIR_FREE(certfile); VIR_FREE(pemdata); @@ -288,7 +286,7 @@ qemuMigrationCookieGraphicsAlloc(virQEMUDriverPtr driver, virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); if (VIR_ALLOC(mig) < 0) - goto no_memory; + goto error; mig->type = def->type; if (mig->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC) { @@ -324,8 +322,6 @@ qemuMigrationCookieGraphicsAlloc(virQEMUDriverPtr driver, virObjectUnref(cfg); return mig; -no_memory: - virReportOOMError(); error: qemuMigrationCookieGraphicsFree(mig); virObjectUnref(cfg); @@ -341,12 +337,12 @@ qemuMigrationCookieNetworkAlloc(virQEMUDriverPtr driver ATTRIBUTE_UNUSED, int i; if (VIR_ALLOC(mig) < 0) - goto no_memory; + goto error; mig->nnets = def->nnets; if (VIR_ALLOC_N(mig->net, def->nnets) <0) - goto no_memory; + goto error; for (i = 0; i < def->nnets; i++) { virDomainNetDefPtr netptr; @@ -379,8 +375,6 @@ qemuMigrationCookieNetworkAlloc(virQEMUDriverPtr driver ATTRIBUTE_UNUSED, } return mig; -no_memory: - virReportOOMError(); error: qemuMigrationCookieNetworkFree(mig); return NULL; @@ -394,7 +388,7 @@ qemuMigrationCookieNew(virDomainObjPtr dom) const char *name; if (VIR_ALLOC(mig) < 0) - goto no_memory; + goto error; if (priv->origname) name = priv->origname; @@ -414,8 +408,6 @@ qemuMigrationCookieNew(virDomainObjPtr dom) return mig; -no_memory: - virReportOOMError(); error: qemuMigrationCookieFree(mig); return NULL; @@ -533,10 +525,8 @@ qemuMigrationCookieAddNBD(qemuMigrationCookiePtr mig, /* It is not a bug if there already is a NBD data */ if (!mig->nbd && - VIR_ALLOC(mig->nbd) < 0) { - virReportOOMError(); + VIR_ALLOC(mig->nbd) < 0) return -1; - } mig->nbd->port = priv->nbdPort; mig->flags |= QEMU_MIGRATION_COOKIE_NBD; @@ -686,7 +676,7 @@ qemuMigrationCookieGraphicsXMLParse(xmlXPathContextPtr ctxt) char *tmp; if (VIR_ALLOC(grap) < 0) - goto no_memory; + goto error; if (!(tmp = virXPathString("string(./graphics/@type)", ctxt))) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -722,8 +712,6 @@ qemuMigrationCookieGraphicsXMLParse(xmlXPathContextPtr ctxt) return grap; -no_memory: - virReportOOMError(); error: qemuMigrationCookieGraphicsFree(grap); return NULL; @@ -741,7 +729,7 @@ qemuMigrationCookieNetworkXMLParse(xmlXPathContextPtr ctxt) xmlNodePtr save_ctxt = ctxt->node; if (VIR_ALLOC(optr) < 0) - goto no_memory; + goto error; if ((n = virXPathNodeSet("./network/interface", ctxt, &interfaces)) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -751,7 +739,7 @@ qemuMigrationCookieNetworkXMLParse(xmlXPathContextPtr ctxt) optr->nnets = n; if (VIR_ALLOC_N(optr->net, optr->nnets) < 0) - goto no_memory; + goto error; for (i = 0; i < n; i++) { /* portdata is optional, and may not exist */ @@ -772,8 +760,6 @@ cleanup: ctxt->node = save_ctxt; return optr; -no_memory: - virReportOOMError(); error: VIR_FREE(interfaces); qemuMigrationCookieNetworkFree(optr); @@ -942,10 +928,8 @@ qemuMigrationCookieXMLParse(qemuMigrationCookiePtr mig, virXPathBoolean("boolean(./nbd)", ctxt)) { char *port; - if (VIR_ALLOC(mig->nbd) < 0) { - virReportOOMError(); + if (VIR_ALLOC(mig->nbd) < 0) goto error; - } port = virXPathString("string(./nbd/@port)", ctxt); if (port && virStrToLong_i(port, NULL, 10, &mig->nbd->port) < 0) { @@ -1131,10 +1115,8 @@ qemuMigrationStartNBDServer(virQEMUDriverPtr driver, VIR_FREE(diskAlias); if (virAsprintf(&diskAlias, "%s%s", - QEMU_DRIVE_HOST_PREFIX, disk->info.alias) < 0) { - virReportOOMError(); + QEMU_DRIVE_HOST_PREFIX, disk->info.alias) < 0) goto cleanup; - } if (qemuDomainObjEnterMonitorAsync(driver, vm, QEMU_ASYNC_JOB_MIGRATION_IN) < 0) @@ -1220,10 +1202,8 @@ qemuMigrationDriveMirror(virQEMUDriverPtr driver, /* escape literal IPv6 address */ if (strchr(host, ':')) { - if (virAsprintf(&hoststr, "[%s]", host) < 0) { - virReportOOMError(); + if (virAsprintf(&hoststr, "[%s]", host) < 0) goto error; - } } else if (VIR_STRDUP(hoststr, host) < 0) { goto error; } @@ -1244,10 +1224,8 @@ qemuMigrationDriveMirror(virQEMUDriverPtr driver, if ((virAsprintf(&diskAlias, "%s%s", QEMU_DRIVE_HOST_PREFIX, disk->info.alias) < 0) || (virAsprintf(&nbd_dest, "nbd:%s:%d:exportname=%s", - hoststr, port, diskAlias) < 0)) { - virReportOOMError(); + hoststr, port, diskAlias) < 0)) goto error; - } if (qemuDomainObjEnterMonitorAsync(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT) < 0) @@ -1329,10 +1307,8 @@ error: VIR_FREE(diskAlias); if (virAsprintf(&diskAlias, "%s%s", - QEMU_DRIVE_HOST_PREFIX, disk->info.alias) < 0) { - virReportOOMError(); + QEMU_DRIVE_HOST_PREFIX, disk->info.alias) < 0) continue; - } if (qemuDomainObjEnterMonitorAsync(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT) == 0) { if (qemuMonitorBlockJob(priv->mon, diskAlias, NULL, 0, @@ -1394,10 +1370,8 @@ qemuMigrationCancelDriveMirror(qemuMigrationCookiePtr mig, VIR_FREE(diskAlias); if (virAsprintf(&diskAlias, "%s%s", - QEMU_DRIVE_HOST_PREFIX, disk->info.alias) < 0) { - virReportOOMError(); + QEMU_DRIVE_HOST_PREFIX, disk->info.alias) < 0) goto cleanup; - } if (qemuDomainObjEnterMonitorAsync(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT) < 0) @@ -2309,10 +2283,8 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver, /* QEMU will be started with -incoming [::]:port * or -incoming 0.0.0.0:port */ - if (virAsprintf(&migrateFrom, "tcp:%s:%d", listenAddr, port) < 0) { - virReportOOMError(); + if (virAsprintf(&migrateFrom, "tcp:%s:%d", listenAddr, port) < 0) goto cleanup; - } } if (!(vm = virDomainObjListAdd(driver->domains, *def, @@ -2567,10 +2539,8 @@ qemuMigrationPrepareDirect(virQEMUDriverPtr driver, * new targets accept both syntaxes though. */ /* Caller frees */ - if (virAsprintf(uri_out, "tcp:%s:%d", hostname, this_port) < 0) { - virReportOOMError(); + if (virAsprintf(uri_out, "tcp:%s:%d", hostname, this_port) < 0) goto cleanup; - } } else { /* Check the URI starts with "tcp:". We will escape the * URI when passing it to the qemu monitor, so bad @@ -2585,10 +2555,8 @@ qemuMigrationPrepareDirect(virQEMUDriverPtr driver, /* Convert uri_in to well-formed URI with // after tcp: */ if (!(STRPREFIX(uri_in, "tcp://"))) { - if (virAsprintf(&uri_str, "tcp://%s", p) < 0) { - virReportOOMError(); + if (virAsprintf(&uri_str, "tcp://%s", p) < 0) goto cleanup; - } } uri = virURIParse(uri_str ? uri_str : uri_in); @@ -2615,10 +2583,8 @@ qemuMigrationPrepareDirect(virQEMUDriverPtr driver, port = 0; /* Caller frees */ - if (virAsprintf(uri_out, "%s:%d", uri_in, this_port) < 0) { - virReportOOMError(); + if (virAsprintf(uri_out, "%s:%d", uri_in, this_port) < 0) goto cleanup; - } } else { this_port = uri->port; @@ -2873,10 +2839,8 @@ static void qemuMigrationIOFunc(void *arg) VIR_DEBUG("Running migration tunnel; stream=%p, sock=%d", data->st, data->sock); - if (VIR_ALLOC_N(buffer, TUNNEL_SEND_BUF_SIZE) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(buffer, TUNNEL_SEND_BUF_SIZE) < 0) goto abrt; - } fds[0].fd = data->sock; fds[1].fd = data->wakeupRecvFD; @@ -2982,7 +2946,7 @@ qemuMigrationStartTunnel(virStreamPtr st, } if (VIR_ALLOC(io) < 0) - goto no_memory; + goto error; io->st = st; io->sock = sock; @@ -2999,8 +2963,6 @@ qemuMigrationStartTunnel(virStreamPtr st, return io; -no_memory: - virReportOOMError(); error: VIR_FORCE_CLOSE(wakeupFD[0]); VIR_FORCE_CLOSE(wakeupFD[1]); @@ -3053,10 +3015,8 @@ qemuMigrationConnect(virQEMUDriverPtr driver, int ret = -1; host = spec->dest.host.name; - if (virAsprintf(&port, "%d", spec->dest.host.port) < 0) { - virReportOOMError(); + if (virAsprintf(&port, "%d", spec->dest.host.port) < 0) return -1; - } spec->destType = MIGRATION_DEST_FD; spec->dest.fd.qemu = -1; @@ -3355,10 +3315,8 @@ static int doNativeMigrate(virQEMUDriverPtr driver, if (STRPREFIX(uri, "tcp:") && !STRPREFIX(uri, "tcp://")) { char *tmp; /* HACK: source host generates bogus URIs, so fix them up */ - if (virAsprintf(&tmp, "tcp://%s", uri + strlen("tcp:")) < 0) { - virReportOOMError(); + if (virAsprintf(&tmp, "tcp://%s", uri + strlen("tcp:")) < 0) return -1; - } uribits = virURIParse(tmp); VIR_FREE(tmp); } else { @@ -3450,10 +3408,8 @@ static int doTunnelMigrate(virQEMUDriverPtr driver, if (virAsprintf(&spec.dest.unix_socket.file, "%s/qemu.tunnelmigrate.src.%s", - cfg->libDir, vm->def->name) < 0) { - virReportOOMError(); + cfg->libDir, vm->def->name) < 0) goto cleanup; - } if (virNetSocketNewListenUNIX(spec.dest.unix_socket.file, 0700, cfg->user, cfg->group, diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index fe5ab0a..067b368 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -489,10 +489,8 @@ qemuMonitorIORead(qemuMonitorPtr mon) if (avail < 1024) { if (VIR_REALLOC_N(mon->buffer, - mon->bufferLength + 1024) < 0) { - virReportOOMError(); + mon->bufferLength + 1024) < 0) return -1; - } mon->bufferLength += 1024; avail += 1024; } @@ -864,10 +862,7 @@ char *qemuMonitorNextCommandID(qemuMonitorPtr mon) { char *id; - if (virAsprintf(&id, "libvirt-%d", ++mon->nextSerial) < 0) { - virReportOOMError(); - return NULL; - } + ignore_value(virAsprintf(&id, "libvirt-%d", ++mon->nextSerial)); return id; } @@ -1962,10 +1957,8 @@ int qemuMonitorMigrateToHost(qemuMonitorPtr mon, } - if (virAsprintf(&uri, "tcp:%s:%d", hostname, port) < 0) { - virReportOOMError(); + if (virAsprintf(&uri, "tcp:%s:%d", hostname, port) < 0) return -1; - } if (mon->json) ret = qemuMonitorJSONMigrate(mon, flags, uri); @@ -1994,15 +1987,11 @@ int qemuMonitorMigrateToCommand(qemuMonitorPtr mon, } argstr = virArgvToString(argv); - if (!argstr) { - virReportOOMError(); + if (!argstr) goto cleanup; - } - if (virAsprintf(&dest, "exec:%s", argstr) < 0) { - virReportOOMError(); + if (virAsprintf(&dest, "exec:%s", argstr) < 0) goto cleanup; - } if (mon->json) ret = qemuMonitorJSONMigrate(mon, flags, dest); @@ -2043,10 +2032,8 @@ int qemuMonitorMigrateToFile(qemuMonitorPtr mon, } argstr = virArgvToString(argv); - if (!argstr) { - virReportOOMError(); + if (!argstr) goto cleanup; - } /* Migrate to file */ virBufferEscapeShell(&buf, target); @@ -2068,10 +2055,8 @@ int qemuMonitorMigrateToFile(qemuMonitorPtr mon, offset / QEMU_MONITOR_MIGRATE_TO_FILE_BS, QEMU_MONITOR_MIGRATE_TO_FILE_TRANSFER_SIZE, QEMU_MONITOR_MIGRATE_TO_FILE_TRANSFER_SIZE, - safe_target) < 0) { - virReportOOMError(); + safe_target) < 0) goto cleanup; - } if (mon->json) ret = qemuMonitorJSONMigrate(mon, flags, dest); @@ -2100,10 +2085,8 @@ int qemuMonitorMigrateToUnix(qemuMonitorPtr mon, return -1; } - if (virAsprintf(&dest, "unix:%s", unixfile) < 0) { - virReportOOMError(); + if (virAsprintf(&dest, "unix:%s", unixfile) < 0) return -1; - } if (mon->json) ret = qemuMonitorJSONMigrate(mon, flags, dest); diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 3383c88..d326551 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -252,10 +252,8 @@ qemuMonitorJSONCommandWithFd(qemuMonitorPtr mon, if (!(cmdstr = virJSONValueToString(cmd, false))) goto cleanup; - if (virAsprintf(&msg.txBuffer, "%s\r\n", cmdstr) < 0) { - virReportOOMError(); + if (virAsprintf(&msg.txBuffer, "%s\r\n", cmdstr) < 0) goto cleanup; - } msg.txLength = strlen(msg.txBuffer); msg.txFD = scm_fd; @@ -409,11 +407,11 @@ qemuMonitorJSONMakeCommandRaw(bool wrap, const char *cmdname, ...) va_start(args, cmdname); if (!(obj = virJSONValueNewObject())) - goto no_memory; + goto error; if (virJSONValueObjectAppendString(obj, wrap ? "type" : "execute", cmdname) < 0) - goto no_memory; + goto error; while ((key = va_arg(args, char *)) != NULL) { int ret; @@ -432,7 +430,7 @@ qemuMonitorJSONMakeCommandRaw(bool wrap, const char *cmdname, ...) if (!jargs && !(jargs = virJSONValueNewObject())) - goto no_memory; + goto error; /* This doesn't support maps, but no command uses those. */ switch (type) { @@ -488,19 +486,17 @@ qemuMonitorJSONMakeCommandRaw(bool wrap, const char *cmdname, ...) goto error; } if (ret < 0) - goto no_memory; + goto error; } if (jargs && virJSONValueObjectAppend(obj, wrap ? "data" : "arguments", jargs) < 0) - goto no_memory; + goto error; va_end(args); return obj; -no_memory: - virReportOOMError(); error: virJSONValueFree(obj); virJSONValueFree(jargs); @@ -533,7 +529,7 @@ qemuMonitorJSONKeywordStringToJSON(const char *str, const char *firstkeyword) int i; if (!(ret = virJSONValueNewObject())) - goto no_memory; + goto error; nkeywords = qemuParseKeywords(str, &keywords, &values, 1); @@ -550,19 +546,17 @@ qemuMonitorJSONKeywordStringToJSON(const char *str, const char *firstkeyword) /* This 3rd arg isn't a typo - the way the parser works is * that the value ended up in the keyword field */ if (virJSONValueObjectAppendString(ret, firstkeyword, keywords[i]) < 0) - goto no_memory; + goto error; } } else { if (virJSONValueObjectAppendString(ret, keywords[i], values[i]) < 0) - goto no_memory; + goto error; } } qemuFreeKeywords(nkeywords, keywords, values); return ret; -no_memory: - virReportOOMError(); error: qemuFreeKeywords(nkeywords, keywords, values); virJSONValueFree(ret); @@ -1202,10 +1196,8 @@ qemuMonitorJSONExtractCPUInfo(virJSONValuePtr reply, goto cleanup; } - if (VIR_REALLOC_N(threads, ncpus) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(threads, ncpus) < 0) goto cleanup; - } for (i = 0; i < ncpus; i++) { virJSONValuePtr entry = virJSONValueArrayGet(data, i); @@ -1545,10 +1537,8 @@ int qemuMonitorJSONGetBlockInfo(qemuMonitorPtr mon, if (STRPREFIX(thisdev, QEMU_DRIVE_HOST_PREFIX)) thisdev += strlen(QEMU_DRIVE_HOST_PREFIX); - if (VIR_ALLOC(info) < 0) { - virReportOOMError(); + if (VIR_ALLOC(info) < 0) goto cleanup; - } if (virHashAddEntry(table, thisdev, info) < 0) { VIR_FREE(info); @@ -2885,10 +2875,8 @@ int qemuMonitorJSONAddNetdev(qemuMonitorPtr mon, if (!args) goto cleanup; - if (virJSONValueObjectAppend(cmd, "arguments", args) < 0) { - virReportOOMError(); + if (virJSONValueObjectAppend(cmd, "arguments", args) < 0) goto cleanup; - } args = NULL; /* obj owns reference to args now */ ret = qemuMonitorJSONCommand(mon, cmd, &reply); @@ -3082,10 +3070,8 @@ int qemuMonitorJSONAddDevice(qemuMonitorPtr mon, if (!args) goto cleanup; - if (virJSONValueObjectAppend(cmd, "arguments", args) < 0) { - virReportOOMError(); + if (virJSONValueObjectAppend(cmd, "arguments", args) < 0) goto cleanup; - } args = NULL; /* obj owns reference to args now */ ret = qemuMonitorJSONCommand(mon, cmd, &reply); @@ -3139,10 +3125,8 @@ int qemuMonitorJSONSetDrivePassphrase(qemuMonitorPtr mon, virJSONValuePtr reply = NULL; char *drive; - if (virAsprintf(&drive, "%s%s", QEMU_DRIVE_HOST_PREFIX, alias) < 0) { - virReportOOMError(); + if (virAsprintf(&drive, "%s%s", QEMU_DRIVE_HOST_PREFIX, alias) < 0) return -1; - } cmd = qemuMonitorJSONMakeCommand("block_passwd", "s:device", drive, @@ -3204,9 +3188,7 @@ qemuMonitorJSONDiskSnapshot(qemuMonitorPtr mon, virJSONValuePtr actions, return -1; if (actions) { - if (virJSONValueArrayAppend(actions, cmd) < 0) { - virReportOOMError(); - } else { + if (virJSONValueArrayAppend(actions, cmd) == 0) { ret = 0; cmd = NULL; } @@ -3412,7 +3394,7 @@ int qemuMonitorJSONSendKey(qemuMonitorPtr mon, /* create the key data array */ if (!(keys = virJSONValueNewArray())) - goto no_memory; + goto cleanup; for (i = 0; i < nkeycodes; i++) { if (keycodes[i] > 0xffff) { @@ -3423,18 +3405,18 @@ int qemuMonitorJSONSendKey(qemuMonitorPtr mon, /* create single key object */ if (!(key = virJSONValueNewObject())) - goto no_memory; + goto cleanup; /* Union KeyValue has two types, use the generic one */ if (virJSONValueObjectAppendString(key, "type", "number") < 0) - goto no_memory; + goto cleanup; /* with the keycode */ if (virJSONValueObjectAppendNumberInt(key, "data", keycodes[i]) < 0) - goto no_memory; + goto cleanup; if (virJSONValueArrayAppend(keys, key) < 0) - goto no_memory; + goto cleanup; key = NULL; @@ -3463,10 +3445,6 @@ cleanup: virJSONValueFree(keys); virJSONValueFree(key); return ret; - -no_memory: - virReportOOMError(); - goto cleanup; } int qemuMonitorJSONScreendump(qemuMonitorPtr mon, @@ -4007,20 +3985,16 @@ int qemuMonitorJSONGetMachines(qemuMonitorPtr mon, } /* null-terminated list */ - if (VIR_ALLOC_N(infolist, n + 1) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(infolist, n + 1) < 0) goto cleanup; - } for (i = 0; i < n; i++) { virJSONValuePtr child = virJSONValueArrayGet(data, i); const char *tmp; qemuMonitorMachineInfoPtr info; - if (VIR_ALLOC(info) < 0) { - virReportOOMError(); + if (VIR_ALLOC(info) < 0) goto cleanup; - } infolist[i] = info; @@ -4123,10 +4097,8 @@ int qemuMonitorJSONGetCPUDefinitions(qemuMonitorPtr mon, } /* null-terminated list */ - if (VIR_ALLOC_N(cpulist, n + 1) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(cpulist, n + 1) < 0) goto cleanup; - } for (i = 0; i < n; i++) { virJSONValuePtr child = virJSONValueArrayGet(data, i); @@ -4193,10 +4165,8 @@ int qemuMonitorJSONGetCommands(qemuMonitorPtr mon, } /* null-terminated list */ - if (VIR_ALLOC_N(commandlist, n + 1) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(commandlist, n + 1) < 0) goto cleanup; - } for (i = 0; i < n; i++) { virJSONValuePtr child = virJSONValueArrayGet(data, i); @@ -4268,10 +4238,8 @@ int qemuMonitorJSONGetEvents(qemuMonitorPtr mon, } /* null-terminated list */ - if (VIR_ALLOC_N(eventlist, n + 1) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(eventlist, n + 1) < 0) goto cleanup; - } for (i = 0; i < n; i++) { virJSONValuePtr child = virJSONValueArrayGet(data, i); @@ -4382,10 +4350,8 @@ qemuMonitorJSONGetCommandLineOptionParameters(qemuMonitorPtr mon, } /* null-terminated list */ - if (VIR_ALLOC_N(paramlist, n + 1) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(paramlist, n + 1) < 0) goto cleanup; - } for (i = 0; i < n; i++) { virJSONValuePtr child = virJSONValueArrayGet(data, i); @@ -4509,10 +4475,8 @@ int qemuMonitorJSONGetObjectTypes(qemuMonitorPtr mon, } /* null-terminated list */ - if (VIR_ALLOC_N(typelist, n + 1) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(typelist, n + 1) < 0) goto cleanup; - } for (i = 0; i < n; i++) { virJSONValuePtr child = virJSONValueArrayGet(data, i); @@ -4587,10 +4551,8 @@ int qemuMonitorJSONGetObjectProps(qemuMonitorPtr mon, } /* null-terminated list */ - if (VIR_ALLOC_N(proplist, n + 1) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(proplist, n + 1) < 0) goto cleanup; - } for (i = 0; i < n; i++) { virJSONValuePtr child = virJSONValueArrayGet(data, i); @@ -4740,18 +4702,18 @@ qemuMonitorJSONSetMigrationCapability(qemuMonitorPtr mon, goto cleanup; if (!(cap = virJSONValueNewObject())) - goto no_memory; + goto cleanup; if (virJSONValueObjectAppendString( cap, "capability", qemuMonitorMigrationCapsTypeToString(capability)) < 0) - goto no_memory; + goto cleanup; if (virJSONValueObjectAppendBoolean(cap, "state", 1) < 0) - goto no_memory; + goto cleanup; if (virJSONValueArrayAppend(caps, cap) < 0) - goto no_memory; + goto cleanup; cap = NULL; @@ -4774,10 +4736,6 @@ cleanup: virJSONValueFree(cmd); virJSONValueFree(reply); return ret; - -no_memory: - virReportOOMError(); - goto cleanup; } int @@ -4794,19 +4752,15 @@ qemuMonitorJSONNBDServerStart(qemuMonitorPtr mon, if (!(data = virJSONValueNewObject()) || !(addr = virJSONValueNewObject()) || - (virAsprintf(&port_str, "%u", port) < 0)) { - virReportOOMError(); + (virAsprintf(&port_str, "%u", port) < 0)) goto cleanup; - } /* port is really expected as a string here by qemu */ if (virJSONValueObjectAppendString(data, "host", host) < 0 || virJSONValueObjectAppendString(data, "port", port_str) < 0 || virJSONValueObjectAppendString(addr, "type", "inet") < 0 || - virJSONValueObjectAppend(addr, "data", data) < 0) { - virReportOOMError(); + virJSONValueObjectAppend(addr, "data", data) < 0) goto cleanup; - } /* From now on, @data is part of @addr */ data = NULL; @@ -4929,10 +4883,8 @@ qemuMonitorJSONGetStringArray(qemuMonitorPtr mon, const char *qmpCmd, } /* null-terminated list */ - if (VIR_ALLOC_N(list, n + 1) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(list, n + 1) < 0) goto cleanup; - } for (i = 0; i < n; i++) { virJSONValuePtr child = virJSONValueArrayGet(data, i); diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c index 15fbcb7..9bc2b9e 100644 --- a/src/qemu/qemu_monitor_text.c +++ b/src/qemu/qemu_monitor_text.c @@ -190,10 +190,8 @@ int qemuMonitorTextIOProcess(qemuMonitorPtr mon ATTRIBUTE_UNUSED, * BASIC_PROMPT we can reasonably reliably cope */ if (want) { if (VIR_REALLOC_N(msg->rxBuffer, - msg->rxLength + want + 1) < 0) { - virReportOOMError(); + msg->rxLength + want + 1) < 0) return -1; - } memcpy(msg->rxBuffer + msg->rxLength, start, want); msg->rxLength += want; msg->rxBuffer[msg->rxLength] = '\0'; @@ -233,10 +231,8 @@ qemuMonitorTextCommandWithHandler(qemuMonitorPtr mon, memset(&msg, 0, sizeof(msg)); - if (virAsprintf(&msg.txBuffer, "%s\r", cmd) < 0) { - virReportOOMError(); + if (virAsprintf(&msg.txBuffer, "%s\r", cmd) < 0) return -1; - } msg.txLength = strlen(msg.txBuffer); msg.txFD = scm_fd; msg.passwordHandler = passwordHandler; @@ -346,7 +342,6 @@ qemuMonitorSendDiskPassphrase(qemuMonitorPtr mon, msg->txLength + passphrase_len + 1 + 1) < 0) { memset(passphrase, 0, passphrase_len); VIR_FREE(passphrase); - virReportOOMError(); return -1; } @@ -457,10 +452,8 @@ int qemuMonitorTextSetLink(qemuMonitorPtr mon, const char *name, enum virDomainN else st_str = "on"; - if (virAsprintf(&cmd, "set_link %s %s", name, st_str) < 0) { - virReportOOMError(); + if (virAsprintf(&cmd, "set_link %s %s", name, st_str) < 0) goto error; - } if (qemuMonitorHMPCommand(mon, cmd, &info) < 0) goto error; @@ -768,10 +761,8 @@ int qemuMonitorTextGetBlockInfo(qemuMonitorPtr mon, dev = p; p = strchr(p, ':'); if (p && p < eol && *(p + 1) == ' ') { - if (VIR_ALLOC(info) < 0) { - virReportOOMError(); + if (VIR_ALLOC(info) < 0) goto cleanup; - } *p = '\0'; p += 2; @@ -1057,10 +1048,8 @@ int qemuMonitorTextBlockResize(qemuMonitorPtr mon, char *reply = NULL; int ret = -1; - if (virAsprintf(&cmd, "block_resize %s %lluB", device, size) < 0) { - virReportOOMError(); + if (virAsprintf(&cmd, "block_resize %s %lluB", device, size) < 0) goto cleanup; - } if (qemuMonitorHMPCommand(mon, cmd, &reply) < 0) goto cleanup; @@ -1091,10 +1080,8 @@ qemuMonitorSendVNCPassphrase(qemuMonitorPtr mon ATTRIBUTE_UNUSED, /* Enlarge transmit buffer to allow for the extra data * to be sent back */ if (VIR_REALLOC_N(msg->txBuffer, - msg->txLength + passphrase_len + 1 + 1) < 0) { - virReportOOMError(); + msg->txLength + passphrase_len + 1 + 1) < 0) return -1; - } /* Queue the password for sending */ memcpy(msg->txBuffer + msg->txLength, @@ -1135,10 +1122,8 @@ int qemuMonitorTextSetPassword(qemuMonitorPtr mon, int ret = -1; if (virAsprintf(&cmd, "set_password %s \"%s\" %s", - protocol, password, action_if_connected) < 0) { - virReportOOMError(); + protocol, password, action_if_connected) < 0) goto cleanup; - } if (qemuMonitorHMPCommand(mon, cmd, &reply) < 0) goto cleanup; @@ -1166,10 +1151,8 @@ int qemuMonitorTextExpirePassword(qemuMonitorPtr mon, int ret = -1; if (virAsprintf(&cmd, "expire_password %s %s", - protocol, expire_time) < 0) { - virReportOOMError(); + protocol, expire_time) < 0) goto cleanup; - } if (qemuMonitorHMPCommand(mon, cmd, &reply) < 0) goto cleanup; @@ -1202,10 +1185,8 @@ int qemuMonitorTextSetBalloon(qemuMonitorPtr mon, * 'newmem' is in KB, QEMU monitor works in MB, and we all wish * we just worked in bytes with unsigned long long everywhere. */ - if (virAsprintf(&cmd, "balloon %lu", VIR_DIV_UP(newmem, 1024)) < 0) { - virReportOOMError(); + if (virAsprintf(&cmd, "balloon %lu", VIR_DIV_UP(newmem, 1024)) < 0) return -1; - } if (qemuMonitorHMPCommand(mon, cmd, &reply) < 0) { VIR_FREE(cmd); @@ -1237,10 +1218,8 @@ int qemuMonitorTextSetCPU(qemuMonitorPtr mon, int cpu, bool online) char *reply = NULL; int ret = -1; - if (virAsprintf(&cmd, "cpu_set %d %s", cpu, online ? "online" : "offline") < 0) { - virReportOOMError(); + if (virAsprintf(&cmd, "cpu_set %d %s", cpu, online ? "online" : "offline") < 0) return -1; - } if (qemuMonitorHMPCommand(mon, cmd, &reply) < 0) { VIR_FREE(cmd); @@ -1270,10 +1249,8 @@ int qemuMonitorTextEjectMedia(qemuMonitorPtr mon, char *reply = NULL; int ret = -1; - if (virAsprintf(&cmd, "eject %s%s", force ? "-f " : "", dev_name) < 0) { - virReportOOMError(); + if (virAsprintf(&cmd, "eject %s%s", force ? "-f " : "", dev_name) < 0) goto cleanup; - } if (qemuMonitorHMPCommand(mon, cmd, &reply) < 0) goto cleanup; @@ -1306,15 +1283,11 @@ int qemuMonitorTextChangeMedia(qemuMonitorPtr mon, char *safepath = NULL; int ret = -1; - if (!(safepath = qemuMonitorEscapeArg(newmedia))) { - virReportOOMError(); + if (!(safepath = qemuMonitorEscapeArg(newmedia))) goto cleanup; - } - if (virAsprintf(&cmd, "change %s \"%s\"", dev_name, safepath) < 0) { - virReportOOMError(); + if (virAsprintf(&cmd, "change %s \"%s\"", dev_name, safepath) < 0) goto cleanup; - } if (qemuMonitorHMPCommand(mon, cmd, &reply) < 0) goto cleanup; @@ -1355,15 +1328,11 @@ static int qemuMonitorTextSaveMemory(qemuMonitorPtr mon, char *safepath = NULL; int ret = -1; - if (!(safepath = qemuMonitorEscapeArg(path))) { - virReportOOMError(); + if (!(safepath = qemuMonitorEscapeArg(path))) goto cleanup; - } - if (virAsprintf(&cmd, "%s %llu %zi \"%s\"", cmdtype, offset, length, safepath) < 0) { - virReportOOMError(); + if (virAsprintf(&cmd, "%s %llu %zi \"%s\"", cmdtype, offset, length, safepath) < 0) goto cleanup; - } if (qemuMonitorHMPCommand(mon, cmd, &reply) < 0) goto cleanup; @@ -1404,10 +1373,8 @@ int qemuMonitorTextSetMigrationSpeed(qemuMonitorPtr mon, char *info = NULL; int ret = -1; - if (virAsprintf(&cmd, "migrate_set_speed %lum", bandwidth) < 0) { - virReportOOMError(); + if (virAsprintf(&cmd, "migrate_set_speed %lum", bandwidth) < 0) goto cleanup; - } if (qemuMonitorHMPCommand(mon, cmd, &info) < 0) goto cleanup; @@ -1428,10 +1395,8 @@ int qemuMonitorTextSetMigrationDowntime(qemuMonitorPtr mon, char *info = NULL; int ret = -1; - if (virAsprintf(&cmd, "migrate_set_downtime %llums", downtime) < 0) { - virReportOOMError(); + if (virAsprintf(&cmd, "migrate_set_downtime %llums", downtime) < 0) goto cleanup; - } if (qemuMonitorHMPCommand(mon, cmd, &info) < 0) goto cleanup; @@ -1592,10 +1557,8 @@ int qemuMonitorTextMigrate(qemuMonitorPtr mon, virBuffer extra = VIR_BUFFER_INITIALIZER; char *extrastr = NULL; - if (!safedest) { - virReportOOMError(); + if (!safedest) return -1; - } if (flags & QEMU_MONITOR_MIGRATE_BACKGROUND) virBufferAddLit(&extra, " -d"); @@ -1611,10 +1574,8 @@ int qemuMonitorTextMigrate(qemuMonitorPtr mon, extrastr = virBufferContentAndReset(&extra); if (virAsprintf(&cmd, "migrate %s\"%s\"", extrastr ? extrastr : "", - safedest) < 0) { - virReportOOMError(); + safedest) < 0) goto cleanup; - } if (qemuMonitorHMPCommand(mon, cmd, &info) < 0) goto cleanup; @@ -1668,10 +1629,8 @@ int qemuMonitorTextGraphicsRelocate(qemuMonitorPtr mon, if (virAsprintf(&cmd, "client_migrate_info %s %s %d %d %s", type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE ? "spice" : "vnc", - hostname, port, tlsPort, tlsSubject ? tlsSubject : "") < 0) { - virReportOOMError(); + hostname, port, tlsPort, tlsSubject ? tlsSubject : "") < 0) return -1; - } if (qemuMonitorHMPCommand(mon, cmd, &info) < 0) { VIR_FREE(cmd); @@ -1693,15 +1652,11 @@ int qemuMonitorTextAddUSBDisk(qemuMonitorPtr mon, char *info = NULL; safepath = qemuMonitorEscapeArg(path); - if (!safepath) { - virReportOOMError(); + if (!safepath) return -1; - } - if (virAsprintf(&cmd, "usb_add disk:%s", safepath) < 0) { - virReportOOMError(); + if (virAsprintf(&cmd, "usb_add disk:%s", safepath) < 0) goto cleanup; - } if (qemuMonitorHMPCommand(mon, cmd, &info) < 0) goto cleanup; @@ -1731,10 +1686,8 @@ static int qemuMonitorTextAddUSBDevice(qemuMonitorPtr mon, char *reply = NULL; int ret = -1; - if (virAsprintf(&cmd, "usb_add %s", addr) < 0) { - virReportOOMError(); + if (virAsprintf(&cmd, "usb_add %s", addr) < 0) return -1; - } if (qemuMonitorHMPCommand(mon, cmd, &reply) < 0) goto cleanup; @@ -1763,10 +1716,8 @@ int qemuMonitorTextAddUSBDeviceExact(qemuMonitorPtr mon, int ret; char *addr; - if (virAsprintf(&addr, "host:%.3d.%.3d", bus, dev) < 0) { - virReportOOMError(); + if (virAsprintf(&addr, "host:%.3d.%.3d", bus, dev) < 0) return -1; - } ret = qemuMonitorTextAddUSBDevice(mon, addr); @@ -1781,10 +1732,8 @@ int qemuMonitorTextAddUSBDeviceMatch(qemuMonitorPtr mon, int ret; char *addr; - if (virAsprintf(&addr, "host:%.4x:%.4x", vendor, product) < 0) { - virReportOOMError(); + if (virAsprintf(&addr, "host:%.4x:%.4x", vendor, product) < 0) return -1; - } ret = qemuMonitorTextAddUSBDevice(mon, addr); @@ -1869,10 +1818,8 @@ int qemuMonitorTextAddPCIHostDevice(qemuMonitorPtr mon, /* XXX hostAddr->domain */ if (virAsprintf(&cmd, "pci_add pci_addr=auto host host=%.2x:%.2x.%.1x", - hostAddr->bus, hostAddr->slot, hostAddr->function) < 0) { - virReportOOMError(); + hostAddr->bus, hostAddr->slot, hostAddr->function) < 0) goto cleanup; - } if (qemuMonitorHMPCommand(mon, cmd, &reply) < 0) goto cleanup; @@ -1910,17 +1857,13 @@ int qemuMonitorTextAddPCIDisk(qemuMonitorPtr mon, int ret = -1; safe_path = qemuMonitorEscapeArg(path); - if (!safe_path) { - virReportOOMError(); + if (!safe_path) return -1; - } try_command: if (virAsprintf(&cmd, "pci_add %s storage file=%s,if=%s", - (tryOldSyntax ? "0": "pci_addr=auto"), safe_path, bus) < 0) { - virReportOOMError(); + (tryOldSyntax ? "0": "pci_addr=auto"), safe_path, bus) < 0) goto cleanup; - } if (qemuMonitorHMPCommand(mon, cmd, &reply) < 0) goto cleanup; @@ -1956,10 +1899,8 @@ int qemuMonitorTextAddPCINetwork(qemuMonitorPtr mon, char *reply = NULL; int ret = -1; - if (virAsprintf(&cmd, "pci_add pci_addr=auto nic %s", nicstr) < 0) { - virReportOOMError(); + if (virAsprintf(&cmd, "pci_add pci_addr=auto nic %s", nicstr) < 0) return -1; - } if (qemuMonitorHMPCommand(mon, cmd, &reply) < 0) goto cleanup; @@ -1989,17 +1930,13 @@ int qemuMonitorTextRemovePCIDevice(qemuMonitorPtr mon, try_command: if (tryOldSyntax) { - if (virAsprintf(&cmd, "pci_del 0 %.2x", guestAddr->slot) < 0) { - virReportOOMError(); + if (virAsprintf(&cmd, "pci_del 0 %.2x", guestAddr->slot) < 0) goto cleanup; - } } else { /* XXX function ? */ if (virAsprintf(&cmd, "pci_del pci_addr=%.4x:%.2x:%.2x", - guestAddr->domain, guestAddr->bus, guestAddr->slot) < 0) { - virReportOOMError(); + guestAddr->domain, guestAddr->bus, guestAddr->slot) < 0) goto cleanup; - } } if (qemuMonitorHMPCommand(mon, cmd, &reply) < 0) @@ -2042,10 +1979,8 @@ int qemuMonitorTextSendFileHandle(qemuMonitorPtr mon, char *reply = NULL; int ret = -1; - if (virAsprintf(&cmd, "getfd %s", fdname) < 0) { - virReportOOMError(); + if (virAsprintf(&cmd, "getfd %s", fdname) < 0) return -1; - } if (qemuMonitorHMPCommandWithFd(mon, cmd, fd, &reply) < 0) goto cleanup; @@ -2082,10 +2017,8 @@ int qemuMonitorTextCloseFileHandle(qemuMonitorPtr mon, char *reply = NULL; int ret = -1; - if (virAsprintf(&cmd, "closefd %s", fdname) < 0) { - virReportOOMError(); + if (virAsprintf(&cmd, "closefd %s", fdname) < 0) return -1; - } if (qemuMonitorHMPCommand(mon, cmd, &reply) < 0) goto cleanup; @@ -2115,10 +2048,8 @@ int qemuMonitorTextAddHostNetwork(qemuMonitorPtr mon, char *reply = NULL; int ret = -1; - if (virAsprintf(&cmd, "host_net_add %s", netstr) < 0) { - virReportOOMError(); + if (virAsprintf(&cmd, "host_net_add %s", netstr) < 0) return -1; - } if (qemuMonitorHMPCommand(mon, cmd, &reply) < 0) goto cleanup; @@ -2147,10 +2078,8 @@ int qemuMonitorTextRemoveHostNetwork(qemuMonitorPtr mon, char *reply = NULL; int ret = -1; - if (virAsprintf(&cmd, "host_net_remove %d %s", vlan, netname) < 0) { - virReportOOMError(); + if (virAsprintf(&cmd, "host_net_remove %d %s", vlan, netname) < 0) return -1; - } if (qemuMonitorHMPCommand(mon, cmd, &reply) < 0) goto cleanup; @@ -2173,10 +2102,8 @@ int qemuMonitorTextAddNetdev(qemuMonitorPtr mon, char *reply = NULL; int ret = -1; - if (virAsprintf(&cmd, "netdev_add %s", netdevstr) < 0) { - virReportOOMError(); + if (virAsprintf(&cmd, "netdev_add %s", netdevstr) < 0) return -1; - } if (qemuMonitorHMPCommand(mon, cmd, &reply) < 0) goto cleanup; @@ -2199,10 +2126,8 @@ int qemuMonitorTextRemoveNetdev(qemuMonitorPtr mon, char *reply = NULL; int ret = -1; - if (virAsprintf(&cmd, "netdev_del %s", alias) < 0) { - virReportOOMError(); + if (virAsprintf(&cmd, "netdev_del %s", alias) < 0) return -1; - } if (qemuMonitorHMPCommand(mon, cmd, &reply) < 0) goto cleanup; @@ -2311,10 +2236,8 @@ int qemuMonitorTextAttachPCIDiskController(qemuMonitorPtr mon, try_command: if (virAsprintf(&cmd, "pci_add %s storage if=%s", - (tryOldSyntax ? "0": "pci_addr=auto"), bus) < 0) { - virReportOOMError(); + (tryOldSyntax ? "0": "pci_addr=auto"), bus) < 0) goto cleanup; - } if (qemuMonitorHMPCommand(mon, cmd, &reply) < 0) goto cleanup; @@ -2398,19 +2321,15 @@ int qemuMonitorTextAttachDrive(qemuMonitorPtr mon, bool tryOldSyntax = false; safe_str = qemuMonitorEscapeArg(drivestr); - if (!safe_str) { - virReportOOMError(); + if (!safe_str) return -1; - } try_command: if (virAsprintf(&cmd, "drive_add %s%.2x:%.2x:%.2x %s", (tryOldSyntax ? "" : "pci_addr="), controllerAddr->domain, controllerAddr->bus, - controllerAddr->slot, safe_str) < 0) { - virReportOOMError(); + controllerAddr->slot, safe_str) < 0) goto cleanup; - } if (qemuMonitorHMPCommand(mon, cmd, &reply) < 0) goto cleanup; @@ -2538,10 +2457,8 @@ int qemuMonitorTextGetAllPCIAddresses(qemuMonitorPtr mon, p++; GET_INT(p, 16, product); - if (VIR_REALLOC_N(addrs, naddrs+1) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(addrs, naddrs+1) < 0) goto error; - } addrs[naddrs].addr.domain = 0; addrs[naddrs].addr.bus = bus; @@ -2579,15 +2496,11 @@ int qemuMonitorTextDelDevice(qemuMonitorPtr mon, char *safedev; int ret = -1; - if (!(safedev = qemuMonitorEscapeArg(devalias))) { - virReportOOMError(); + if (!(safedev = qemuMonitorEscapeArg(devalias))) goto cleanup; - } - if (virAsprintf(&cmd, "device_del %s", safedev) < 0) { - virReportOOMError(); + if (virAsprintf(&cmd, "device_del %s", safedev) < 0) goto cleanup; - } VIR_DEBUG("TextDelDevice devalias=%s", devalias); if (qemuMonitorHMPCommand(mon, cmd, &reply) < 0) @@ -2617,15 +2530,11 @@ int qemuMonitorTextAddDevice(qemuMonitorPtr mon, char *safedev; int ret = -1; - if (!(safedev = qemuMonitorEscapeArg(devicestr))) { - virReportOOMError(); + if (!(safedev = qemuMonitorEscapeArg(devicestr))) goto cleanup; - } - if (virAsprintf(&cmd, "device_add %s", safedev) < 0) { - virReportOOMError(); + if (virAsprintf(&cmd, "device_add %s", safedev) < 0) goto cleanup; - } if (qemuMonitorHMPCommand(mon, cmd, &reply) < 0) goto cleanup; @@ -2665,17 +2574,13 @@ int qemuMonitorTextAddDrive(qemuMonitorPtr mon, char *safe_str; safe_str = qemuMonitorEscapeArg(drivestr); - if (!safe_str) { - virReportOOMError(); + if (!safe_str) return -1; - } /* 'dummy' here is just a placeholder since there is no PCI * address required when attaching drives to a controller */ - if (virAsprintf(&cmd, "drive_add dummy %s", safe_str) < 0) { - virReportOOMError(); + if (virAsprintf(&cmd, "drive_add dummy %s", safe_str) < 0) goto cleanup; - } if (qemuMonitorHMPCommand(mon, cmd, &reply) < 0) goto cleanup; @@ -2712,15 +2617,11 @@ int qemuMonitorTextDriveDel(qemuMonitorPtr mon, int ret = -1; VIR_DEBUG("TextDriveDel drivestr=%s", drivestr); - if (!(safedev = qemuMonitorEscapeArg(drivestr))) { - virReportOOMError(); + if (!(safedev = qemuMonitorEscapeArg(drivestr))) goto cleanup; - } - if (virAsprintf(&cmd, "drive_del %s", safedev) < 0) { - virReportOOMError(); + if (virAsprintf(&cmd, "drive_del %s", safedev) < 0) goto cleanup; - } if (qemuMonitorHMPCommand(mon, cmd, &reply) < 0) goto cleanup; @@ -2761,16 +2662,12 @@ int qemuMonitorTextSetDrivePassphrase(qemuMonitorPtr mon, char *safe_str; safe_str = qemuMonitorEscapeArg(passphrase); - if (!safe_str) { - virReportOOMError(); + if (!safe_str) return -1; - } if (virAsprintf(&cmd, "block_passwd %s%s \"%s\"", - QEMU_DRIVE_HOST_PREFIX, alias, safe_str) < 0) { - virReportOOMError(); + QEMU_DRIVE_HOST_PREFIX, alias, safe_str) < 0) goto cleanup; - } if (qemuMonitorHMPCommand(mon, cmd, &reply) < 0) goto cleanup; @@ -2802,10 +2699,8 @@ int qemuMonitorTextCreateSnapshot(qemuMonitorPtr mon, const char *name) char *safename; if (!(safename = qemuMonitorEscapeArg(name)) || - virAsprintf(&cmd, "savevm \"%s\"", safename) < 0) { - virReportOOMError(); + virAsprintf(&cmd, "savevm \"%s\"", safename) < 0) goto cleanup; - } if (qemuMonitorHMPCommand(mon, cmd, &reply)) goto cleanup; @@ -2847,10 +2742,8 @@ int qemuMonitorTextLoadSnapshot(qemuMonitorPtr mon, const char *name) char *safename; if (!(safename = qemuMonitorEscapeArg(name)) || - virAsprintf(&cmd, "loadvm \"%s\"", safename) < 0) { - virReportOOMError(); + virAsprintf(&cmd, "loadvm \"%s\"", safename) < 0) goto cleanup; - } if (qemuMonitorHMPCommand(mon, cmd, &reply)) goto cleanup; @@ -2902,10 +2795,8 @@ int qemuMonitorTextDeleteSnapshot(qemuMonitorPtr mon, const char *name) char *safename; if (!(safename = qemuMonitorEscapeArg(name)) || - virAsprintf(&cmd, "delvm \"%s\"", safename) < 0) { - virReportOOMError(); + virAsprintf(&cmd, "delvm \"%s\"", safename) < 0) goto cleanup; - } if (qemuMonitorHMPCommand(mon, cmd, &reply)) goto cleanup; @@ -2940,10 +2831,8 @@ int qemuMonitorTextArbitraryCommand(qemuMonitorPtr mon, const char *cmd, char *safecmd = NULL; int ret; - if (!(safecmd = qemuMonitorEscapeArg(cmd))) { - virReportOOMError(); + if (!(safecmd = qemuMonitorEscapeArg(cmd))) return -1; - } ret = qemuMonitorHMPCommand(mon, safecmd, reply); @@ -3032,10 +2921,8 @@ int qemuMonitorTextScreendump(qemuMonitorPtr mon, const char *file) char *reply = NULL; int ret = -1; - if (virAsprintf(&cmd, "screendump %s", file) < 0){ - virReportOOMError(); + if (virAsprintf(&cmd, "screendump %s", file) < 0) goto cleanup; - } if (qemuMonitorHMPCommand(mon, cmd, &reply) < 0) goto cleanup; @@ -3063,10 +2950,8 @@ int qemuMonitorTextOpenGraphics(qemuMonitorPtr mon, char *reply = NULL; int ret = -1; - if (virAsprintf(&cmd, "add_client %s %s %d", protocol, fdname, skipauth ? 0 : 1) < 0){ - virReportOOMError(); + if (virAsprintf(&cmd, "add_client %s %s %d", protocol, fdname, skipauth ? 0 : 1) < 0) goto cleanup; - } if (qemuMonitorHMPCommand(mon, cmd, &reply) < 0) goto cleanup; @@ -3097,10 +2982,8 @@ int qemuMonitorTextSetBlockIoThrottle(qemuMonitorPtr mon, if (virAsprintf(&cmd, "%s %s %llu %llu %llu %llu %llu %llu", cmd_name, device, info->total_bytes_sec, info->read_bytes_sec, info->write_bytes_sec, info->total_iops_sec, - info->read_iops_sec, info->write_iops_sec) < 0) { - virReportOOMError(); + info->read_iops_sec, info->write_iops_sec) < 0) goto cleanup; - } if (qemuMonitorHMPCommand(mon, cmd, &result) < 0) goto cleanup; diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index df0ac72..6833662 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -88,10 +88,8 @@ qemuProcessRemoveDomainStatus(virQEMUDriverPtr driver, virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); int ret = -1; - if (virAsprintf(&file, "%s/%s.xml", cfg->stateDir, vm->def->name) < 0) { - virReportOOMError(); + if (virAsprintf(&file, "%s/%s.xml", cfg->stateDir, vm->def->name) < 0) goto cleanup; - } if (unlink(file) < 0 && errno != ENOENT && errno != ENOTDIR) VIR_WARN("Failed to remove domain XML for %s: %s", @@ -465,7 +463,6 @@ qemuProcessGetVolumeQcowPassphrase(virConnectPtr conn, if (VIR_ALLOC_N(passphrase, size + 1) < 0) { memset(data, 0, size); VIR_FREE(data); - virReportOOMError(); goto cleanup; } memcpy(passphrase, data, size); @@ -879,8 +876,6 @@ qemuProcessHandleWatchdog(qemuMonitorPtr mon ATTRIBUTE_UNUSED, vm = NULL; VIR_FREE(processEvent); } - } else { - virReportOOMError(); } } @@ -1023,24 +1018,24 @@ qemuProcessHandleGraphics(qemuMonitorPtr mon ATTRIBUTE_UNUSED, int i; if (VIR_ALLOC(localAddr) < 0) - goto no_memory; + goto error; localAddr->family = localFamily; if (VIR_STRDUP(localAddr->service, localService) < 0 || VIR_STRDUP(localAddr->node, localNode) < 0) goto error; if (VIR_ALLOC(remoteAddr) < 0) - goto no_memory; + goto error; remoteAddr->family = remoteFamily; if (VIR_STRDUP(remoteAddr->service, remoteService) < 0 || VIR_STRDUP(remoteAddr->node, remoteNode) < 0) goto error; if (VIR_ALLOC(subject) < 0) - goto no_memory; + goto error; if (x509dname) { if (VIR_REALLOC_N(subject->identities, subject->nidentity+1) < 0) - goto no_memory; + goto error; subject->nidentity++; if (VIR_STRDUP(subject->identities[subject->nidentity-1].type, "x509dname") < 0 || VIR_STRDUP(subject->identities[subject->nidentity-1].name, x509dname) < 0) @@ -1048,7 +1043,7 @@ qemuProcessHandleGraphics(qemuMonitorPtr mon ATTRIBUTE_UNUSED, } if (saslUsername) { if (VIR_REALLOC_N(subject->identities, subject->nidentity+1) < 0) - goto no_memory; + goto error; subject->nidentity++; if (VIR_STRDUP(subject->identities[subject->nidentity-1].type, "saslUsername") < 0 || VIR_STRDUP(subject->identities[subject->nidentity-1].name, saslUsername) < 0) @@ -1064,8 +1059,6 @@ qemuProcessHandleGraphics(qemuMonitorPtr mon ATTRIBUTE_UNUSED, return 0; -no_memory: - virReportOOMError(); error: if (localAddr) { VIR_FREE(localAddr->service); @@ -1296,10 +1289,8 @@ qemuProcessHandleGuestPanic(qemuMonitorPtr mon ATTRIBUTE_UNUSED, struct qemuProcessEvent *processEvent; virObjectLock(vm); - if (VIR_ALLOC(processEvent) < 0) { - virReportOOMError(); + if (VIR_ALLOC(processEvent) < 0) goto cleanup; - } processEvent->eventType = QEMU_PROCESS_EVENT_GUESTPANIC; processEvent->action = vm->def->onCrash; @@ -1733,10 +1724,8 @@ qemuProcessWaitForMonitor(virQEMUDriverPtr driver, if ((logfd = qemuDomainOpenLog(driver, vm, pos)) < 0) return -1; - if (VIR_ALLOC_N(buf, buf_size) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(buf, buf_size) < 0) goto closelog; - } if (qemuProcessReadLogOutput(vm, logfd, buf, buf_size, qemuProcessFindCharDevicePTYs, @@ -1777,10 +1766,8 @@ cleanup: if ((logfd = qemuDomainOpenLog(driver, vm, pos)) < 0) return -1; - if (VIR_ALLOC_N(buf, buf_size) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(buf, buf_size) < 0) goto closelog; - } } len = strlen(buf); @@ -1820,10 +1807,8 @@ qemuProcessDetectVcpuPIDs(virQEMUDriverPtr driver, virResetLastError(); priv->nvcpupids = 1; - if (VIR_ALLOC_N(priv->vcpupids, priv->nvcpupids) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(priv->vcpupids, priv->nvcpupids) < 0) return -1; - } priv->vcpupids[0] = vm->pid; return 0; } @@ -1864,10 +1849,8 @@ qemuPrepareCpumap(virQEMUDriverPtr driver, if (maxcpu > hostcpus) maxcpu = hostcpus; - if (!(cpumap = virBitmapNew(maxcpu))) { - virReportOOMError(); + if (!(cpumap = virBitmapNew(maxcpu))) return NULL; - } if (nodemask) { if (!(caps = virQEMUDriverGetCapabilities(driver, false))) { @@ -2577,13 +2560,8 @@ qemuProcessPrepareMonitorChr(virQEMUDriverConfigPtr cfg, monConfig->type = VIR_DOMAIN_CHR_TYPE_UNIX; monConfig->data.nix.listen = true; - if (virAsprintf(&monConfig->data.nix.path, "%s/%s.monitor", - cfg->libDir, vm) < 0) { - virReportOOMError(); - return -1; - } - - return 0; + return virAsprintf(&monConfig->data.nix.path, "%s/%s.monitor", + cfg->libDir, vm); } @@ -3172,10 +3150,8 @@ qemuProcessReconnectHelper(virDomainObjPtr obj, struct qemuProcessReconnectData *src = opaque; struct qemuProcessReconnectData *data; - if (VIR_ALLOC(data) < 0) { - virReportOOMError(); + if (VIR_ALLOC(data) < 0) return -1; - } memcpy(data, src, sizeof(*data)); data->payload = obj; @@ -3537,10 +3513,8 @@ int qemuProcessStart(virConnectPtr conn, if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC || graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE) { if (graphics->nListens == 0) { - if (VIR_EXPAND_N(graphics->listens, graphics->nListens, 1) < 0) { - virReportOOMError(); + if (VIR_EXPAND_N(graphics->listens, graphics->nListens, 1) < 0) goto cleanup; - } graphics->listens[0].type = VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS; if (VIR_STRDUP(graphics->listens[0].address, graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC ? @@ -3622,10 +3596,8 @@ int qemuProcessStart(virConnectPtr conn, if (qemuSetupCgroup(driver, vm, nodemask) < 0) goto cleanup; - if (VIR_ALLOC(priv->monConfig) < 0) { - virReportOOMError(); + if (VIR_ALLOC(priv->monConfig) < 0) goto cleanup; - } VIR_DEBUG("Preparing monitor state"); if (qemuProcessPrepareMonitorChr(cfg, priv->monConfig, vm->def->name) < 0) @@ -3694,7 +3666,6 @@ int qemuProcessStart(virConnectPtr conn, } if ((timestamp = virTimeStringNow()) == NULL) { - virReportOOMError(); goto cleanup; } else { if (safewrite(logfile, timestamp, strlen(timestamp)) < 0 || @@ -4054,9 +4025,7 @@ void qemuProcessStop(virQEMUDriverPtr driver, VIR_WARN("Unable to open logfile: %s", virStrerror(errno, ebuf, sizeof(ebuf))); } else { - if ((timestamp = virTimeStringNow()) == NULL) { - virReportOOMError(); - } else { + if ((timestamp = virTimeStringNow()) != NULL) { if (safewrite(logfile, timestamp, strlen(timestamp)) < 0 || safewrite(logfile, SHUTDOWN_POSTFIX, strlen(SHUTDOWN_POSTFIX)) < 0) { @@ -4341,7 +4310,7 @@ int qemuProcessAttach(virConnectPtr conn ATTRIBUTE_UNUSED, } seclabeldef->type = VIR_DOMAIN_SECLABEL_STATIC; if (VIR_ALLOC(seclabel) < 0) - goto no_memory; + goto cleanup; if (virSecurityManagerGetProcessLabel(driver->securityManager, vm->def, vm->pid, seclabel) < 0) goto cleanup; @@ -4385,7 +4354,6 @@ int qemuProcessAttach(virConnectPtr conn ATTRIBUTE_UNUSED, } if ((timestamp = virTimeStringNow()) == NULL) { - virReportOOMError(); goto cleanup; } else { if (safewrite(logfile, timestamp, strlen(timestamp)) < 0 || @@ -4479,8 +4447,6 @@ int qemuProcessAttach(virConnectPtr conn ATTRIBUTE_UNUSED, return 0; -no_memory: - virReportOOMError(); cleanup: /* We jump here if we failed to start the VM for any reason, or * if we failed to initialize the now running VM. kill it off and -- 1.8.1.5

On 07/04/2013 02:06 PM, Michal Privoznik wrote: [...]
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index ba93233..7288ce7 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -10289,7 +10186,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps,
if (!(disk->src || disk->nhosts > 0) || !disk->dst) - goto no_memory; + goto error;
I can't see how this can get true in the code, especially due to no memory. However, this is there already, so I'm more curious than concerned. But please check that any possible OOMError gets reported in this path. ACK, Martin

--- src/remote/remote_driver.c | 107 ++++++++++++--------------------------------- 1 file changed, 27 insertions(+), 80 deletions(-) diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 7f3e833..c2f1132 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -495,7 +495,7 @@ doRemoteOpen(virConnectPtr conn, /* Remote server defaults to "localhost" if not specified. */ if (conn->uri && conn->uri->port != 0) { if (virAsprintf(&port, "%d", conn->uri->port) < 0) - goto no_memory; + goto failed; } else if (transport == trans_tls) { if (VIR_STRDUP(port, LIBVIRTD_TLS_PORT) < 0) goto failed; @@ -677,7 +677,7 @@ doRemoteOpen(virConnectPtr conn, if (virAsprintf(&sockname, "%s/" LIBVIRTD_USER_UNIX_SOCKET, userdir) < 0) { VIR_FREE(userdir); - goto no_memory; + goto failed; } VIR_FREE(userdir); } else { @@ -878,9 +878,6 @@ doRemoteOpen(virConnectPtr conn, return retcode; -no_memory: - virReportOOMError(); - failed: virObjectUnref(priv->remoteProgram); virObjectUnref(priv->lxcProgram); @@ -899,10 +896,8 @@ static struct private_data * remoteAllocPrivateData(void) { struct private_data *priv; - if (VIR_ALLOC(priv) < 0) { - virReportOOMError(); + if (VIR_ALLOC(priv) < 0) return NULL; - } if (virMutexInit(&priv->lock) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -1429,17 +1424,13 @@ remoteConnectListAllDomains(virConnectPtr conn, goto done; if (domains) { - if (VIR_ALLOC_N(doms, ret.domains.domains_len + 1) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(doms, ret.domains.domains_len + 1) < 0) goto cleanup; - } for (i = 0; i < ret.domains.domains_len; i++) { doms[i] = get_nonnull_domain(conn, ret.domains.domains_val[i]); - if (!doms[i]) { - virReportOOMError(); + if (!doms[i]) goto cleanup; - } } *domains = doms; doms = NULL; @@ -1493,10 +1484,8 @@ remoteSerializeTypedParameters(virTypedParameterPtr params, remote_typed_param *val; *args_params_len = nparams; - if (VIR_ALLOC_N(val, nparams) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(val, nparams) < 0) goto cleanup; - } for (i = 0; i < nparams; ++i) { /* call() will free this: */ @@ -1563,10 +1552,8 @@ remoteDeserializeTypedParameters(remote_typed_param *ret_params_val, goto cleanup; } } else { - if (VIR_ALLOC_N(*params, ret_params_len) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(*params, ret_params_len) < 0) goto cleanup; - } } *nparams = ret_params_len; @@ -2850,17 +2837,13 @@ remoteConnectListAllNetworks(virConnectPtr conn, goto done; if (nets) { - if (VIR_ALLOC_N(tmp_nets, ret.nets.nets_len + 1) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(tmp_nets, ret.nets.nets_len + 1) < 0) goto cleanup; - } for (i = 0; i < ret.nets.nets_len; i++) { tmp_nets[i] = get_nonnull_network(conn, ret.nets.nets_val[i]); - if (!tmp_nets[i]) { - virReportOOMError(); + if (!tmp_nets[i]) goto cleanup; - } } *nets = tmp_nets; tmp_nets = NULL; @@ -2913,17 +2896,13 @@ remoteConnectListAllInterfaces(virConnectPtr conn, goto done; if (ifaces) { - if (VIR_ALLOC_N(tmp_ifaces, ret.ifaces.ifaces_len + 1) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(tmp_ifaces, ret.ifaces.ifaces_len + 1) < 0) goto cleanup; - } for (i = 0; i < ret.ifaces.ifaces_len; i++) { tmp_ifaces[i] = get_nonnull_interface(conn, ret.ifaces.ifaces_val[i]); - if (!tmp_ifaces[i]) { - virReportOOMError(); + if (!tmp_ifaces[i]) goto cleanup; - } } *ifaces = tmp_ifaces; tmp_ifaces = NULL; @@ -2976,17 +2955,13 @@ remoteConnectListAllNodeDevices(virConnectPtr conn, goto done; if (devices) { - if (VIR_ALLOC_N(tmp_devices, ret.devices.devices_len + 1) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(tmp_devices, ret.devices.devices_len + 1) < 0) goto cleanup; - } for (i = 0; i < ret.devices.devices_len; i++) { tmp_devices[i] = get_nonnull_node_device(conn, ret.devices.devices_val[i]); - if (!tmp_devices[i]) { - virReportOOMError(); + if (!tmp_devices[i]) goto cleanup; - } } *devices = tmp_devices; tmp_devices = NULL; @@ -3039,17 +3014,13 @@ remoteConnectListAllNWFilters(virConnectPtr conn, goto done; if (filters) { - if (VIR_ALLOC_N(tmp_filters, ret.filters.filters_len + 1) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(tmp_filters, ret.filters.filters_len + 1) < 0) goto cleanup; - } for (i = 0; i < ret.filters.filters_len; i++) { tmp_filters[i] = get_nonnull_nwfilter(conn, ret.filters.filters_val[i]); - if (!tmp_filters[i]) { - virReportOOMError(); + if (!tmp_filters[i]) goto cleanup; - } } *filters = tmp_filters; tmp_filters = NULL; @@ -3102,17 +3073,13 @@ remoteConnectListAllSecrets(virConnectPtr conn, goto done; if (secrets) { - if (VIR_ALLOC_N(tmp_secrets, ret.secrets.secrets_len + 1) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(tmp_secrets, ret.secrets.secrets_len + 1) < 0) goto cleanup; - } for (i = 0; i < ret.secrets.secrets_len; i++) { tmp_secrets[i] = get_nonnull_secret(conn, ret.secrets.secrets_val[i]); - if (!tmp_secrets[i]) { - virReportOOMError(); + if (!tmp_secrets[i]) goto cleanup; - } } *secrets = tmp_secrets; tmp_secrets = NULL; @@ -3303,17 +3270,13 @@ remoteConnectListAllStoragePools(virConnectPtr conn, goto done; if (pools) { - if (VIR_ALLOC_N(tmp_pools, ret.pools.pools_len + 1) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(tmp_pools, ret.pools.pools_len + 1) < 0) goto cleanup; - } for (i = 0; i < ret.pools.pools_len; i++) { tmp_pools[i] = get_nonnull_storage_pool(conn, ret.pools.pools_val[i]); - if (!tmp_pools[i]) { - virReportOOMError(); + if (!tmp_pools[i]) goto cleanup; - } } *pools = tmp_pools; tmp_pools = NULL; @@ -3367,17 +3330,13 @@ remoteStoragePoolListAllVolumes(virStoragePoolPtr pool, goto done; if (vols) { - if (VIR_ALLOC_N(tmp_vols, ret.vols.vols_len + 1) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(tmp_vols, ret.vols.vols_len + 1) < 0) goto cleanup; - } for (i = 0; i < ret.vols.vols_len; i++) { tmp_vols[i] = get_nonnull_storage_vol(pool->conn, ret.vols.vols_val[i]); - if (!tmp_vols[i]) { - virReportOOMError(); + if (!tmp_vols[i]) goto cleanup; - } } *vols = tmp_vols; tmp_vols = NULL; @@ -4881,10 +4840,8 @@ remoteStreamEventAddCallback(virStreamPtr st, int ret = -1; struct remoteStreamCallbackData *cbdata; - if (VIR_ALLOC(cbdata) < 0) { - virReportOOMError(); + if (VIR_ALLOC(cbdata) < 0) return -1; - } cbdata->cb = cb; cbdata->opaque = opaque; cbdata->ff = ff; @@ -5778,16 +5735,12 @@ remoteDomainListAllSnapshots(virDomainPtr dom, goto done; if (snapshots) { - if (VIR_ALLOC_N(snaps, ret.snapshots.snapshots_len + 1) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(snaps, ret.snapshots.snapshots_len + 1) < 0) goto cleanup; - } for (i = 0; i < ret.snapshots.snapshots_len; i++) { snaps[i] = get_nonnull_domain_snapshot(dom, ret.snapshots.snapshots_val[i]); - if (!snaps[i]) { - virReportOOMError(); + if (!snaps[i]) goto cleanup; - } } *snapshots = snaps; snaps = NULL; @@ -5841,16 +5794,12 @@ remoteDomainSnapshotListAllChildren(virDomainSnapshotPtr parent, goto done; if (snapshots) { - if (VIR_ALLOC_N(snaps, ret.snapshots.snapshots_len + 1) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(snaps, ret.snapshots.snapshots_len + 1) < 0) goto cleanup; - } for (i = 0; i < ret.snapshots.snapshots_len; i++) { snaps[i] = get_nonnull_domain_snapshot(parent->domain, ret.snapshots.snapshots_val[i]); - if (!snaps[i]) { - virReportOOMError(); + if (!snaps[i]) goto cleanup; - } } *snapshots = snaps; snaps = NULL; @@ -5950,10 +5899,8 @@ remoteNodeGetCPUMap(virConnectPtr conn, goto cleanup; if (cpumap) { - if (VIR_ALLOC_N(*cpumap, ret.cpumap.cpumap_len) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(*cpumap, ret.cpumap.cpumap_len) < 0) goto cleanup; - } memcpy(*cpumap, ret.cpumap.cpumap_val, ret.cpumap.cpumap_len); } -- 1.8.1.5

On 07/04/2013 02:06 PM, Michal Privoznik wrote:
--- src/remote/remote_driver.c | 107 ++++++++++++--------------------------------- 1 file changed, 27 insertions(+), 80 deletions(-)
ACK Jan

--- src/rpc/gendispatch.pl | 8 ++------ src/rpc/virnetclient.c | 26 ++++++++------------------ src/rpc/virnetclientprogram.c | 12 +++--------- src/rpc/virnetclientstream.c | 4 +--- src/rpc/virnetmessage.c | 24 ++++++------------------ src/rpc/virnetserver.c | 23 +++++++---------------- src/rpc/virnetserverclient.c | 19 ++++--------------- src/rpc/virnetservermdns.c | 20 +++++--------------- src/rpc/virnetserverprogram.c | 8 ++------ src/rpc/virnetserverservice.c | 12 +++--------- src/rpc/virnetsocket.c | 8 ++------ src/rpc/virnetsshsession.c | 21 +++++---------------- src/rpc/virnettlscontext.c | 26 +++++++++++--------------- 13 files changed, 59 insertions(+), 152 deletions(-) diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl index fdf5a79..de2d82c 100755 --- a/src/rpc/gendispatch.pl +++ b/src/rpc/gendispatch.pl @@ -661,10 +661,8 @@ elsif ($mode eq "server") { push(@free_list, " VIR_FREE($1);"); push(@free_list_on_error, "VIR_FREE($1_p);"); push(@prepare_ret_list, - "if (VIR_ALLOC($1_p) < 0) {\n" . - " virReportOOMError();\n" . + "if (VIR_ALLOC($1_p) < 0)\n" . " goto cleanup;\n" . - " }\n" . " \n" . " if (VIR_STRDUP(*$1_p, $1) < 0)\n". " goto cleanup;\n"); @@ -932,10 +930,8 @@ elsif ($mode eq "server") { if ($single_ret_as_list) { print " /* Allocate return buffer. */\n"; print " if (VIR_ALLOC_N(ret->$single_ret_list_name.${single_ret_list_name}_val," . - " args->$single_ret_list_max_var) < 0) {\n"; - print " virReportOOMError();\n"; + " args->$single_ret_list_max_var) < 0)\n"; print " goto cleanup;\n"; - print " }\n"; print "\n"; } diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c index fed2c87..bc282f8 100644 --- a/src/rpc/virnetclient.c +++ b/src/rpc/virnetclient.c @@ -875,15 +875,14 @@ int virNetClientAddProgram(virNetClientPtr client, virObjectLock(client); if (VIR_EXPAND_N(client->programs, client->nprograms, 1) < 0) - goto no_memory; + goto error; client->programs[client->nprograms-1] = virObjectRef(prog); virObjectUnlock(client); return 0; -no_memory: - virReportOOMError(); +error: virObjectUnlock(client); return -1; } @@ -895,15 +894,14 @@ int virNetClientAddStream(virNetClientPtr client, virObjectLock(client); if (VIR_EXPAND_N(client->streams, client->nstreams, 1) < 0) - goto no_memory; + goto error; client->streams[client->nstreams-1] = virObjectRef(st); virObjectUnlock(client); return 0; -no_memory: - virReportOOMError(); +error: virObjectUnlock(client); return -1; } @@ -981,10 +979,8 @@ virNetClientCallDispatchReply(virNetClientPtr client) return -1; } - if (VIR_REALLOC_N(thecall->msg->buffer, client->msg.bufferLength) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(thecall->msg->buffer, client->msg.bufferLength) < 0) return -1; - } memcpy(thecall->msg->buffer, client->msg.buffer, client->msg.bufferLength); memcpy(&thecall->msg->header, &client->msg.header, sizeof(client->msg.header)); @@ -1233,10 +1229,8 @@ virNetClientIOReadMessage(virNetClientPtr client) /* Start by reading length word */ if (client->msg.bufferLength == 0) { client->msg.bufferLength = 4; - if (VIR_ALLOC_N(client->msg.buffer, client->msg.bufferLength) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(client->msg.buffer, client->msg.bufferLength) < 0) return -ENOMEM; - } } wantData = client->msg.bufferLength - client->msg.bufferOffset; @@ -1888,10 +1882,8 @@ virNetClientCallNew(virNetMessagePtr msg, goto error; } - if (VIR_ALLOC(call) < 0) { - virReportOOMError(); + if (VIR_ALLOC(call) < 0) goto error; - } if (virCondInit(&call->cond) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -1964,10 +1956,8 @@ static int virNetClientSendInternal(virNetClientPtr client, return -1; } - if (!(call = virNetClientCallNew(msg, expectReply, nonBlock))) { - virReportOOMError(); + if (!(call = virNetClientCallNew(msg, expectReply, nonBlock))) return -1; - } call->haveThread = true; ret = virNetClientIO(client, call); diff --git a/src/rpc/virnetclientprogram.c b/src/rpc/virnetclientprogram.c index 1016f55..1c4e4ba 100644 --- a/src/rpc/virnetclientprogram.c +++ b/src/rpc/virnetclientprogram.c @@ -250,10 +250,8 @@ int virNetClientProgramDispatch(virNetClientProgramPtr prog, return -1; } - if (VIR_ALLOC_N(evdata, event->msg_len) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(evdata, event->msg_len) < 0) return -1; - } if (virNetMessageDecodePayload(msg, event->msg_filter, evdata) < 0) goto cleanup; @@ -297,10 +295,8 @@ int virNetClientProgramCall(virNetClientProgramPtr prog, msg->header.serial = serial; msg->header.proc = proc; msg->nfds = noutfds; - if (VIR_ALLOC_N(msg->fds, msg->nfds) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(msg->fds, msg->nfds) < 0) goto error; - } for (i = 0; i < msg->nfds; i++) msg->fds[i] = -1; for (i = 0; i < msg->nfds; i++) { @@ -358,10 +354,8 @@ int virNetClientProgramCall(virNetClientProgramPtr prog, case VIR_NET_OK: if (infds && ninfds) { *ninfds = msg->nfds; - if (VIR_ALLOC_N(*infds, *ninfds) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(*infds, *ninfds) < 0) goto error; - } for (i = 0; i < *ninfds; i++) (*infds)[i] = -1; for (i = 0; i < *ninfds; i++) { diff --git a/src/rpc/virnetclientstream.c b/src/rpc/virnetclientstream.c index b8c457e..b785392 100644 --- a/src/rpc/virnetclientstream.c +++ b/src/rpc/virnetclientstream.c @@ -373,10 +373,8 @@ int virNetClientStreamRecvPacket(virNetClientStreamPtr st, goto cleanup; } - if (!(msg = virNetMessageNew(false))) { - virReportOOMError(); + if (!(msg = virNetMessageNew(false))) goto cleanup; - } msg->header.prog = virNetClientProgramGetProgram(st->prog); msg->header.vers = virNetClientProgramGetVersion(st->prog); diff --git a/src/rpc/virnetmessage.c b/src/rpc/virnetmessage.c index f27a236..0424276 100644 --- a/src/rpc/virnetmessage.c +++ b/src/rpc/virnetmessage.c @@ -37,10 +37,8 @@ virNetMessagePtr virNetMessageNew(bool tracked) { virNetMessagePtr msg; - if (VIR_ALLOC(msg) < 0) { - virReportOOMError(); + if (VIR_ALLOC(msg) < 0) return NULL; - } msg->tracked = tracked; VIR_DEBUG("msg=%p tracked=%d", msg, tracked); @@ -144,10 +142,8 @@ int virNetMessageDecodeLength(virNetMessagePtr msg) /* Extend our declared buffer length and carry on reading the header + payload */ msg->bufferLength += len; - if (VIR_REALLOC_N(msg->buffer, msg->bufferLength) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(msg->buffer, msg->bufferLength) < 0) goto cleanup; - } VIR_DEBUG("Got length, now need %zu total (%u more)", msg->bufferLength, len); @@ -223,10 +219,8 @@ int virNetMessageEncodeHeader(virNetMessagePtr msg) unsigned int len = 0; msg->bufferLength = VIR_NET_MESSAGE_INITIAL + VIR_NET_MESSAGE_LEN_MAX; - if (VIR_REALLOC_N(msg->buffer, msg->bufferLength) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(msg->buffer, msg->bufferLength) < 0) return ret; - } msg->bufferOffset = 0; /* Format the header. */ @@ -322,10 +316,8 @@ int virNetMessageDecodeNumFDs(virNetMessagePtr msg) } msg->nfds = numFDs; - if (VIR_ALLOC_N(msg->fds, msg->nfds) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(msg->fds, msg->nfds) < 0) goto cleanup; - } for (i = 0; i < msg->nfds; i++) msg->fds[i] = -1; @@ -364,10 +356,8 @@ int virNetMessageEncodePayload(virNetMessagePtr msg, msg->bufferLength = (msg->bufferLength - VIR_NET_MESSAGE_LEN_MAX) * 4 + VIR_NET_MESSAGE_LEN_MAX; - if (VIR_REALLOC_N(msg->buffer, msg->bufferLength) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(msg->buffer, msg->bufferLength) < 0) goto error; - } xdrmem_create(&xdr, msg->buffer + msg->bufferOffset, msg->bufferLength - msg->bufferOffset, XDR_ENCODE); @@ -445,10 +435,8 @@ int virNetMessageEncodePayloadRaw(virNetMessagePtr msg, msg->bufferLength = msg->bufferOffset + len; - if (VIR_REALLOC_N(msg->buffer, msg->bufferLength) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(msg->buffer, msg->bufferLength) < 0) return -1; - } VIR_DEBUG("Increased message buffer length = %zu", msg->bufferLength); } diff --git a/src/rpc/virnetserver.c b/src/rpc/virnetserver.c index 9f56b03..c8b0ba4 100644 --- a/src/rpc/virnetserver.c +++ b/src/rpc/virnetserver.c @@ -221,10 +221,8 @@ static int virNetServerDispatchNewMessage(virNetServerClientPtr client, if (srv->workers) { virNetServerJobPtr job; - if (VIR_ALLOC(job) < 0) { - virReportOOMError(); + if (VIR_ALLOC(job) < 0) goto cleanup; - } job->client = client; job->msg = msg; @@ -267,10 +265,8 @@ static int virNetServerAddClient(virNetServerPtr srv, if (virNetServerClientInit(client) < 0) goto error; - if (VIR_EXPAND_N(srv->clients, srv->nclients, 1) < 0) { - virReportOOMError(); + if (VIR_EXPAND_N(srv->clients, srv->nclients, 1) < 0) goto error; - } srv->clients[srv->nclients-1] = client; virObjectRef(client); @@ -933,10 +929,10 @@ int virNetServerAddSignalHandler(virNetServerPtr srv, goto error; if (VIR_EXPAND_N(srv->signals, srv->nsignals, 1) < 0) - goto no_memory; + goto error; if (VIR_ALLOC(sigdata) < 0) - goto no_memory; + goto error; sigdata->signum = signum; sigdata->func = func; @@ -954,8 +950,6 @@ int virNetServerAddSignalHandler(virNetServerPtr srv, virObjectUnlock(srv); return 0; -no_memory: - virReportOOMError(); error: VIR_FREE(sigdata); virObjectUnlock(srv); @@ -971,7 +965,7 @@ int virNetServerAddService(virNetServerPtr srv, virObjectLock(srv); if (VIR_EXPAND_N(srv->services, srv->nservices, 1) < 0) - goto no_memory; + goto error; if (mdnsEntryName) { int port = virNetServerServiceGetPort(svc); @@ -992,8 +986,6 @@ int virNetServerAddService(virNetServerPtr srv, virObjectUnlock(srv); return 0; -no_memory: - virReportOOMError(); error: virObjectUnlock(srv); return -1; @@ -1005,15 +997,14 @@ int virNetServerAddProgram(virNetServerPtr srv, virObjectLock(srv); if (VIR_EXPAND_N(srv->programs, srv->nprograms, 1) < 0) - goto no_memory; + goto error; srv->programs[srv->nprograms-1] = virObjectRef(prog); virObjectUnlock(srv); return 0; -no_memory: - virReportOOMError(); +error: virObjectUnlock(srv); return -1; } diff --git a/src/rpc/virnetserverclient.c b/src/rpc/virnetserverclient.c index 2fc4838..83d5cf1 100644 --- a/src/rpc/virnetserverclient.c +++ b/src/rpc/virnetserverclient.c @@ -241,10 +241,8 @@ int virNetServerClientAddFilter(virNetServerClientPtr client, virNetServerClientFilterPtr *place; int ret; - if (VIR_ALLOC(filter) < 0) { - virReportOOMError(); + if (VIR_ALLOC(filter) < 0) return -1; - } virObjectLock(client); @@ -316,7 +314,6 @@ virNetServerClientCheckAccess(virNetServerClientPtr client) */ confirm->bufferLength = 1; if (VIR_ALLOC_N(confirm->buffer, confirm->bufferLength) < 0) { - virReportOOMError(); virNetMessageFree(confirm); return -1; } @@ -378,10 +375,8 @@ virNetServerClientNewInternal(virNetSocketPtr sock, if (!(client->rx = virNetMessageNew(true))) goto error; client->rx->bufferLength = VIR_NET_MESSAGE_LEN_MAX; - if (VIR_ALLOC_N(client->rx->buffer, client->rx->bufferLength) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(client->rx->buffer, client->rx->bufferLength) < 0) goto error; - } client->nrequests = 1; PROBE(RPC_SERVER_CLIENT_NEW, @@ -680,15 +675,11 @@ virNetServerClientCreateIdentity(virNetServerClientPtr client) if (!(groupname = virGetGroupName(gid))) goto cleanup; if (virAsprintf(&processid, "%llu", - (unsigned long long)pid) < 0) { - virReportOOMError(); + (unsigned long long)pid) < 0) goto cleanup; - } if (virAsprintf(&processtime, "%llu", - timestamp) < 0) { - virReportOOMError(); + timestamp) < 0) goto cleanup; - } } #if WITH_SASL @@ -1243,7 +1234,6 @@ readmore: client->rx->bufferLength = VIR_NET_MESSAGE_LEN_MAX; if (VIR_ALLOC_N(client->rx->buffer, client->rx->bufferLength) < 0) { - virReportOOMError(); client->wantClose = true; } else { client->nrequests++; @@ -1346,7 +1336,6 @@ virNetServerClientDispatchWrite(virNetServerClientPtr client) virNetMessageClear(msg); msg->bufferLength = VIR_NET_MESSAGE_LEN_MAX; if (VIR_ALLOC_N(msg->buffer, msg->bufferLength) < 0) { - virReportOOMError(); virNetMessageFree(msg); return; } diff --git a/src/rpc/virnetservermdns.c b/src/rpc/virnetservermdns.c index 4b3c19a..85ae100 100644 --- a/src/rpc/virnetservermdns.c +++ b/src/rpc/virnetservermdns.c @@ -273,10 +273,8 @@ static AvahiWatch *virNetServerMDNSWatchNew(const AvahiPoll *api ATTRIBUTE_UNUSE { AvahiWatch *w; virEventHandleType hEvents; - if (VIR_ALLOC(w) < 0) { - virReportOOMError(); + if (VIR_ALLOC(w) < 0) return NULL; - } w->fd = fd; w->revents = 0; @@ -338,10 +336,8 @@ static AvahiTimeout *virNetServerMDNSTimeoutNew(const AvahiPoll *api ATTRIBUTE_U struct timeval now; long long nowms, thenms, timeout; VIR_DEBUG("Add timeout TV %p", tv); - if (VIR_ALLOC(t) < 0) { - virReportOOMError(); + if (VIR_ALLOC(t) < 0) return NULL; - } if (gettimeofday(&now, NULL) < 0) { virReportSystemError(errno, "%s", @@ -413,10 +409,8 @@ static void virNetServerMDNSTimeoutFree(AvahiTimeout *t) static AvahiPoll *virNetServerMDNSCreatePoll(void) { AvahiPoll *p; - if (VIR_ALLOC(p) < 0) { - virReportOOMError(); + if (VIR_ALLOC(p) < 0) return NULL; - } p->userdata = NULL; @@ -475,10 +469,8 @@ virNetServerMDNSGroupPtr virNetServerMDNSAddGroup(virNetServerMDNS *mdns, virNetServerMDNSGroupPtr group; VIR_DEBUG("Adding group '%s'", name); - if (VIR_ALLOC(group) < 0) { - virReportOOMError(); + if (VIR_ALLOC(group) < 0) return NULL; - } if (VIR_STRDUP(group->name, name) < 0) { VIR_FREE(group); @@ -519,10 +511,8 @@ virNetServerMDNSEntryPtr virNetServerMDNSAddEntry(virNetServerMDNSGroupPtr group virNetServerMDNSEntryPtr entry; VIR_DEBUG("Adding entry %s %d to group %s", type, port, group->name); - if (VIR_ALLOC(entry) < 0) { - virReportOOMError(); + if (VIR_ALLOC(entry) < 0) return NULL; - } entry->port = port; if (VIR_STRDUP(entry->type, type) < 0) { diff --git a/src/rpc/virnetserverprogram.c b/src/rpc/virnetserverprogram.c index 09d4d21..93a3fb1 100644 --- a/src/rpc/virnetserverprogram.c +++ b/src/rpc/virnetserverprogram.c @@ -408,14 +408,10 @@ virNetServerProgramDispatchCall(virNetServerProgramPtr prog, goto error; } - if (VIR_ALLOC_N(arg, dispatcher->arg_len) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(arg, dispatcher->arg_len) < 0) goto error; - } - if (VIR_ALLOC_N(ret, dispatcher->ret_len) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(ret, dispatcher->ret_len) < 0) goto error; - } if (virNetMessageDecodePayload(msg, dispatcher->arg_filter, arg) < 0) goto error; diff --git a/src/rpc/virnetserverservice.c b/src/rpc/virnetserverservice.c index baf0ebe..53f78ab 100644 --- a/src/rpc/virnetserverservice.c +++ b/src/rpc/virnetserverservice.c @@ -175,7 +175,7 @@ virNetServerServicePtr virNetServerServiceNewUNIX(const char *path, svc->nsocks = 1; if (VIR_ALLOC_N(svc->socks, svc->nsocks) < 0) - goto no_memory; + goto error; if (virNetSocketNewListenUNIX(path, mask, @@ -204,8 +204,6 @@ virNetServerServicePtr virNetServerServiceNewUNIX(const char *path, return svc; -no_memory: - virReportOOMError(); error: virObjectUnref(svc); return NULL; @@ -237,7 +235,7 @@ virNetServerServicePtr virNetServerServiceNewFD(int fd, svc->nsocks = 1; if (VIR_ALLOC_N(svc->socks, svc->nsocks) < 0) - goto no_memory; + goto error; if (virNetSocketNewListenFD(fd, &svc->socks[0]) < 0) @@ -257,8 +255,6 @@ virNetServerServicePtr virNetServerServiceNewFD(int fd, return svc; -no_memory: - virReportOOMError(); error: virObjectUnref(svc); return NULL; @@ -310,10 +306,8 @@ virNetServerServicePtr virNetServerServiceNewPostExecRestart(virJSONValuePtr obj } svc->nsocks = n; - if (VIR_ALLOC_N(svc->socks, svc->nsocks) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(svc->socks, svc->nsocks) < 0) goto error; - } for (i = 0; i < svc->nsocks; i++) { virJSONValuePtr child = virJSONValueArrayGet(socks, i); diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c index 27709d8..45dd8b4 100644 --- a/src/rpc/virnetsocket.c +++ b/src/rpc/virnetsocket.c @@ -297,10 +297,8 @@ int virNetSocketNewListenTCP(const char *nodename, VIR_DEBUG("%p f=%d f=%d", &addr, runp->ai_family, addr.data.sa.sa_family); - if (VIR_EXPAND_N(socks, nsocks, 1) < 0) { - virReportOOMError(); + if (VIR_EXPAND_N(socks, nsocks, 1) < 0) goto error; - } if (!(socks[nsocks-1] = virNetSocketNew(&addr, NULL, false, fd, -1, 0))) goto error; @@ -1435,10 +1433,8 @@ static ssize_t virNetSocketReadSASL(virNetSocketPtr sock, char *buf, size_t len) if (sock->saslDecoded == NULL) { ssize_t encodedLen = virNetSASLSessionGetMaxBufSize(sock->saslSession); char *encoded; - if (VIR_ALLOC_N(encoded, encodedLen) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(encoded, encodedLen) < 0) return -1; - } encodedLen = virNetSocketReadWire(sock, encoded, encodedLen); if (encodedLen <= 0) { diff --git a/src/rpc/virnetsshsession.c b/src/rpc/virnetsshsession.c index b6aedc8..77b5c88 100644 --- a/src/rpc/virnetsshsession.c +++ b/src/rpc/virnetsshsession.c @@ -378,7 +378,6 @@ virNetSSHCheckHostKey(virNetSSHSessionPtr sess) keyhash, sess->hostname, sess->port, "y", "n") < 0) { - virReportOOMError(); VIR_FREE(keyhash); return -1; } @@ -635,10 +634,8 @@ virNetSSHAuthenticatePrivkey(virNetSSHSessionPtr sess, if (virAsprintf((char **)&retr_passphrase.prompt, _("Passphrase for key '%s'"), - priv->filename) < 0) { - virReportOOMError(); + priv->filename) < 0) return -1; - } if (sess->cred->cb(&retr_passphrase, 1, sess->cred->cbdata)) { virReportError(VIR_ERR_SSH, "%s", @@ -966,10 +963,8 @@ virNetSSHSessionAuthAddPasswordAuth(virNetSSHSessionPtr sess, VIR_STRDUP(pass, password) < 0) goto error; - if (!(auth = virNetSSHSessionAuthMethodNew(sess))) { - virReportOOMError(); + if (!(auth = virNetSSHSessionAuthMethodNew(sess))) goto error; - } auth->username = user; auth->password = pass; @@ -1004,10 +999,8 @@ virNetSSHSessionAuthAddAgentAuth(virNetSSHSessionPtr sess, if (VIR_STRDUP(user, username) < 0) goto error; - if (!(auth = virNetSSHSessionAuthMethodNew(sess))) { - virReportOOMError(); + if (!(auth = virNetSSHSessionAuthMethodNew(sess))) goto error; - } auth->username = user; auth->method = VIR_NET_SSH_AUTH_AGENT; @@ -1047,10 +1040,8 @@ virNetSSHSessionAuthAddPrivKeyAuth(virNetSSHSessionPtr sess, VIR_STRDUP(pass, password) < 0) goto error; - if (!(auth = virNetSSHSessionAuthMethodNew(sess))) { - virReportOOMError(); + if (!(auth = virNetSSHSessionAuthMethodNew(sess))) goto error; - } auth->username = user; auth->password = pass; @@ -1088,10 +1079,8 @@ virNetSSHSessionAuthAddKeyboardAuth(virNetSSHSessionPtr sess, if (VIR_STRDUP(user, username) < 0) goto error; - if (!(auth = virNetSSHSessionAuthMethodNew(sess))) { - virReportOOMError(); + if (!(auth = virNetSSHSessionAuthMethodNew(sess))) goto error; - } auth->username = user; auth->tries = tries; diff --git a/src/rpc/virnettlscontext.c b/src/rpc/virnettlscontext.c index 9b43a80..482c860 100644 --- a/src/rpc/virnettlscontext.c +++ b/src/rpc/virnettlscontext.c @@ -314,10 +314,8 @@ static int virNetTLSContextCheckCertKeyPurpose(gnutls_x509_crt_t cert, return -1; } - if (VIR_ALLOC_N(buffer, size) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(buffer, size) < 0) return -1; - } status = gnutls_x509_crt_get_key_purpose_oid(cert, i, buffer, &size, &purposeCritical); if (status < 0) { @@ -776,17 +774,17 @@ static int virNetTLSContextLocateCredentials(const char *pkipath, VIR_DEBUG("Told to use TLS credentials in %s", pkipath); if ((virAsprintf(cacert, "%s/%s", pkipath, "cacert.pem")) < 0) - goto out_of_memory; + goto error; if ((virAsprintf(cacrl, "%s/%s", pkipath, "cacrl.pem")) < 0) - goto out_of_memory; + goto error; if ((virAsprintf(key, "%s/%s", pkipath, isServer ? "serverkey.pem" : "clientkey.pem")) < 0) - goto out_of_memory; + goto error; if ((virAsprintf(cert, "%s/%s", pkipath, isServer ? "servercert.pem" : "clientcert.pem")) < 0) - goto out_of_memory; + goto error; } else if (tryUserPkiPath) { /* Check to see if $HOME/.pki contains at least one of the * files and if so, use that @@ -794,28 +792,28 @@ static int virNetTLSContextLocateCredentials(const char *pkipath, userdir = virGetUserDirectory(); if (!userdir) - goto out_of_memory; + goto error; if (virAsprintf(&user_pki_path, "%s/.pki/libvirt", userdir) < 0) - goto out_of_memory; + goto error; VIR_DEBUG("Trying to find TLS user credentials in %s", user_pki_path); if ((virAsprintf(cacert, "%s/%s", user_pki_path, "cacert.pem")) < 0) - goto out_of_memory; + goto error; if ((virAsprintf(cacrl, "%s/%s", user_pki_path, "cacrl.pem")) < 0) - goto out_of_memory; + goto error; if ((virAsprintf(key, "%s/%s", user_pki_path, isServer ? "serverkey.pem" : "clientkey.pem")) < 0) - goto out_of_memory; + goto error; if ((virAsprintf(cert, "%s/%s", user_pki_path, isServer ? "servercert.pem" : "clientcert.pem")) < 0) - goto out_of_memory; + goto error; /* * If some of the files can't be found, fallback @@ -864,8 +862,6 @@ static int virNetTLSContextLocateCredentials(const char *pkipath, return 0; -out_of_memory: - virReportOOMError(); error: VIR_FREE(*cacert); VIR_FREE(*cacrl); -- 1.8.1.5

On 07/04/2013 02:06 PM, Michal Privoznik wrote:
--- src/rpc/gendispatch.pl | 8 ++------ src/rpc/virnetclient.c | 26 ++++++++------------------ src/rpc/virnetclientprogram.c | 12 +++--------- src/rpc/virnetclientstream.c | 4 +--- src/rpc/virnetmessage.c | 24 ++++++------------------ src/rpc/virnetserver.c | 23 +++++++---------------- src/rpc/virnetserverclient.c | 19 ++++--------------- src/rpc/virnetservermdns.c | 20 +++++--------------- src/rpc/virnetserverprogram.c | 8 ++------ src/rpc/virnetserverservice.c | 12 +++--------- src/rpc/virnetsocket.c | 8 ++------ src/rpc/virnetsshsession.c | 21 +++++---------------- src/rpc/virnettlscontext.c | 26 +++++++++++--------------- 13 files changed, 59 insertions(+), 152 deletions(-)
In src/rpc/virnetmessage.c:492: void virNetMessageSaveError(virNetMessageErrorPtr rerr) you should use VIR_ALLOC_QUIET to avoid overwriting the error message. ACK Jan

--- src/secret/secret_driver.c | 49 ++++++++++++---------------------------------- 1 file changed, 12 insertions(+), 37 deletions(-) diff --git a/src/secret/secret_driver.c b/src/secret/secret_driver.c index 71b3fe7..dc8714d 100644 --- a/src/secret/secret_driver.c +++ b/src/secret/secret_driver.c @@ -173,10 +173,8 @@ replaceFile(const char *filename, void *data, size_t size) char *tmp_path = NULL; int fd = -1, ret = -1; - if (virAsprintf(&tmp_path, "%sXXXXXX", filename) < 0) { - virReportOOMError(); + if (virAsprintf(&tmp_path, "%sXXXXXX", filename) < 0) goto cleanup; - } fd = mkostemp(tmp_path, O_CLOEXEC); if (fd == -1) { virReportSystemError(errno, _("mkostemp('%s') failed"), tmp_path); @@ -225,10 +223,7 @@ secretComputePath(virSecretDriverStatePtr driver, virUUIDFormat(secret->def->uuid, uuidstr); - if (virAsprintf(&ret, "%s/%s%s", driver->directory, uuidstr, suffix) < 0) - /* ret is NULL */ - virReportOOMError(); - + ignore_value(virAsprintf(&ret, "%s/%s%s", driver->directory, uuidstr, suffix)); return ret; } @@ -397,10 +392,8 @@ secretLoadValue(virSecretDriverStatePtr driver, goto cleanup; } - if (VIR_ALLOC_N(contents, st.st_size) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(contents, st.st_size) < 0) goto cleanup; - } if (saferead(fd, contents, st.st_size) != st.st_size) { virReportSystemError(errno, _("cannot read '%s'"), filename); goto cleanup; @@ -412,10 +405,8 @@ secretLoadValue(virSecretDriverStatePtr driver, _("invalid base64 in '%s'"), filename); goto cleanup; } - if (value == NULL) { - virReportOOMError(); + if (value == NULL) goto cleanup; - } secret->value = (unsigned char *)value; value = NULL; @@ -446,10 +437,8 @@ secretLoad(virSecretDriverStatePtr driver, char *xml_filename; if (virAsprintf(&xml_filename, "%s/%s", driver->directory, - xml_basename) < 0) { - virReportOOMError(); + xml_basename) < 0) goto cleanup; - } def = virSecretDefParseFile(xml_filename); if (def == NULL) goto cleanup; @@ -458,10 +447,8 @@ secretLoad(virSecretDriverStatePtr driver, if (secretLoadValidateUUID(def, xml_basename) < 0) goto cleanup; - if (VIR_ALLOC(secret) < 0) { - virReportOOMError(); + if (VIR_ALLOC(secret) < 0) goto cleanup; - } secret->def = def; def = NULL; @@ -598,10 +585,8 @@ secretConnectListSecrets(virConnectPtr conn, char **uuids, int maxuuids) continue; if (i == maxuuids) break; - if (VIR_ALLOC_N(uuidstr, VIR_UUID_STRING_BUFLEN) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(uuidstr, VIR_UUID_STRING_BUFLEN) < 0) goto cleanup; - } virUUIDFormat(secret->def->uuid, uuidstr); uuids[i] = uuidstr; i++; @@ -664,12 +649,8 @@ secretConnectListAllSecrets(virConnectPtr conn, for (entry = driver->secrets; entry != NULL; entry = entry->next) nsecrets++; - if (secrets) { - if (VIR_ALLOC_N(tmp_secrets, nsecrets + 1) < 0) { - virReportOOMError(); - goto cleanup; - } - } + if (secrets && VIR_ALLOC_N(tmp_secrets, nsecrets + 1) < 0) + goto cleanup; for (entry = driver->secrets; entry != NULL; entry = entry->next) { if (!virConnectListAllSecretsCheckACL(conn, @@ -825,10 +806,8 @@ secretDefineXML(virConnectPtr conn, const char *xml, } /* No existing secret at all, create one */ - if (VIR_ALLOC(secret) < 0) { - virReportOOMError(); + if (VIR_ALLOC(secret) < 0) goto cleanup; - } listInsert(&driver->secrets, secret); secret->def = new_attrs; @@ -949,10 +928,8 @@ secretSetValue(virSecretPtr obj, const unsigned char *value, virCheckFlags(0, -1); - if (VIR_ALLOC_N(new_value, value_size) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(new_value, value_size) < 0) return -1; - } secretDriverLock(driver); @@ -1041,10 +1018,8 @@ secretGetValue(virSecretPtr obj, size_t *value_size, unsigned int flags, goto cleanup; } - if (VIR_ALLOC_N(ret, secret->value_size) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(ret, secret->value_size) < 0) goto cleanup; - } memcpy(ret, secret->value, secret->value_size); *value_size = secret->value_size; -- 1.8.1.5

On 07/04/2013 02:06 PM, Michal Privoznik wrote:
--- src/secret/secret_driver.c | 49 ++++++++++++---------------------------------- 1 file changed, 12 insertions(+), 37 deletions(-)
ACK Jan

On 07/08/2013 09:34 AM, Ján Tomko wrote:
On 07/04/2013 02:06 PM, Michal Privoznik wrote:
--- src/secret/secret_driver.c | 49 ++++++++++++---------------------------------- 1 file changed, 12 insertions(+), 37 deletions(-)
ACK
Jan
You can also get rid of the out_of_memory label (and the double OOM error reporting) in secretStateInitialize. Jan

--- src/security/security_apparmor.c | 25 ++++++------------------ src/security/security_dac.c | 12 +++--------- src/security/security_manager.c | 8 ++------ src/security/security_selinux.c | 41 ++++++++++++---------------------------- src/security/security_stack.c | 8 ++------ 5 files changed, 25 insertions(+), 69 deletions(-) diff --git a/src/security/security_apparmor.c b/src/security/security_apparmor.c index 50b0e74..eb80d23 100644 --- a/src/security/security_apparmor.c +++ b/src/security/security_apparmor.c @@ -77,16 +77,13 @@ profile_status(const char *str, const int check_enforcing) int rc = -1; /* create string that is '<str> \0' for accurate matching */ - if (virAsprintf(&tmp, "%s ", str) == -1) { - virReportOOMError(); + if (virAsprintf(&tmp, "%s ", str) == -1) return rc; - } if (check_enforcing != 0) { /* create string that is '<str> (enforce)\0' for accurate matching */ if (virAsprintf(&etmp, "%s (enforce)", str) == -1) { VIR_FREE(tmp); - virReportOOMError(); return rc; } } @@ -132,10 +129,8 @@ profile_status_file(const char *str) int rc = -1; int len; - if (virAsprintf(&profile, "%s/%s", APPARMOR_DIR "/libvirt", str) == -1) { - virReportOOMError(); + if (virAsprintf(&profile, "%s/%s", APPARMOR_DIR "/libvirt", str) == -1) return rc; - } if (!virFileExists(profile)) goto failed; @@ -147,10 +142,8 @@ profile_status_file(const char *str) } /* create string that is ' <str> flags=(complain)\0' */ - if (virAsprintf(&tmp, " %s flags=(complain)", str) == -1) { - virReportOOMError(); + if (virAsprintf(&tmp, " %s flags=(complain)", str) == -1) goto failed; - } if (strstr(content, tmp) != NULL) rc = 0; @@ -231,10 +224,8 @@ get_profile_name(virDomainDefPtr def) char *name = NULL; virUUIDFormat(def->uuid, uuidstr); - if (virAsprintf(&name, "%s%s", AA_PREFIX, uuidstr) < 0) { - virReportOOMError(); + if (virAsprintf(&name, "%s%s", AA_PREFIX, uuidstr) < 0) return NULL; - } return name; } @@ -363,10 +354,8 @@ AppArmorSecurityManagerProbe(const char *virtDriver) /* see if template file exists */ if (virAsprintf(&template, "%s/TEMPLATE", - APPARMOR_DIR "/libvirt") == -1) { - virReportOOMError(); + APPARMOR_DIR "/libvirt") == -1) return rc; - } if (!virFileExists(template)) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -920,10 +909,8 @@ AppArmorSetFDLabel(virSecurityManagerPtr mgr, if (secdef->imagelabel == NULL) return 0; - if (virAsprintf(&proc, "/proc/self/fd/%d", fd) == -1) { - virReportOOMError(); + if (virAsprintf(&proc, "/proc/self/fd/%d", fd) == -1) return rc; - } if (virFileResolveLink(proc, &fd_path) < 0) { /* it's a deleted file, presumably. Ignore? */ diff --git a/src/security/security_dac.c b/src/security/security_dac.c index 0d6defc..365ab8b 100644 --- a/src/security/security_dac.c +++ b/src/security/security_dac.c @@ -713,10 +713,8 @@ virSecurityDACSetChardevLabel(virSecurityManagerPtr mgr, case VIR_DOMAIN_CHR_TYPE_PIPE: if ((virAsprintf(&in, "%s.in", dev->data.file.path) < 0) || - (virAsprintf(&out, "%s.out", dev->data.file.path) < 0)) { - virReportOOMError(); + (virAsprintf(&out, "%s.out", dev->data.file.path) < 0)) goto done; - } if (virFileExists(in) && virFileExists(out)) { if ((virSecurityDACSetOwnership(in, user, group) < 0) || (virSecurityDACSetOwnership(out, user, group) < 0)) { @@ -755,10 +753,8 @@ virSecurityDACRestoreChardevLabel(virSecurityManagerPtr mgr ATTRIBUTE_UNUSED, case VIR_DOMAIN_CHR_TYPE_PIPE: if ((virAsprintf(&out, "%s.out", dev->data.file.path) < 0) || - (virAsprintf(&in, "%s.in", dev->data.file.path) < 0)) { - virReportOOMError(); + (virAsprintf(&in, "%s.in", dev->data.file.path) < 0)) goto done; - } if (virFileExists(in) && virFileExists(out)) { if ((virSecurityDACRestoreSecurityFileLabel(out) < 0) || (virSecurityDACRestoreSecurityFileLabel(in) < 0)) { @@ -1084,10 +1080,8 @@ virSecurityDACGenLabel(virSecurityManagerPtr mgr, case VIR_DOMAIN_SECLABEL_DYNAMIC: if (virAsprintf(&seclabel->label, "%u:%u", (unsigned int) priv->user, - (unsigned int) priv->group) < 0) { - virReportOOMError(); + (unsigned int) priv->group) < 0) return rc; - } if (seclabel->label == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot generate dac user and group id " diff --git a/src/security/security_manager.c b/src/security/security_manager.c index f5ea73a..729d0e3 100644 --- a/src/security/security_manager.c +++ b/src/security/security_manager.c @@ -80,10 +80,8 @@ static virSecurityManagerPtr virSecurityManagerNewDriver(virSecurityDriverPtr dr allowDiskFormatProbing, defaultConfined, requireConfined); - if (VIR_ALLOC_N(privateData, drv->privateDataLen) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(privateData, drv->privateDataLen) < 0) return NULL; - } if (!(mgr = virObjectLockableNew(virSecurityManagerClass))) { VIR_FREE(privateData); @@ -701,10 +699,8 @@ virSecurityManagerGetNested(virSecurityManagerPtr mgr) return virSecurityStackGetNested(mgr); } - if (VIR_ALLOC_N(list, 2) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(list, 2) < 0) return NULL; - } list[0] = mgr; list[1] = NULL; diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c index 8842d85..62bfc73 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -141,20 +141,16 @@ virSecuritySELinuxMCSFind(virSecurityManagerPtr mgr, VIR_DEBUG("Try cat %s:c%d,c%d", sens, c1 + catMin, c2 + catMin); if (c1 == c2) { - if (virAsprintf(&mcs, "%s:c%d", sens, catMin + c1) < 0) { - virReportOOMError(); + if (virAsprintf(&mcs, "%s:c%d", sens, catMin + c1) < 0) return NULL; - } } else { if (c1 > c2) { int t = c1; c1 = c2; c2 = t; } - if (virAsprintf(&mcs, "%s:c%d,c%d", sens, catMin + c1, catMin + c2) < 0) { - virReportOOMError(); + if (virAsprintf(&mcs, "%s:c%d,c%d", sens, catMin + c1, catMin + c2) < 0) return NULL; - } } if (virHashLookup(data->mcs, mcs) == NULL) @@ -630,7 +626,7 @@ virSecuritySELinuxGenSecurityLabel(virSecurityManagerPtr mgr, range = context_range_get(ctx); if (!range) { - virReportOOMError(); + virReportSystemError(errno, "%s", _("unable to get selinux context range")); goto cleanup; } if (VIR_STRDUP(mcs, range) < 0) @@ -1392,10 +1388,8 @@ virSecuritySELinuxSetSecurityHostdevCapsLabel(virDomainDefPtr def, case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_STORAGE: { if (vroot) { if (virAsprintf(&path, "%s/%s", vroot, - dev->source.caps.u.storage.block) < 0) { - virReportOOMError(); + dev->source.caps.u.storage.block) < 0) return -1; - } } else { if (VIR_STRDUP(path, dev->source.caps.u.storage.block) < 0) return -1; @@ -1408,10 +1402,8 @@ virSecuritySELinuxSetSecurityHostdevCapsLabel(virDomainDefPtr def, case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_MISC: { if (vroot) { if (virAsprintf(&path, "%s/%s", vroot, - dev->source.caps.u.misc.chardev) < 0) { - virReportOOMError(); + dev->source.caps.u.misc.chardev) < 0) return -1; - } } else { if (VIR_STRDUP(path, dev->source.caps.u.misc.chardev) < 0) return -1; @@ -1582,10 +1574,8 @@ virSecuritySELinuxRestoreSecurityHostdevCapsLabel(virSecurityManagerPtr mgr, case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_STORAGE: { if (vroot) { if (virAsprintf(&path, "%s/%s", vroot, - dev->source.caps.u.storage.block) < 0) { - virReportOOMError(); + dev->source.caps.u.storage.block) < 0) return -1; - } } else { if (VIR_STRDUP(path, dev->source.caps.u.storage.block) < 0) return -1; @@ -1598,10 +1588,8 @@ virSecuritySELinuxRestoreSecurityHostdevCapsLabel(virSecurityManagerPtr mgr, case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_MISC: { if (vroot) { if (virAsprintf(&path, "%s/%s", vroot, - dev->source.caps.u.misc.chardev) < 0) { - virReportOOMError(); + dev->source.caps.u.misc.chardev) < 0) return -1; - } } else { if (VIR_STRDUP(path, dev->source.caps.u.misc.chardev) < 0) return -1; @@ -1695,10 +1683,8 @@ virSecuritySELinuxSetSecurityChardevLabel(virDomainDefPtr def, case VIR_DOMAIN_CHR_TYPE_PIPE: if ((virAsprintf(&in, "%s.in", dev_source->data.file.path) < 0) || - (virAsprintf(&out, "%s.out", dev_source->data.file.path) < 0)) { - virReportOOMError(); + (virAsprintf(&out, "%s.out", dev_source->data.file.path) < 0)) goto done; - } if (virFileExists(in) && virFileExists(out)) { if ((virSecuritySELinuxSetFilecon(in, imagelabel) < 0) || (virSecuritySELinuxSetFilecon(out, imagelabel) < 0)) { @@ -1762,10 +1748,8 @@ virSecuritySELinuxRestoreSecurityChardevLabel(virSecurityManagerPtr mgr, case VIR_DOMAIN_CHR_TYPE_PIPE: if ((virAsprintf(&out, "%s.out", dev_source->data.file.path) < 0) || - (virAsprintf(&in, "%s.in", dev_source->data.file.path) < 0)) { - virReportOOMError(); + (virAsprintf(&in, "%s.in", dev_source->data.file.path) < 0)) goto done; - } if (virFileExists(in) && virFileExists(out)) { if ((virSecuritySELinuxRestoreSecurityFileLabel(mgr, out) < 0) || (virSecuritySELinuxRestoreSecurityFileLabel(mgr, in) < 0)) { @@ -2399,7 +2383,8 @@ virSecuritySELinuxGenImageLabel(virSecurityManagerPtr mgr, if (secdef->label) { ctx = context_new(secdef->label); if (!ctx) { - virReportOOMError(); + virReportSystemError(errno, _("unable to create selinux context for: %s"), + secdef->label); goto cleanup; } range = context_range_get(ctx); @@ -2432,10 +2417,8 @@ virSecuritySELinuxGetSecurityMountOptions(virSecurityManagerPtr mgr, if (secdef->imagelabel && virAsprintf(&opts, ",context=\"%s\"", - (const char*) secdef->imagelabel) < 0) { - virReportOOMError(); + (const char*) secdef->imagelabel) < 0) return NULL; - } } if (!opts && VIR_STRDUP(opts, "") < 0) diff --git a/src/security/security_stack.c b/src/security/security_stack.c index 14d757d..9afc641 100644 --- a/src/security/security_stack.c +++ b/src/security/security_stack.c @@ -53,10 +53,8 @@ virSecurityStackAddNested(virSecurityManagerPtr mgr, while (tmp && tmp->next) tmp = tmp->next; - if (VIR_ALLOC(item) < 0) { - virReportOOMError(); + if (VIR_ALLOC(item) < 0) return -1; - } item->securityManager = nested; if (tmp) tmp->next = item; @@ -520,10 +518,8 @@ virSecurityStackGetNested(virSecurityManagerPtr mgr) for (item = priv->itemsHead; item; item = item->next) len++; - if (VIR_ALLOC_N(list, len + 1) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(list, len + 1) < 0) return NULL; - } for (item = priv->itemsHead; item; item = item->next, i++) list[i] = item->securityManager; -- 1.8.1.5

On 07/04/2013 02:06 PM, Michal Privoznik wrote:
--- src/security/security_apparmor.c | 25 ++++++------------------ src/security/security_dac.c | 12 +++--------- src/security/security_manager.c | 8 ++------ src/security/security_selinux.c | 41 ++++++++++++---------------------------- src/security/security_stack.c | 8 ++------ 5 files changed, 25 insertions(+), 69 deletions(-)
virt-aa-helper.c uses vah_error for OOM error reporting, virAsprintf and VIR_ALLOC should be quiet there. ACK to the rest. Jan

--- src/storage/storage_backend.c | 35 ++++++------------------- src/storage/storage_backend_disk.c | 17 +++--------- src/storage/storage_backend_fs.c | 31 ++++++---------------- src/storage/storage_backend_iscsi.c | 27 +++++-------------- src/storage/storage_backend_logical.c | 48 +++++++++------------------------- src/storage/storage_backend_mpath.c | 20 ++++---------- src/storage/storage_backend_rbd.c | 18 ++++--------- src/storage/storage_backend_scsi.c | 21 +++------------ src/storage/storage_backend_sheepdog.c | 4 +-- src/storage/storage_driver.c | 23 +++++----------- 10 files changed, 60 insertions(+), 184 deletions(-) diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c index 9a3bcf8..e2527c9 100644 --- a/src/storage/storage_backend.c +++ b/src/storage/storage_backend.c @@ -161,13 +161,11 @@ virStorageBackendCopyToFD(virStorageVolDefPtr vol, if (VIR_ALLOC_N(zerobuf, wbytes) < 0) { ret = -errno; - virReportOOMError(); goto cleanup; } if (VIR_ALLOC_N(buf, rbytes) < 0) { ret = -errno; - virReportOOMError(); goto cleanup; } @@ -466,10 +464,8 @@ virStorageGenerateQcowEncryption(virConnectPtr conn, } if (VIR_ALLOC(enc_secret) < 0 || VIR_REALLOC_N(enc->secrets, 1) < 0 || - VIR_ALLOC(def) < 0) { - virReportOOMError(); + VIR_ALLOC(def) < 0) goto cleanup; - } def->ephemeral = false; def->private = false; @@ -798,10 +794,8 @@ virStorageBackendCreateQemuImgCmd(virConnectPtr conn, */ if ('/' != *(vol->backingStore.path) && virAsprintf(&absolutePath, "%s/%s", pool->def->target.path, - vol->backingStore.path) < 0) { - virReportOOMError(); + vol->backingStore.path) < 0) return NULL; - } accessRetCode = access(absolutePath ? absolutePath : vol->backingStore.path, R_OK); VIR_FREE(absolutePath); @@ -986,10 +980,8 @@ virStorageBackendCreateQcowCreate(virConnectPtr conn ATTRIBUTE_UNUSED, /* Size in MB - yes different units to qemu-img :-( */ if (virAsprintf(&size, "%llu", - VIR_DIV_UP(vol->capacity, (1024 * 1024))) < 0) { - virReportOOMError(); + VIR_DIV_UP(vol->capacity, (1024 * 1024))) < 0) return -1; - } cmd = virCommandNewArgList("qcow-create", size, vol->target.path, NULL); @@ -1298,10 +1290,8 @@ virStorageBackendUpdateVolTargetInfoFD(virStorageVolTargetPtr target, target->perms.uid = sb.st_uid; target->perms.gid = sb.st_gid; - if (!target->timestamps && VIR_ALLOC(target->timestamps) < 0) { - virReportOOMError(); + if (!target->timestamps && VIR_ALLOC(target->timestamps) < 0) return -1; - } target->timestamps->atime = get_stat_atime(&sb); target->timestamps->btime = get_stat_birthtime(&sb); target->timestamps->ctime = get_stat_ctime(&sb); @@ -1485,7 +1475,6 @@ virStorageBackendStablePath(virStoragePoolObjPtr pool, if (virAsprintf(&stablepath, "%s/%s", pool->def->target.path, dent->d_name) == -1) { - virReportOOMError(); closedir(dh); return NULL; } @@ -1543,10 +1532,8 @@ virStorageBackendRunProgRegex(virStoragePoolObjPtr pool, char **groups; /* Compile all regular expressions */ - if (VIR_ALLOC_N(reg, nregex) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(reg, nregex) < 0) return -1; - } for (i = 0; i < nregex; i++) { err = regcomp(®[i], regex[i], REG_EXTENDED); @@ -1568,14 +1555,10 @@ virStorageBackendRunProgRegex(virStoragePoolObjPtr pool, } /* Storage for matched variables */ - if (VIR_ALLOC_N(groups, totgroups) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(groups, totgroups) < 0) goto cleanup; - } - if (VIR_ALLOC_N(vars, maxvars+1) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(vars, maxvars+1) < 0) goto cleanup; - } virCommandSetOutputFD(cmd, &fd); if (virCommandRunAsync(cmd, NULL) < 0) { @@ -1679,10 +1662,8 @@ virStorageBackendRunProgNul(virStoragePoolObjPtr pool, if (n_columns == 0) return -1; - if (VIR_ALLOC_N(v, n_columns) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(v, n_columns) < 0) return -1; - } for (i = 0; i < n_columns; i++) v[i] = NULL; diff --git a/src/storage/storage_backend_disk.c b/src/storage/storage_backend_disk.c index d0b91f9..6ebcf48 100644 --- a/src/storage/storage_backend_disk.c +++ b/src/storage/storage_backend_disk.c @@ -50,14 +50,11 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr pool, char *tmp, *devpath; if (vol == NULL) { - if (VIR_ALLOC(vol) < 0) { - virReportOOMError(); + if (VIR_ALLOC(vol) < 0) return -1; - } if (VIR_REALLOC_N(pool->volumes.objs, pool->volumes.count+1) < 0) { - virReportOOMError(); virStorageVolDefFree(vol); return -1; } @@ -94,10 +91,8 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr pool, } if (vol->source.extents == NULL) { - if (VIR_ALLOC(vol->source.extents) < 0) { - virReportOOMError(); + if (VIR_ALLOC(vol->source.extents) < 0) return -1; - } vol->source.nextent = 1; if (virStrToLong_ull(groups[3], NULL, 10, @@ -487,10 +482,8 @@ virStorageBackendDiskPartFormat(virStoragePoolObjPtr pool, /* XXX Only support one extended partition */ switch (virStorageBackendDiskPartTypeToCreate(pool)) { case VIR_STORAGE_VOL_DISK_TYPE_PRIMARY: - if (virAsprintf(partFormat, "primary %s", partedFormat) < 0) { - virReportOOMError(); + if (virAsprintf(partFormat, "primary %s", partedFormat) < 0) return -1; - } break; case VIR_STORAGE_VOL_DISK_TYPE_LOGICAL: /* make sure we have a extended partition */ @@ -498,10 +491,8 @@ virStorageBackendDiskPartFormat(virStoragePoolObjPtr pool, if (pool->volumes.objs[i]->target.format == VIR_STORAGE_VOL_DISK_EXTENDED) { if (virAsprintf(partFormat, "logical %s", - partedFormat) < 0) { - virReportOOMError(); + partedFormat) < 0) return -1; - } break; } } diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c index 3598d83..9802d15 100644 --- a/src/storage/storage_backend_fs.c +++ b/src/storage/storage_backend_fs.c @@ -129,10 +129,8 @@ virStorageBackendProbeTarget(virStorageVolTargetPtr target, *capacity = meta->capacity; if (encryption != NULL && meta->encrypted) { - if (VIR_ALLOC(*encryption) < 0) { - virReportOOMError(); + if (VIR_ALLOC(*encryption) < 0) goto cleanup; - } switch (target->format) { case VIR_STORAGE_FILE_QCOW: @@ -211,10 +209,8 @@ virStorageBackendFileSystemNetFindPoolSourcesFunc(virStoragePoolObjPtr pool ATTR if (!(src = virStoragePoolSourceListNewSource(&state->list))) goto cleanup; - if (VIR_ALLOC_N(src->hosts, 1) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(src->hosts, 1) < 0) goto cleanup; - } src->nhost = 1; if (VIR_STRDUP(src->hosts[0].name, state->host) < 0 || @@ -292,10 +288,8 @@ virStorageBackendFileSystemNetFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSE goto cleanup; retval = virStoragePoolSourceListFormat(&state.list); - if (retval == NULL) { - virReportOOMError(); + if (retval == NULL) goto cleanup; - } cleanup: for (i = 0; i < state.list.nsources; i++) @@ -397,10 +391,8 @@ virStorageBackendFileSystemMount(virStoragePoolObjPtr pool) { if (pool->def->type == VIR_STORAGE_POOL_NETFS) { if (virAsprintf(&src, "%s:%s", pool->def->source.hosts[0].name, - pool->def->source.dir) == -1) { - virReportOOMError(); + pool->def->source.dir) == -1) return -1; - } } else { if (VIR_STRDUP(src, pool->def->source.devices[0].path) < 0) @@ -833,7 +825,7 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn ATTRIBUTE_UNUSED, int backingStoreFormat; if (VIR_ALLOC(vol) < 0) - goto no_memory; + goto cleanup; if (VIR_STRDUP(vol->name, ent->d_name) < 0) goto cleanup; @@ -843,7 +835,7 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn ATTRIBUTE_UNUSED, if (virAsprintf(&vol->target.path, "%s/%s", pool->def->target.path, vol->name) == -1) - goto no_memory; + goto cleanup; if (VIR_STRDUP(vol->key, vol->target.path) < 0) goto cleanup; @@ -897,7 +889,7 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn ATTRIBUTE_UNUSED, if (VIR_REALLOC_N(pool->volumes.objs, pool->volumes.count+1) < 0) - goto no_memory; + goto cleanup; pool->volumes.objs[pool->volumes.count++] = vol; vol = NULL; } @@ -918,10 +910,6 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn ATTRIBUTE_UNUSED, return 0; -no_memory: - virReportOOMError(); - /* fallthrough */ - cleanup: if (dir) closedir(dir); @@ -1000,10 +988,8 @@ virStorageBackendFileSystemVolCreate(virConnectPtr conn ATTRIBUTE_UNUSED, VIR_FREE(vol->target.path); if (virAsprintf(&vol->target.path, "%s/%s", pool->def->target.path, - vol->name) == -1) { - virReportOOMError(); + vol->name) == -1) return -1; - } if (virFileExists(vol->target.path)) { virReportError(VIR_ERR_OPERATION_INVALID, @@ -1194,7 +1180,6 @@ virStorageBackendFileSystemVolRefresh(virConnectPtr conn, if (VIR_ALLOC_N(vol->target.encryption->secrets, 1) < 0 || VIR_ALLOC(encsec) < 0) { VIR_FREE(vol->target.encryption->secrets); - virReportOOMError(); virSecretFree(sec); return -1; } diff --git a/src/storage/storage_backend_iscsi.c b/src/storage/storage_backend_iscsi.c index 0a4cd22..402462d 100644 --- a/src/storage/storage_backend_iscsi.c +++ b/src/storage/storage_backend_iscsi.c @@ -62,11 +62,9 @@ virStorageBackendISCSIPortal(virStoragePoolSourcePtr source) port = source->hosts[0].port; if (strchr(host, ':')) { - if (virAsprintf(&portal, "[%s]:%d,1", host, port) < 0) - virReportOOMError(); + ignore_value(virAsprintf(&portal, "[%s]:%d,1", host, port)); } else { - if (virAsprintf(&portal, "%s:%d,1", host, port) < 0) - virReportOOMError(); + ignore_value(virAsprintf(&portal, "%s:%d,1", host, port)); } return portal; @@ -234,10 +232,8 @@ virStorageBackendCreateIfaceIQN(const char *initiatoriqn, if (virAsprintf(&temp_ifacename, "libvirt-iface-%08llx", - (unsigned long long)virRandomBits(30)) < 0) { - virReportOOMError(); + (unsigned long long)virRandomBits(30)) < 0) return -1; - } VIR_DEBUG("Attempting to create interface '%s' with IQN '%s'", temp_ifacename, initiatoriqn); @@ -396,10 +392,8 @@ virStorageBackendISCSIFindLUs(virStoragePoolObjPtr pool, uint32_t host; if (virAsprintf(&sysfs_path, - "/sys/class/iscsi_session/session%s/device", session) < 0) { - virReportOOMError(); + "/sys/class/iscsi_session/session%s/device", session) < 0) return -1; - } if (virStorageBackendISCSIGetHostNumber(sysfs_path, &host) < 0) { virReportSystemError(errno, @@ -452,7 +446,6 @@ virStorageBackendISCSIGetTargets(virStoragePoolObjPtr pool ATTRIBUTE_UNUSED, if (VIR_REALLOC_N(list->targets, list->ntargets + 1) < 0) { VIR_FREE(target); - virReportOOMError(); return -1; } @@ -590,17 +583,13 @@ virStorageBackendISCSIFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSED, &ntargets, &targets) < 0) goto cleanup; - if (VIR_ALLOC_N(list.sources, ntargets) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(list.sources, ntargets) < 0) goto cleanup; - } for (i = 0; i < ntargets; i++) { if (VIR_ALLOC_N(list.sources[i].devices, 1) < 0 || - VIR_ALLOC_N(list.sources[i].hosts, 1) < 0) { - virReportOOMError(); + VIR_ALLOC_N(list.sources[i].hosts, 1) < 0) goto cleanup; - } list.sources[i].nhost = 1; list.sources[i].hosts[0] = source->hosts[0]; list.sources[i].initiator = source->initiator; @@ -609,10 +598,8 @@ virStorageBackendISCSIFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSED, list.nsources++; } - if (!(ret = virStoragePoolSourceListFormat(&list))) { - virReportOOMError(); + if (!(ret = virStoragePoolSourceListFormat(&list))) goto cleanup; - } cleanup: if (list.sources) { diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c index 944aa0e..fff303d 100644 --- a/src/storage/storage_backend_logical.c +++ b/src/storage/storage_backend_logical.c @@ -97,10 +97,8 @@ virStorageBackendLogicalMakeVol(virStoragePoolObjPtr pool, /* Or a completely new volume */ if (vol == NULL) { - if (VIR_ALLOC(vol) < 0) { - virReportOOMError(); + if (VIR_ALLOC(vol) < 0) return -1; - } is_new_vol = true; vol->type = VIR_STORAGE_VOL_BLOCK; @@ -109,18 +107,14 @@ virStorageBackendLogicalMakeVol(virStoragePoolObjPtr pool, goto cleanup; if (VIR_REALLOC_N(pool->volumes.objs, - pool->volumes.count + 1)) { - virReportOOMError(); + pool->volumes.count + 1)) goto cleanup; - } } if (vol->target.path == NULL) { if (virAsprintf(&vol->target.path, "%s/%s", - pool->def->target.path, vol->name) < 0) { - virReportOOMError(); + pool->def->target.path, vol->name) < 0) goto cleanup; - } } /* Skips the backingStore of lv created with "--virtualsize", @@ -132,10 +126,8 @@ virStorageBackendLogicalMakeVol(virStoragePoolObjPtr pool, */ if (groups[1] && !STREQ(groups[1], "") && (groups[1][0] != '[')) { if (virAsprintf(&vol->backingStore.path, "%s/%s", - pool->def->target.path, groups[1]) < 0) { - virReportOOMError(); + pool->def->target.path, groups[1]) < 0) goto cleanup; - } vol->backingStore.format = VIR_STORAGE_POOL_LOGICAL_LVM2; } @@ -157,10 +149,8 @@ virStorageBackendLogicalMakeVol(virStoragePoolObjPtr pool, /* Finally fill in extents information */ if (VIR_REALLOC_N(vol->source.extents, - vol->source.nextent + nextents) < 0) { - virReportOOMError(); + vol->source.nextent + nextents) < 0) goto cleanup; - } if (virStrToLong_ull(groups[6], NULL, 10, &length) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -183,28 +173,22 @@ virStorageBackendLogicalMakeVol(virStoragePoolObjPtr pool, goto cleanup; for (i = 1; i < nextents; i++) { - if (VIR_REALLOC_N(regex, strlen(regex) + strlen(regex_unit) + 2) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(regex, strlen(regex) + strlen(regex_unit) + 2) < 0) goto cleanup; - } /* "," is the separator of "devices" field */ strcat(regex, ","); strncat(regex, regex_unit, strlen(regex_unit)); } - if (VIR_ALLOC(reg) < 0) { - virReportOOMError(); + if (VIR_ALLOC(reg) < 0) goto cleanup; - } /* Each extent has a "path:offset" pair, and vars[0] will * be the whole matched string. */ nvars = (nextents * 2) + 1; - if (VIR_ALLOC_N(vars, nvars) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(vars, nvars) < 0) goto cleanup; - } err = regcomp(reg, regex, REG_EXTENDED); if (err != 0) { @@ -380,10 +364,8 @@ virStorageBackendLogicalFindPoolSourcesFunc(virStoragePoolObjPtr pool ATTRIBUTE_ else VIR_FREE(vgname); - if (VIR_REALLOC_N(thisSource->devices, thisSource->ndevice + 1) != 0) { - virReportOOMError(); + if (VIR_REALLOC_N(thisSource->devices, thisSource->ndevice + 1) != 0) goto error; - } dev = &thisSource->devices[thisSource->ndevice]; thisSource->ndevice++; @@ -473,10 +455,8 @@ virStorageBackendLogicalCheckPool(virConnectPtr conn ATTRIBUTE_UNUSED, char *path; *isActive = false; - if (virAsprintf(&path, "/dev/%s", pool->def->source.name) < 0) { - virReportOOMError(); + if (virAsprintf(&path, "/dev/%s", pool->def->source.name) < 0) return -1; - } if (access(path, F_OK) == 0) *isActive = true; @@ -719,10 +699,8 @@ virStorageBackendLogicalCreateVol(virConnectPtr conn, if (virAsprintf(&vol->target.path, "%s/%s", pool->def->target.path, - vol->name) == -1) { - virReportOOMError(); + vol->name) == -1) return -1; - } cmd = virCommandNewArgList(LVCREATE, "--name", vol->name, @@ -822,10 +800,8 @@ virStorageBackendLogicalDeleteVol(virConnectPtr conn ATTRIBUTE_UNUSED, virCheckFlags(0, -1); if (virAsprintf(&volpath, "%s/%s", - pool->def->source.name, vol->name) < 0) { - virReportOOMError(); + pool->def->source.name, vol->name) < 0) goto cleanup; - } virFileWaitForDevices(); diff --git a/src/storage/storage_backend_mpath.c b/src/storage/storage_backend_mpath.c index 357c346..8333f18 100644 --- a/src/storage/storage_backend_mpath.c +++ b/src/storage/storage_backend_mpath.c @@ -75,22 +75,16 @@ virStorageBackendMpathNewVol(virStoragePoolObjPtr pool, virStorageVolDefPtr vol; int ret = -1; - if (VIR_ALLOC(vol) < 0) { - virReportOOMError(); + if (VIR_ALLOC(vol) < 0) goto cleanup; - } vol->type = VIR_STORAGE_VOL_BLOCK; - if (virAsprintf(&(vol->name), "dm-%u", devnum) < 0) { - virReportOOMError(); + if (virAsprintf(&(vol->name), "dm-%u", devnum) < 0) goto cleanup; - } - if (virAsprintf(&vol->target.path, "/dev/%s", dev) < 0) { - virReportOOMError(); + if (virAsprintf(&vol->target.path, "/dev/%s", dev) < 0) goto cleanup; - } if (virStorageBackendMpathUpdateVolTargetInfo(&vol->target, &vol->allocation, @@ -103,10 +97,8 @@ virStorageBackendMpathNewVol(virStoragePoolObjPtr pool, goto cleanup; if (VIR_REALLOC_N(pool->volumes.objs, - pool->volumes.count + 1) < 0) { - virReportOOMError(); + pool->volumes.count + 1) < 0) goto cleanup; - } pool->volumes.objs[pool->volumes.count++] = vol; pool->def->capacity += vol->capacity; pool->def->allocation += vol->allocation; @@ -220,10 +212,8 @@ virStorageBackendCreateVols(virStoragePoolObjPtr pool, if (is_mpath == 1) { - if (virAsprintf(&map_device, "mapper/%s", names->name) < 0) { - virReportOOMError(); + if (virAsprintf(&map_device, "mapper/%s", names->name) < 0) goto out; - } if (virStorageBackendGetMinorNumber(names->name, &minor) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, diff --git a/src/storage/storage_backend_rbd.c b/src/storage/storage_backend_rbd.c index 953a8ee..7b73a38 100644 --- a/src/storage/storage_backend_rbd.c +++ b/src/storage/storage_backend_rbd.c @@ -238,18 +238,14 @@ static int volStorageBackendRBDRefreshVolInfo(virStorageVolDefPtr vol, VIR_FREE(vol->target.path); if (virAsprintf(&vol->target.path, "%s/%s", pool->def->source.name, - vol->name) == -1) { - virReportOOMError(); + vol->name) == -1) goto cleanup; - } VIR_FREE(vol->key); if (virAsprintf(&vol->key, "%s/%s", pool->def->source.name, - vol->name) == -1) { - virReportOOMError(); + vol->name) == -1) goto cleanup; - } ret = 0; @@ -308,7 +304,7 @@ static int virStorageBackendRBDRefreshPool(virConnectPtr conn ATTRIBUTE_UNUSED, while (true) { if (VIR_ALLOC_N(names, max_size) < 0) - goto out_of_memory; + goto cleanup; len = rbd_list(ptr.ioctx, names, &max_size); if (len >= 0) @@ -325,14 +321,14 @@ static int virStorageBackendRBDRefreshPool(virConnectPtr conn ATTRIBUTE_UNUSED, if (VIR_REALLOC_N(pool->volumes.objs, pool->volumes.count + 1) < 0) { virStoragePoolObjClearVols(pool); - goto out_of_memory; + goto cleanup; } if (STREQ(name, "")) break; if (VIR_ALLOC(vol) < 0) - goto out_of_memory; + goto cleanup; if (VIR_STRDUP(vol->name, name) < 0) { VIR_FREE(vol); @@ -358,10 +354,6 @@ cleanup: VIR_FREE(names); virStorageBackendRBDCloseRADOSConn(ptr); return ret; - -out_of_memory: - virReportOOMError(); - goto cleanup; } static int virStorageBackendRBDDeleteVol(virConnectPtr conn, diff --git a/src/storage/storage_backend_scsi.c b/src/storage/storage_backend_scsi.c index 3deceda..8cb762a 100644 --- a/src/storage/storage_backend_scsi.c +++ b/src/storage/storage_backend_scsi.c @@ -56,10 +56,8 @@ getDeviceType(uint32_t host, int retval = 0; if (virAsprintf(&type_path, "/sys/bus/scsi/devices/%u:%u:%u:%u/type", - host, bus, target, lun) < 0) { - virReportOOMError(); + host, bus, target, lun) < 0) goto out; - } typefile = fopen(type_path, "r"); if (typefile == NULL) { @@ -213,7 +211,6 @@ virStorageBackendSCSINewLun(virStoragePoolObjPtr pool, int retval = 0; if (VIR_ALLOC(vol) < 0) { - virReportOOMError(); retval = -1; goto out; } @@ -226,13 +223,11 @@ virStorageBackendSCSINewLun(virStoragePoolObjPtr pool, * just leave 'host' out */ if (virAsprintf(&(vol->name), "unit:%u:%u:%u", bus, target, lun) < 0) { - virReportOOMError(); retval = -1; goto free_vol; } if (virAsprintf(&devpath, "/dev/%s", dev) < 0) { - virReportOOMError(); retval = -1; goto free_vol; } @@ -284,7 +279,6 @@ virStorageBackendSCSINewLun(virStoragePoolObjPtr pool, if (VIR_REALLOC_N(pool->volumes.objs, pool->volumes.count + 1) < 0) { - virReportOOMError(); retval = -1; goto free_vol; } @@ -310,10 +304,8 @@ getNewStyleBlockDevice(const char *lun_path, struct dirent *block_dirent = NULL; int retval = 0; - if (virAsprintf(&block_path, "%s/block", lun_path) < 0) { - virReportOOMError(); + if (virAsprintf(&block_path, "%s/block", lun_path) < 0) goto out; - } VIR_DEBUG("Looking for block device in '%s'", block_path); @@ -395,10 +387,8 @@ getBlockDevice(uint32_t host, int retval = 0; if (virAsprintf(&lun_path, "/sys/bus/scsi/devices/%u:%u:%u:%u", - host, bus, target, lun) < 0) { - virReportOOMError(); + host, bus, target, lun) < 0) goto out; - } lun_dir = opendir(lun_path); if (lun_dir == NULL) { @@ -543,7 +533,6 @@ virStorageBackendSCSITriggerRescan(uint32_t host) VIR_DEBUG("Triggering rescan of host %d", host); if (virAsprintf(&path, "/sys/class/scsi_host/host%u/scan", host) < 0) { - virReportOOMError(); retval = -1; goto out; } @@ -708,10 +697,8 @@ virStorageBackendSCSICheckPool(virConnectPtr conn ATTRIBUTE_UNUSED, if (getHostNumber(name, &host) < 0) goto cleanup; - if (virAsprintf(&path, "/sys/class/scsi_host/host%d", host) < 0) { - virReportOOMError(); + if (virAsprintf(&path, "/sys/class/scsi_host/host%d", host) < 0) goto cleanup; - } if (access(path, F_OK) == 0) *isActive = true; diff --git a/src/storage/storage_backend_sheepdog.c b/src/storage/storage_backend_sheepdog.c index b4d7b8e..a97af1b 100644 --- a/src/storage/storage_backend_sheepdog.c +++ b/src/storage/storage_backend_sheepdog.c @@ -263,10 +263,8 @@ virStorageBackendSheepdogRefreshVol(virConnectPtr conn ATTRIBUTE_UNUSED, VIR_FREE(vol->key); if (virAsprintf(&vol->key, "%s/%s", - pool->def->source.name, vol->name) == -1) { - virReportOOMError(); + pool->def->source.name, vol->name) == -1) goto cleanup; - } VIR_FREE(vol->target.path); ignore_value(VIR_STRDUP(vol->target.path, vol->name)); diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index 02f7b69..3cbb15a 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -158,11 +158,11 @@ storageStateInitialize(bool privileged, */ if (virAsprintf(&driverState->configDir, "%s/storage", base) == -1) - goto out_of_memory; + goto error; if (virAsprintf(&driverState->autostartDir, "%s/storage/autostart", base) == -1) - goto out_of_memory; + goto error; VIR_FREE(base); @@ -175,8 +175,6 @@ storageStateInitialize(bool privileged, storageDriverUnlock(driverState); return 0; -out_of_memory: - virReportOOMError(); error: VIR_FREE(base); storageDriverUnlock(driverState); @@ -1283,10 +1281,8 @@ storagePoolListAllVolumes(virStoragePoolPtr pool, goto cleanup; } - if (VIR_ALLOC_N(tmp_vols, obj->volumes.count + 1) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(tmp_vols, obj->volumes.count + 1) < 0) goto cleanup; - } for (i = 0; i < obj->volumes.count; i++) { if (!virStoragePoolListAllVolumesCheckACL(pool->conn, obj->def, @@ -1512,10 +1508,8 @@ storageVolCreateXML(virStoragePoolPtr obj, } if (VIR_REALLOC_N(pool->volumes.objs, - pool->volumes.count+1) < 0) { - virReportOOMError(); + pool->volumes.count+1) < 0) goto cleanup; - } if (!backend->createVol) { virReportError(VIR_ERR_NO_SUPPORT, @@ -1541,7 +1535,6 @@ storageVolCreateXML(virStoragePoolPtr obj, virStorageVolDefPtr buildvoldef = NULL; if (VIR_ALLOC(buildvoldef) < 0) { - virReportOOMError(); voldef = NULL; goto cleanup; } @@ -1693,10 +1686,8 @@ storageVolCreateXMLFrom(virStoragePoolPtr obj, goto cleanup; if (VIR_REALLOC_N(pool->volumes.objs, - pool->volumes.count+1) < 0) { - virReportOOMError(); + pool->volumes.count+1) < 0) goto cleanup; - } /* 'Define' the new volume so we get async progress reporting */ if (backend->createVol(obj->conn, pool, newvol) < 0) { @@ -2173,10 +2164,8 @@ storageVolWipeInternal(virStorageVolDefPtr def, ret = storageVolZeroSparseFile(def, st.st_size, fd); } else { - if (VIR_ALLOC_N(writebuf, st.st_blksize) != 0) { - virReportOOMError(); + if (VIR_ALLOC_N(writebuf, st.st_blksize) < 0) goto out; - } ret = storageWipeExtent(def, fd, -- 1.8.1.5

On 07/04/13 14:06, Michal Privoznik wrote:
--- src/storage/storage_backend.c | 35 ++++++------------------- src/storage/storage_backend_disk.c | 17 +++--------- src/storage/storage_backend_fs.c | 31 ++++++---------------- src/storage/storage_backend_iscsi.c | 27 +++++-------------- src/storage/storage_backend_logical.c | 48 +++++++++------------------------- src/storage/storage_backend_mpath.c | 20 ++++---------- src/storage/storage_backend_rbd.c | 18 ++++--------- src/storage/storage_backend_scsi.c | 21 +++------------ src/storage/storage_backend_sheepdog.c | 4 +-- src/storage/storage_driver.c | 23 +++++----------- 10 files changed, 60 insertions(+), 184 deletions(-)
ACK. PEter

--- src/test/test_driver.c | 91 ++++++++++++++++---------------------------------- 1 file changed, 28 insertions(+), 63 deletions(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 80a84d5..a5dbdc3 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -170,18 +170,18 @@ testBuildCapabilities(virConnectPtr conn) { int i; if ((caps = virCapabilitiesNew(VIR_ARCH_I686, 0, 0)) == NULL) - goto no_memory; + goto error; if (virCapabilitiesAddHostFeature(caps, "pae") < 0) - goto no_memory; + goto error; if (virCapabilitiesAddHostFeature(caps ,"nonpae") < 0) - goto no_memory; + goto error; for (i = 0; i < privconn->numCells; i++) { virCapsHostNUMACellCPUPtr cpu_cells; if (VIR_ALLOC_N(cpu_cells, privconn->cells[i].numCpus) < 0) - goto no_memory; + goto error; memcpy(cpu_cells, privconn->cells[i].cpus, sizeof(*cpu_cells) * privconn->cells[i].numCpus); @@ -189,7 +189,7 @@ testBuildCapabilities(virConnectPtr conn) { if (virCapabilitiesAddHostNUMACell(caps, i, privconn->cells[i].numCpus, 0, cpu_cells) < 0) - goto no_memory; + goto error; } for (i = 0; i < ARRAY_CARDINALITY(guest_types); i++) { @@ -200,7 +200,7 @@ testBuildCapabilities(virConnectPtr conn) { NULL, 0, NULL)) == NULL) - goto no_memory; + goto error; if (virCapabilitiesAddGuestDomain(guest, "test", @@ -208,17 +208,17 @@ testBuildCapabilities(virConnectPtr conn) { NULL, 0, NULL) == NULL) - goto no_memory; + goto error; if (virCapabilitiesAddGuestFeature(guest, "pae", 1, 1) == NULL) - goto no_memory; + goto error; if (virCapabilitiesAddGuestFeature(guest ,"nonpae", 1, 1) == NULL) - goto no_memory; + goto error; } caps->host.nsecModels = 1; if (VIR_ALLOC_N(caps->host.secModels, caps->host.nsecModels) < 0) - goto no_memory; + goto error; if (VIR_STRDUP(caps->host.secModels[0].model, "testSecurity") < 0) goto error; @@ -227,8 +227,6 @@ testBuildCapabilities(virConnectPtr conn) { return caps; -no_memory: - virReportOOMError(); error: virObjectUnref(caps); return NULL; @@ -337,10 +335,8 @@ testDomainGenerateIfname(virDomainDefPtr domdef) { char *ifname; int found = 0; - if (virAsprintf(&ifname, "testnet%d", ifctr) < 0) { - virReportOOMError(); + if (virAsprintf(&ifname, "testnet%d", ifctr) < 0) return NULL; - } /* Generate network interface names */ for (i = 0; i < domdef->nnets; i++) { @@ -446,15 +442,11 @@ testDomainUpdateVCPUs(virConnectPtr conn, maxcpu = VIR_NODEINFO_MAXCPUS(privconn->nodeInfo); cpumaplen = VIR_CPU_MAPLEN(maxcpu); - if (VIR_REALLOC_N(privdata->vcpu_infos, nvcpus) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(privdata->vcpu_infos, nvcpus) < 0) goto cleanup; - } - if (VIR_REALLOC_N(privdata->cpumaps, nvcpus * cpumaplen) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(privdata->cpumaps, nvcpus * cpumaplen) < 0) goto cleanup; - } /* Set running VCPU and cpumap state */ if (clear_all) { @@ -534,10 +526,8 @@ static int testOpenDefault(virConnectPtr conn) { virNodeDeviceDefPtr nodedef = NULL; virNodeDeviceObjPtr nodeobj = NULL; - if (VIR_ALLOC(privconn) < 0) { - virReportOOMError(); + if (VIR_ALLOC(privconn) < 0) return VIR_DRV_OPEN_ERROR; - } if (virMutexInit(&privconn->lock) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot initialize mutex")); @@ -561,10 +551,8 @@ static int testOpenDefault(virConnectPtr conn) { } for (u = 0; u < 16; u++) { virBitmapPtr siblings = virBitmapNew(16); - if (!siblings) { - virReportOOMError(); + if (!siblings) goto error; - } ignore_value(virBitmapSetBit(siblings, u)); privconn->cells[u / 8].cpus[(u % 8)].id = u; privconn->cells[u / 8].cpus[(u % 8)].socket_id = u / 8; @@ -710,10 +698,8 @@ static int testOpenVolumesForPool(xmlDocPtr xml, virStorageVolDefPtr def = NULL; /* Find storage volumes */ - if (virAsprintf(&vol_xpath, "/node/pool[%d]/volume", poolidx) < 0) { - virReportOOMError(); + if (virAsprintf(&vol_xpath, "/node/pool[%d]/volume", poolidx) < 0) goto error; - } ret = virXPathNodeSet(vol_xpath, ctxt, &vols); VIR_FREE(vol_xpath); @@ -744,18 +730,14 @@ static int testOpenVolumesForPool(xmlDocPtr xml, } if (VIR_REALLOC_N(pool->volumes.objs, - pool->volumes.count+1) < 0) { - virReportOOMError(); + pool->volumes.count+1) < 0) goto error; - } if (def->target.path == NULL) { if (virAsprintf(&def->target.path, "%s/%s", pool->def->target.path, - def->name) == -1) { - virReportOOMError(); + def->name) == -1) goto error; - } } if (!def->key && VIR_STRDUP(def->key, def->target.path) < 0) @@ -790,10 +772,8 @@ static int testOpenFromFile(virConnectPtr conn, virInterfaceObjPtr iface; virDomainObjPtr dom; testConnPtr privconn; - if (VIR_ALLOC(privconn) < 0) { - virReportOOMError(); + if (VIR_ALLOC(privconn) < 0) return VIR_DRV_OPEN_ERROR; - } if (virMutexInit(&privconn->lock) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot initialize mutex")); @@ -1944,10 +1924,8 @@ testDomainRestoreFlags(virConnectPtr conn, "%s", _("length of metadata out of range")); goto cleanup; } - if (VIR_ALLOC_N(xml, len+1) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(xml, len+1) < 0) goto cleanup; - } if (saferead(fd, xml, len) != len) { virReportSystemError(errno, _("incomplete metdata in '%s'"), path); @@ -4176,9 +4154,8 @@ testConnectFindStoragePoolSources(virConnectPtr conn ATTRIBUTE_UNUSED, goto cleanup; } - if (virAsprintf(&ret, defaultPoolSourcesNetFSXML, - source->hosts[0].name) < 0) - virReportOOMError(); + ignore_value(virAsprintf(&ret, defaultPoolSourcesNetFSXML, + source->hosts[0].name)); break; default: @@ -4687,10 +4664,8 @@ testStoragePoolListAllVolumes(virStoragePoolPtr obj, goto cleanup; } - if (VIR_ALLOC_N(tmp_vols, pool->volumes.count + 1) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(tmp_vols, pool->volumes.count + 1) < 0) goto cleanup; - } for (i = 0; i < pool->volumes.count; i++) { if (!(vol = virGetStorageVol(obj->conn, pool->def->name, @@ -4882,17 +4857,13 @@ testStorageVolCreateXML(virStoragePoolPtr pool, } if (VIR_REALLOC_N(privpool->volumes.objs, - privpool->volumes.count+1) < 0) { - virReportOOMError(); + privpool->volumes.count+1) < 0) goto cleanup; - } if (virAsprintf(&privvol->target.path, "%s/%s", privpool->def->target.path, - privvol->name) == -1) { - virReportOOMError(); + privvol->name) == -1) goto cleanup; - } if (VIR_STRDUP(privvol->key, privvol->target.path) < 0) goto cleanup; @@ -4974,17 +4945,13 @@ testStorageVolCreateXMLFrom(virStoragePoolPtr pool, privpool->def->allocation); if (VIR_REALLOC_N(privpool->volumes.objs, - privpool->volumes.count+1) < 0) { - virReportOOMError(); + privpool->volumes.count+1) < 0) goto cleanup; - } if (virAsprintf(&privvol->target.path, "%s/%s", privpool->def->target.path, - privvol->name) == -1) { - virReportOOMError(); + privvol->name) == -1) goto cleanup; - } if (VIR_STRDUP(privvol->key, privvol->target.path) < 0) goto cleanup; @@ -5721,10 +5688,8 @@ testNodeGetCPUMap(virConnectPtr conn, testDriverLock(privconn); if (cpumap) { - if (VIR_ALLOC_N(*cpumap, 1) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(*cpumap, 1) < 0) goto cleanup; - } *cpumap[0] = 0x15; } -- 1.8.1.5

On 07/04/2013 02:06 PM, Michal Privoznik wrote:
--- src/test/test_driver.c | 91 ++++++++++++++++---------------------------------- 1 file changed, 28 insertions(+), 63 deletions(-)
ACK, Martin

--- src/uml/uml_conf.c | 28 +++++++--------------------- src/uml/uml_driver.c | 36 +++++++++--------------------------- 2 files changed, 16 insertions(+), 48 deletions(-) diff --git a/src/uml/uml_conf.c b/src/uml/uml_conf.c index 38dcfbb..e9d3ddb 100644 --- a/src/uml/uml_conf.c +++ b/src/uml/uml_conf.c @@ -285,32 +285,24 @@ umlBuildCommandLineChr(virDomainChrDefPtr def, switch (def->source.type) { case VIR_DOMAIN_CHR_TYPE_NULL: - if (virAsprintf(&ret, "%s%d=null", dev, def->target.port) < 0) { - virReportOOMError(); + if (virAsprintf(&ret, "%s%d=null", dev, def->target.port) < 0) return NULL; - } break; case VIR_DOMAIN_CHR_TYPE_PTY: - if (virAsprintf(&ret, "%s%d=pts", dev, def->target.port) < 0) { - virReportOOMError(); + if (virAsprintf(&ret, "%s%d=pts", dev, def->target.port) < 0) return NULL; - } break; case VIR_DOMAIN_CHR_TYPE_DEV: if (virAsprintf(&ret, "%s%d=tty:%s", dev, def->target.port, - def->source.data.file.path) < 0) { - virReportOOMError(); + def->source.data.file.path) < 0) return NULL; - } break; case VIR_DOMAIN_CHR_TYPE_STDIO: - if (virAsprintf(&ret, "%s%d=fd:0,fd:1", dev, def->target.port) < 0) { - virReportOOMError(); + if (virAsprintf(&ret, "%s%d=fd:0,fd:1", dev, def->target.port) < 0) return NULL; - } break; case VIR_DOMAIN_CHR_TYPE_TCP: @@ -321,10 +313,8 @@ umlBuildCommandLineChr(virDomainChrDefPtr def, } if (virAsprintf(&ret, "%s%d=port:%s", dev, def->target.port, - def->source.data.tcp.service) < 0) { - virReportOOMError(); + def->source.data.tcp.service) < 0) return NULL; - } break; case VIR_DOMAIN_CHR_TYPE_FILE: @@ -339,7 +329,6 @@ umlBuildCommandLineChr(virDomainChrDefPtr def, return NULL; } if (virAsprintf(&ret, "%s%d=null,fd:%d", dev, def->target.port, fd_out) < 0) { - virReportOOMError(); VIR_FORCE_CLOSE(fd_out); return NULL; } @@ -440,7 +429,7 @@ virCommandPtr umlBuildCommandLine(virConnectPtr conn, ret = umlBuildCommandLineChr(chr, "con", cmd); if (!ret) if (virAsprintf(&ret, "con%d=none", i) < 0) - goto no_memory; + goto error; virCommandAddArg(cmd, ret); VIR_FREE(ret); } @@ -455,7 +444,7 @@ virCommandPtr umlBuildCommandLine(virConnectPtr conn, ret = umlBuildCommandLineChr(chr, "ssl", cmd); if (!ret) if (virAsprintf(&ret, "ssl%d=none", i) < 0) - goto no_memory; + goto error; virCommandAddArg(cmd, ret); VIR_FREE(ret); @@ -481,10 +470,7 @@ virCommandPtr umlBuildCommandLine(virConnectPtr conn, return cmd; - no_memory: - virReportOOMError(); error: - virCommandFree(cmd); return NULL; } diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c index df98eb8..eea68db 100644 --- a/src/uml/uml_driver.c +++ b/src/uml/uml_driver.c @@ -239,10 +239,8 @@ umlIdentifyOneChrPTY(struct uml_driver *driver, char *cmd; char *res = NULL; int retries = 0; - if (virAsprintf(&cmd, "config %s%d", dev, def->target.port) < 0) { - virReportOOMError(); + if (virAsprintf(&cmd, "config %s%d", dev, def->target.port) < 0) return -1; - } requery: if (umlMonitorCommand(driver, dom, cmd, &res) < 0) return -1; @@ -793,10 +791,8 @@ static int umlReadPidFile(struct uml_driver *driver, vm->pid = -1; if (virAsprintf(&pidfile, "%s/%s/pid", - driver->monitorDir, vm->def->name) < 0) { - virReportOOMError(); + driver->monitorDir, vm->def->name) < 0) return -1; - } reopen: if (!(file = fopen(pidfile, "r"))) { @@ -835,10 +831,8 @@ static int umlMonitorAddress(const struct uml_driver *driver, int retval = 0; if (virAsprintf(&sockname, "%s/%s/mconsole", - driver->monitorDir, vm->def->name) < 0) { - virReportOOMError(); + driver->monitorDir, vm->def->name) < 0) return -1; - } memset(addr, 0, sizeof(*addr)); addr->sun_family = AF_UNIX; @@ -974,10 +968,8 @@ static int umlMonitorCommand(const struct uml_driver *driver, goto error; } - if (VIR_REALLOC_N(retdata, retlen + res.length) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(retdata, retlen + res.length) < 0) goto error; - } memcpy(retdata + retlen, res.data, res.length); retlen += res.length - 1; retdata[retlen] = '\0'; @@ -1057,10 +1049,8 @@ static int umlStartVMDaemon(virConnectPtr conn, } if (virAsprintf(&logfile, "%s/%s.log", - driver->logDir, vm->def->name) < 0) { - virReportOOMError(); + driver->logDir, vm->def->name) < 0) return -1; - } if ((logfd = open(logfile, O_CREAT | O_TRUNC | O_WRONLY, S_IRUSR | S_IWUSR)) < 0) { @@ -1095,10 +1085,8 @@ static int umlStartVMDaemon(virConnectPtr conn, for (i = 0; i < vm->def->nconsoles; i++) { VIR_FREE(vm->def->consoles[i]->info.alias); - if (virAsprintf(&vm->def->consoles[i]->info.alias, "console%zu", i) < 0) { - virReportOOMError(); + if (virAsprintf(&vm->def->consoles[i]->info.alias, "console%zu", i) < 0) goto cleanup; - } } virCommandWriteArgLog(cmd, logfd); @@ -2145,18 +2133,14 @@ static int umlDomainAttachUmlDisk(struct uml_driver *driver, goto error; } - if (virAsprintf(&cmd, "config %s=%s", disk->dst, disk->src) < 0) { - virReportOOMError(); + if (virAsprintf(&cmd, "config %s=%s", disk->dst, disk->src) < 0) return -1; - } if (umlMonitorCommand(driver, vm, cmd, &reply) < 0) goto error; - if (VIR_REALLOC_N(vm->def->disks, vm->def->ndisks+1) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(vm->def->disks, vm->def->ndisks+1) < 0) goto error; - } virDomainDiskInsertPreAlloced(vm->def, disk); @@ -2274,10 +2258,8 @@ static int umlDomainDetachUmlDisk(struct uml_driver *driver, detach = vm->def->disks[i]; - if (virAsprintf(&cmd, "remove %s", detach->dst) < 0) { - virReportOOMError(); + if (virAsprintf(&cmd, "remove %s", detach->dst) < 0) return -1; - } if (umlMonitorCommand(driver, vm, cmd, &reply) < 0) goto cleanup; -- 1.8.1.5

On 07/04/13 14:06, Michal Privoznik wrote:
--- src/uml/uml_conf.c | 28 +++++++--------------------- src/uml/uml_driver.c | 36 +++++++++--------------------------- 2 files changed, 16 insertions(+), 48 deletions(-)
diff --git a/src/uml/uml_conf.c b/src/uml/uml_conf.c index 38dcfbb..e9d3ddb 100644 --- a/src/uml/uml_conf.c +++ b/src/uml/uml_conf.c
ACK, Peter

--- src/util/iohelper.c | 4 +- src/util/virauth.c | 6 +-- src/util/virauthconfig.c | 16 ++---- src/util/vircgroup.c | 11 +--- src/util/vircommand.c | 13 ++--- src/util/virconf.c | 10 +--- src/util/virdnsmasq.c | 53 +++++++------------ src/util/vireventpoll.c | 4 +- src/util/virfile.c | 34 +++---------- src/util/virhash.c | 11 +--- src/util/viridentity.c | 4 +- src/util/virinitctl.c | 4 +- src/util/viriptables.c | 11 ++-- src/util/virkeyfile.c | 4 +- src/util/virlockspace.c | 37 ++++---------- src/util/virlog.c | 2 +- src/util/virnetdev.c | 45 ++++------------ src/util/virnetdevbandwidth.c | 21 ++------ src/util/virnetdevbridge.c | 8 +-- src/util/virnetdevmacvlan.c | 6 +-- src/util/virnetdevopenvswitch.c | 18 +++---- src/util/virnetdevtap.c | 8 +-- src/util/virnetdevveth.c | 8 +-- src/util/virnetdevvlan.c | 4 +- src/util/virnetdevvportprofile.c | 4 +- src/util/virnetlink.c | 8 +-- src/util/virobject.c | 8 +-- src/util/virpci.c | 96 ++++++++--------------------------- src/util/virportallocator.c | 1 - src/util/virprocess.c | 17 ++----- src/util/virrandom.c | 9 +--- src/util/virscsi.c | 28 +++------- src/util/virsexpr.c | 4 +- src/util/virsocketaddr.c | 6 +-- src/util/virstoragefile.c | 32 +++--------- src/util/virstring.c | 8 ++- src/util/virsysinfo.c | 22 +++----- src/util/virthreadpool.c | 21 ++------ src/util/virtime.c | 8 +-- src/util/virtpm.c | 4 +- src/util/virtypedparam.c | 68 +++++++------------------ src/util/viruri.c | 12 ++--- src/util/virusb.c | 13 ++--- src/util/virutil.c | 107 +++++++++------------------------------ src/util/virxml.c | 1 - 45 files changed, 211 insertions(+), 608 deletions(-) diff --git a/src/util/iohelper.c b/src/util/iohelper.c index 33ba852..9610063 100644 --- a/src/util/iohelper.c +++ b/src/util/iohelper.c @@ -95,10 +95,8 @@ runIO(const char *path, int fd, int oflags, unsigned long long length) } buf = base; #else - if (VIR_ALLOC_N(buf, buflen + alignMask) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(buf, buflen + alignMask) < 0) goto cleanup; - } base = buf; buf = (char *) (((intptr_t) base + alignMask) & ~alignMask); #endif diff --git a/src/util/virauth.c b/src/util/virauth.c index cd22e89..693efbd 100644 --- a/src/util/virauth.c +++ b/src/util/virauth.c @@ -73,7 +73,7 @@ int virAuthGetConfigFilePath(virConnectPtr conn, goto cleanup; if (virAsprintf(path, "%s/auth.conf", userdir) < 0) - goto no_memory; + goto cleanup; VIR_DEBUG("Checking for readability of '%s'", *path); if (access(*path, R_OK) == 0) @@ -98,10 +98,6 @@ cleanup: VIR_FREE(userdir); return ret; - -no_memory: - virReportOOMError(); - goto cleanup; } diff --git a/src/util/virauthconfig.c b/src/util/virauthconfig.c index c9f6046..808d1cb 100644 --- a/src/util/virauthconfig.c +++ b/src/util/virauthconfig.c @@ -42,10 +42,8 @@ virAuthConfigPtr virAuthConfigNew(const char *path) { virAuthConfigPtr auth; - if (VIR_ALLOC(auth) < 0) { - virReportOOMError(); + if (VIR_ALLOC(auth) < 0) goto error; - } if (VIR_STRDUP(auth->path, path) < 0) goto error; @@ -70,10 +68,8 @@ virAuthConfigPtr virAuthConfigNewData(const char *path, { virAuthConfigPtr auth; - if (VIR_ALLOC(auth) < 0) { - virReportOOMError(); + if (VIR_ALLOC(auth) < 0) goto error; - } if (VIR_STRDUP(auth->path, path) < 0) goto error; @@ -121,10 +117,8 @@ int virAuthConfigLookup(virAuthConfigPtr auth, if (!hostname) hostname = "localhost"; - if (virAsprintf(&authgroup, "auth-%s-%s", service, hostname) < 0) { - virReportOOMError(); + if (virAsprintf(&authgroup, "auth-%s-%s", service, hostname) < 0) goto cleanup; - } if (!virKeyFileHasGroup(auth->keyfile, authgroup)) { ret = 0; @@ -138,10 +132,8 @@ int virAuthConfigLookup(virAuthConfigPtr auth, goto cleanup; } - if (virAsprintf(&credgroup, "credentials-%s", authcred) < 0) { - virReportOOMError(); + if (virAsprintf(&credgroup, "credentials-%s", authcred) < 0) goto cleanup; - } if (!virKeyFileHasGroup(auth->keyfile, credgroup)) { virReportError(VIR_ERR_CONF_SYNTAX, diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 13fd162..f7f05fd 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -1204,7 +1204,6 @@ static int virCgroupSetPartitionSuffix(const char *path, char **res) if (VIR_REALLOC_N(tokens[i], strlen(tokens[i]) + strlen(".partition") + 1) < 0) { ret = -ENOMEM; - virReportOOMError(); goto cleanup; } strcat(tokens[i], ".partition"); @@ -1212,8 +1211,6 @@ static int virCgroupSetPartitionSuffix(const char *path, char **res) ret = virCgroupPartitionEscape(&(tokens[i])); if (ret < 0) { - if (ret == -ENOMEM) - virReportOOMError(); goto cleanup; } } @@ -2592,10 +2589,8 @@ int virCgroupIsolateMount(virCgroupPtr group, const char *oldroot, } if (virAsprintf(&opts, - "mode=755,size=65536%s", mountopts) < 0) { - virReportOOMError(); + "mode=755,size=65536%s", mountopts) < 0) goto cleanup; - } if (mount("tmpfs", root, "tmpfs", MS_NOSUID|MS_NODEV|MS_NOEXEC, opts) < 0) { virReportSystemError(errno, @@ -2613,10 +2608,8 @@ int virCgroupIsolateMount(virCgroupPtr group, const char *oldroot, if (virAsprintf(&src, "%s%s%s", oldroot, group->controllers[i].mountPoint, - group->controllers[i].placement) < 0) { - virReportOOMError(); + group->controllers[i].placement) < 0) goto cleanup; - } VIR_DEBUG("Create mount point '%s'", group->controllers[i].mountPoint); if (virFileMakePath(group->controllers[i].mountPoint) < 0) { diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 6e2eb1e..7863d5d 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -1840,17 +1840,13 @@ virCommandProcessIO(virCommandPtr cmd) * results accumulated over a prior run of the same command. */ if (cmd->outbuf) { outfd = cmd->outfd; - if (VIR_REALLOC_N(*cmd->outbuf, 1) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(*cmd->outbuf, 1) < 0) ret = -1; - } } if (cmd->errbuf) { errfd = cmd->errfd; - if (VIR_REALLOC_N(*cmd->errbuf, 1) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(*cmd->errbuf, 1) < 0) ret = -1; - } } if (ret == -1) goto cleanup; @@ -1924,10 +1920,8 @@ virCommandProcessIO(virCommandPtr cmd) else errfd = -1; } else { - if (VIR_REALLOC_N(*buf, *len + done + 1) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(*buf, *len + done + 1) < 0) goto cleanup; - } memcpy(*buf + *len, data, done); *len += done; } @@ -2471,7 +2465,6 @@ int virCommandHandshakeWait(virCommandPtr cmd) char *msg; ssize_t len; if (VIR_ALLOC_N(msg, 1024) < 0) { - virReportOOMError(); VIR_FORCE_CLOSE(cmd->handshakeWait[0]); return -1; } diff --git a/src/util/virconf.c b/src/util/virconf.c index ef76369..9952f3f 100644 --- a/src/util/virconf.c +++ b/src/util/virconf.c @@ -173,10 +173,8 @@ virConfNew(void) { virConfPtr ret; - if (VIR_ALLOC(ret) < 0) { - virReportOOMError(); + if (VIR_ALLOC(ret) < 0) return NULL; - } ret->filename = NULL; ret->flags = 0; @@ -225,10 +223,8 @@ virConfAddEntry(virConfPtr conf, char *name, virConfValuePtr value, char *comm) if ((comm == NULL) && (name == NULL)) return NULL; - if (VIR_ALLOC(ret) < 0) { - virReportOOMError(); + if (VIR_ALLOC(ret) < 0) return NULL; - } ret->name = name; ret->value = value; @@ -529,7 +525,6 @@ virConfParseValue(virConfParserCtxtPtr ctxt) return NULL; } if (VIR_ALLOC(ret) < 0) { - virReportOOMError(); virConfFreeList(lst); VIR_FREE(str); return NULL; @@ -883,7 +878,6 @@ virConfSetValue(virConfPtr conf, if (!cur) { if (VIR_ALLOC(cur) < 0) { - virReportOOMError(); virConfFreeValue(value); return -1; } diff --git a/src/util/virdnsmasq.c b/src/util/virdnsmasq.c index d37ee3e..9bbf76a 100644 --- a/src/util/virdnsmasq.c +++ b/src/util/virdnsmasq.c @@ -112,11 +112,11 @@ addnhostsAdd(dnsmasqAddnHostsfile *addnhostsfile, if (idx < 0) { if (VIR_REALLOC_N(addnhostsfile->hosts, addnhostsfile->nhosts + 1) < 0) - goto alloc_error; + goto error; idx = addnhostsfile->nhosts; if (VIR_ALLOC(addnhostsfile->hosts[idx].hostnames) < 0) - goto alloc_error; + goto error; if (VIR_STRDUP(addnhostsfile->hosts[idx].ip, ipstr) < 0) goto error; @@ -126,7 +126,7 @@ addnhostsAdd(dnsmasqAddnHostsfile *addnhostsfile, } if (VIR_REALLOC_N(addnhostsfile->hosts[idx].hostnames, addnhostsfile->hosts[idx].nhostnames + 1) < 0) - goto alloc_error; + goto error; if (VIR_STRDUP(addnhostsfile->hosts[idx].hostnames[addnhostsfile->hosts[idx].nhostnames], name) < 0) @@ -138,8 +138,6 @@ addnhostsAdd(dnsmasqAddnHostsfile *addnhostsfile, return 0; - alloc_error: - virReportOOMError(); error: VIR_FREE(ipstr); return -1; @@ -151,19 +149,15 @@ addnhostsNew(const char *name, { dnsmasqAddnHostsfile *addnhostsfile; - if (VIR_ALLOC(addnhostsfile) < 0) { - virReportOOMError(); + if (VIR_ALLOC(addnhostsfile) < 0) return NULL; - } addnhostsfile->hosts = NULL; addnhostsfile->nhosts = 0; if (virAsprintf(&addnhostsfile->path, "%s/%s.%s", config_dir, name, - DNSMASQ_ADDNHOSTSFILE_SUFFIX) < 0) { - virReportOOMError(); + DNSMASQ_ADDNHOSTSFILE_SUFFIX) < 0) goto error; - } return addnhostsfile; @@ -311,7 +305,7 @@ hostsfileAdd(dnsmasqHostsfile *hostsfile, { char *ipstr = NULL; if (VIR_REALLOC_N(hostsfile->hosts, hostsfile->nhosts + 1) < 0) - goto alloc_error; + goto error; if (!(ipstr = virSocketAddrFormat(ip))) return -1; @@ -321,28 +315,28 @@ hostsfileAdd(dnsmasqHostsfile *hostsfile, if (name && id) { if (virAsprintf(&hostsfile->hosts[hostsfile->nhosts].host, "id:%s,%s,[%s]", id, name, ipstr) < 0) - goto alloc_error; + goto error; } else if (name && !id) { if (virAsprintf(&hostsfile->hosts[hostsfile->nhosts].host, "%s,[%s]", name, ipstr) < 0) - goto alloc_error; + goto error; } else if (!name && id) { if (virAsprintf(&hostsfile->hosts[hostsfile->nhosts].host, "id:%s,[%s]", id, ipstr) < 0) - goto alloc_error; + goto error; } } else if (name && mac) { if (virAsprintf(&hostsfile->hosts[hostsfile->nhosts].host, "%s,%s,%s", mac, ipstr, name) < 0) - goto alloc_error; + goto error; } else if (name && !mac){ if (virAsprintf(&hostsfile->hosts[hostsfile->nhosts].host, "%s,%s", name, ipstr) < 0) - goto alloc_error; + goto error; } else { if (virAsprintf(&hostsfile->hosts[hostsfile->nhosts].host, "%s,%s", mac, ipstr) < 0) - goto alloc_error; + goto error; } VIR_FREE(ipstr); @@ -350,8 +344,7 @@ hostsfileAdd(dnsmasqHostsfile *hostsfile, return 0; - alloc_error: - virReportOOMError(); + error: VIR_FREE(ipstr); return -1; } @@ -362,19 +355,15 @@ hostsfileNew(const char *name, { dnsmasqHostsfile *hostsfile; - if (VIR_ALLOC(hostsfile) < 0) { - virReportOOMError(); + if (VIR_ALLOC(hostsfile) < 0) return NULL; - } hostsfile->hosts = NULL; hostsfile->nhosts = 0; if (virAsprintf(&hostsfile->path, "%s/%s.%s", config_dir, name, - DNSMASQ_HOSTSFILE_SUFFIX) < 0) { - virReportOOMError(); + DNSMASQ_HOSTSFILE_SUFFIX) < 0) goto error; - } return hostsfile; @@ -466,10 +455,8 @@ dnsmasqContextNew(const char *network_name, { dnsmasqContext *ctx; - if (VIR_ALLOC(ctx) < 0) { - virReportOOMError(); + if (VIR_ALLOC(ctx) < 0) return NULL; - } if (VIR_STRDUP(ctx->config_dir, config_dir) < 0) goto error; @@ -772,10 +759,8 @@ dnsmasqCapsRefreshInternal(dnsmasqCapsPtr caps, bool force) goto cleanup; } - if (virAsprintf(&complete, "%s\n%s", version, help) < 0) { - virReportOOMError(); + if (virAsprintf(&complete, "%s\n%s", version, help) < 0) goto cleanup; - } ret = dnsmasqCapsSetFromBuffer(caps, complete); @@ -796,10 +781,8 @@ dnsmasqCapsNewEmpty(const char *binaryPath) return NULL; if (!(caps = virObjectNew(dnsmasqCapsClass))) return NULL; - if (!(caps->flags = virBitmapNew(DNSMASQ_CAPS_LAST))) { - virReportOOMError(); + if (!(caps->flags = virBitmapNew(DNSMASQ_CAPS_LAST))) goto error; - } if (VIR_STRDUP(caps->binaryPath, binaryPath ? binaryPath : DNSMASQ) < 0) goto error; return caps; diff --git a/src/util/vireventpoll.c b/src/util/vireventpoll.c index cc29dcb..6e54389 100644 --- a/src/util/vireventpoll.c +++ b/src/util/vireventpoll.c @@ -379,10 +379,8 @@ static struct pollfd *virEventPollMakePollFDs(int *nfds) { } /* Setup the poll file handle data structs */ - if (VIR_ALLOC_N(fds, *nfds) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(fds, *nfds) < 0) return NULL; - } *nfds = 0; for (i = 0; i < eventLoop.handlesCount; i++) { diff --git a/src/util/virfile.c b/src/util/virfile.c index ad01845..feb351a 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -211,10 +211,8 @@ virFileWrapperFdNew(int *fd, const char *name, unsigned int flags) return NULL; } - if (VIR_ALLOC(ret) < 0) { - virReportOOMError(); + if (VIR_ALLOC(ret) < 0) return NULL; - } mode = fcntl(*fd, F_GETFL); @@ -426,10 +424,8 @@ virFileRewrite(const char *path, int fd = -1; int ret = -1; - if (virAsprintf(&newfile, "%s.new", path) < 0) { - virReportOOMError(); + if (virAsprintf(&newfile, "%s.new", path) < 0) goto cleanup; - } if ((fd = open(newfile, O_WRONLY | O_CREAT | O_TRUNC, mode)) < 0) { virReportSystemError(errno, _("cannot create file '%s'"), @@ -553,10 +549,8 @@ static int virFileLoopDeviceOpen(char **dev_name) if (!STRPREFIX(de->d_name, "loop")) continue; - if (virAsprintf(&looppath, "/dev/%s", de->d_name) < 0) { - virReportOOMError(); + if (virAsprintf(&looppath, "/dev/%s", de->d_name) < 0) goto cleanup; - } VIR_DEBUG("Checking up on device %s", looppath); if ((fd = open(looppath, O_RDWR)) < 0) { @@ -666,10 +660,8 @@ virFileNBDDeviceIsBusy(const char *devname) int ret = -1; if (virAsprintf(&path, SYSFS_BLOCK_DIR "/%s/pid", - devname) < 0) { - virReportOOMError(); + devname) < 0) return -1; - } if (access(path, F_OK) < 0) { if (errno == ENOENT) @@ -709,10 +701,8 @@ virFileNBDDeviceFindUnused(void) if (rv < 0) goto cleanup; if (rv == 0) { - if (virAsprintf(&ret, "/dev/%s", de->d_name) < 0) { - virReportOOMError(); + if (virAsprintf(&ret, "/dev/%s", de->d_name) < 0) goto cleanup; - } goto cleanup; } } @@ -847,10 +837,8 @@ int virFileDeleteTree(const char *dir) continue; if (virAsprintf(&filepath, "%s/%s", - dir, de->d_name) < 0) { - virReportOOMError(); + dir, de->d_name) < 0) goto cleanup; - } if (lstat(filepath, &sb) < 0) { virReportSystemError(errno, _("Cannot access '%s'"), @@ -2064,15 +2052,9 @@ virFileBuildPath(const char *dir, const char *name, const char *ext) char *path; if (ext == NULL) { - if (virAsprintf(&path, "%s/%s", dir, name) < 0) { - virReportOOMError(); - return NULL; - } + ignore_value(virAsprintf(&path, "%s/%s", dir, name)); } else { - if (virAsprintf(&path, "%s/%s%s", dir, name, ext) < 0) { - virReportOOMError(); - return NULL; - } + ignore_value(virAsprintf(&path, "%s/%s%s", dir, name, ext)); } return path; diff --git a/src/util/virhash.c b/src/util/virhash.c index 7185016..41c5920 100644 --- a/src/util/virhash.c +++ b/src/util/virhash.c @@ -129,10 +129,8 @@ virHashTablePtr virHashCreateFull(ssize_t size, if (size <= 0) size = 256; - if (VIR_ALLOC(table) < 0) { - virReportOOMError(); + if (VIR_ALLOC(table) < 0) return NULL; - } table->seed = virRandomBits(32); table->size = size; @@ -144,7 +142,6 @@ virHashTablePtr virHashCreateFull(ssize_t size, table->keyFree = keyFree; if (VIR_ALLOC_N(table->table, size) < 0) { - virReportOOMError(); VIR_FREE(table); return NULL; } @@ -204,7 +201,6 @@ virHashGrow(virHashTablePtr table, size_t size) return -1; if (VIR_ALLOC_N(table->table, size) < 0) { - virReportOOMError(); table->table = oldtable; return -1; } @@ -302,7 +298,6 @@ virHashAddOrUpdateEntry(virHashTablePtr table, const void *name, } if (VIR_ALLOC(entry) < 0 || !(new_name = table->keyCopy(name))) { - virReportOOMError(); VIR_FREE(entry); return -1; } @@ -673,10 +668,8 @@ virHashKeyValuePairPtr virHashGetItems(virHashTablePtr table, if (numElems < 0) return NULL; - if (VIR_ALLOC_N(iter.sortArray, numElems + 1)) { - virReportOOMError(); + if (VIR_ALLOC_N(iter.sortArray, numElems + 1)) return NULL; - } virHashForEach(table, virHashGetKeysIterator, &iter); diff --git a/src/util/viridentity.c b/src/util/viridentity.c index 6d93d0f..781f660 100644 --- a/src/util/viridentity.c +++ b/src/util/viridentity.c @@ -142,10 +142,8 @@ virIdentityPtr virIdentityGetSystem(void) char *processid = NULL; if (virAsprintf(&processid, "%llu", - (unsigned long long)getpid()) < 0) { - virReportOOMError(); + (unsigned long long)getpid()) < 0) goto cleanup; - } if (!(username = virGetUserName(getuid()))) goto cleanup; diff --git a/src/util/virinitctl.c b/src/util/virinitctl.c index b980952..64bc23a 100644 --- a/src/util/virinitctl.c +++ b/src/util/virinitctl.c @@ -132,10 +132,8 @@ int virInitctlSetRunLevel(virInitctlRunLevel level, req.runlevel = '0' + level; if (vroot) { - if (virAsprintf(&path, "%s/%s", vroot, VIR_INITCTL_FIFO) < 0) { - virReportOOMError(); + if (virAsprintf(&path, "%s/%s", vroot, VIR_INITCTL_FIFO) < 0) return -1; - } } else { if (VIR_STRDUP(path, VIR_INITCTL_FIFO) < 0) return -1; diff --git a/src/util/viriptables.c b/src/util/viriptables.c index 63a8031..0f57d66 100644 --- a/src/util/viriptables.c +++ b/src/util/viriptables.c @@ -266,8 +266,7 @@ static char *iptablesFormatNetwork(virSocketAddr *netaddr, if (!netstr) return NULL; - if (virAsprintf(&ret, "%s/%d", netstr, prefix) < 0) - virReportOOMError(); + ignore_value(virAsprintf(&ret, "%s/%d", netstr, prefix)); VIR_FREE(netstr); return ret; @@ -738,10 +737,8 @@ iptablesForwardMasquerade(virSocketAddr *netaddr, if (port->start < port->end && port->end < 65536) { if (virAsprintf(&portRangeStr, ":%u-%u", - port->start, port->end) < 0) { - virReportOOMError(); + port->start, port->end) < 0) goto cleanup; - } } else { virReportError(VIR_ERR_INTERNAL_ERROR, _("Invalid port range '%u-%u'."), @@ -761,10 +758,8 @@ iptablesForwardMasquerade(virSocketAddr *netaddr, portRangeStr ? portRangeStr : ""); } - if (r < 0) { - virReportOOMError(); + if (r < 0) goto cleanup; - } virCommandAddArgList(cmd, "--jump", "SNAT", "--to-source", natRangeStr, NULL); diff --git a/src/util/virkeyfile.c b/src/util/virkeyfile.c index b6220bc..0596d4b 100644 --- a/src/util/virkeyfile.c +++ b/src/util/virkeyfile.c @@ -282,10 +282,8 @@ virKeyFilePtr virKeyFileNew(void) { virKeyFilePtr conf; - if (VIR_ALLOC(conf) < 0) { - virReportOOMError(); + if (VIR_ALLOC(conf) < 0) goto error; - } if (!(conf->groups = virHashCreate(10, virKeyFileEntryFree))) diff --git a/src/util/virlockspace.c b/src/util/virlockspace.c index 97830cc..afb1abb 100644 --- a/src/util/virlockspace.c +++ b/src/util/virlockspace.c @@ -64,16 +64,10 @@ static char *virLockSpaceGetResourcePath(virLockSpacePtr lockspace, const char *resname) { char *ret; - if (lockspace->dir) { - if (virAsprintf(&ret, "%s/%s", lockspace->dir, resname) < 0) { - virReportOOMError(); - return NULL; - } - } else { - if (VIR_STRDUP(ret, resname) < 0) - return NULL; - } - + if (lockspace->dir) + ignore_value(virAsprintf(&ret, "%s/%s", lockspace->dir, resname)); + else + ignore_value(VIR_STRDUP(ret, resname)); return ret; } @@ -134,7 +128,7 @@ virLockSpaceResourceNew(virLockSpacePtr lockspace, goto error; if (!(res->path = virLockSpaceGetResourcePath(lockspace, resname))) - goto no_memory; + goto error; if (flags & VIR_LOCK_SPACE_ACQUIRE_AUTOCREATE) { while (1) { @@ -223,14 +217,12 @@ virLockSpaceResourceNew(virLockSpacePtr lockspace, res->lockHeld = true; if (VIR_EXPAND_N(res->owners, res->nOwners, 1) < 0) - goto no_memory; + goto error; res->owners[res->nOwners-1] = owner; return res; -no_memory: - virReportOOMError(); error: virLockSpaceResourceFree(res); return NULL; @@ -343,10 +335,8 @@ virLockSpacePtr virLockSpaceNewPostExecRestart(virJSONValuePtr object) size_t j; int m; - if (VIR_ALLOC(res) < 0) { - virReportOOMError(); + if (VIR_ALLOC(res) < 0) goto error; - } res->fd = -1; if (!(tmp = virJSONValueObjectGetString(child, "name"))) { @@ -412,7 +402,6 @@ virLockSpacePtr virLockSpaceNewPostExecRestart(virJSONValuePtr object) res->nOwners = m; if (VIR_ALLOC_N(res->owners, res->nOwners) < 0) { - virReportOOMError(); virLockSpaceResourceFree(res); goto error; } @@ -451,10 +440,8 @@ virJSONValuePtr virLockSpacePreExecRestart(virLockSpacePtr lockspace) virJSONValuePtr resources; virHashKeyValuePairPtr pairs = NULL, tmp; - if (!object) { - virReportOOMError(); + if (!object) return NULL; - } virMutexLock(&lockspace->lock); @@ -477,10 +464,8 @@ virJSONValuePtr virLockSpacePreExecRestart(virLockSpacePtr lockspace) virJSONValuePtr owners = NULL; size_t i; - if (!child) { - virReportOOMError(); + if (!child) goto error; - } if (virJSONValueArrayAppend(resources, child) < 0) { virJSONValueFree(child); @@ -641,10 +626,8 @@ int virLockSpaceAcquireResource(virLockSpacePtr lockspace, if ((res->flags & VIR_LOCK_SPACE_ACQUIRE_SHARED) && (flags & VIR_LOCK_SPACE_ACQUIRE_SHARED)) { - if (VIR_EXPAND_N(res->owners, res->nOwners, 1) < 0) { - virReportOOMError(); + if (VIR_EXPAND_N(res->owners, res->nOwners, 1) < 0) goto cleanup; - } res->owners[res->nOwners-1] = owner; goto done; diff --git a/src/util/virlog.c b/src/util/virlog.c index 064f8e8..1dcbd61 100644 --- a/src/util/virlog.c +++ b/src/util/virlog.c @@ -563,7 +563,7 @@ virLogDefineFilter(const char *match, goto cleanup; } i = virLogNbFilters; - if (VIR_REALLOC_N(virLogFilters, virLogNbFilters + 1)) { + if (VIR_REALLOC_N_QUIET(virLogFilters, virLogNbFilters + 1)) { i = -1; VIR_FREE(mdup); goto cleanup; diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index 5e8dffb..1b76737 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -315,10 +315,8 @@ virNetDevReplaceMacAddress(const char *linkdev, if (virAsprintf(&path, "%s/%s", stateDir, - linkdev) < 0) { - virReportOOMError(); + linkdev) < 0) return -1; - } virMacAddrFormat(&oldmac, macstr); if (virFileWriteStr(path, macstr, O_CREAT|O_TRUNC|O_WRONLY) < 0) { virReportSystemError(errno, _("Unable to preserve mac for %s"), @@ -352,10 +350,8 @@ virNetDevRestoreMacAddress(const char *linkdev, if (virAsprintf(&path, "%s/%s", stateDir, - linkdev) < 0) { - virReportOOMError(); + linkdev) < 0) return -1; - } if (virFileReadAll(path, VIR_MAC_STRING_BUFLEN, &macstr) < 0) return -1; @@ -505,10 +501,8 @@ int virNetDevSetNamespace(const char *ifname, pid_t pidInNs) "ip", "link", "set", ifname, "netns", NULL, NULL }; - if (virAsprintf(&pid, "%lld", (long long) pidInNs) == -1) { - virReportOOMError(); + if (virAsprintf(&pid, "%lld", (long long) pidInNs) == -1) return -1; - } argv[5] = pid; rc = virRun(argv, NULL); @@ -1056,13 +1050,7 @@ virNetDevSysfsFile(char **pf_sysfs_device_link, const char *ifname, const char *file) { - if (virAsprintf(pf_sysfs_device_link, NET_SYSFS "%s/%s", - ifname, file) < 0) { - virReportOOMError(); - return -1; - } - - return 0; + return virAsprintf(pf_sysfs_device_link, NET_SYSFS "%s/%s", ifname, file); } static int @@ -1070,13 +1058,8 @@ virNetDevSysfsDeviceFile(char **pf_sysfs_device_link, const char *ifname, const char *file) { - if (virAsprintf(pf_sysfs_device_link, NET_SYSFS "%s/device/%s", - ifname, file) < 0) { - virReportOOMError(); - return -1; - } - - return 0; + return virAsprintf(pf_sysfs_device_link, NET_SYSFS "%s/device/%s", + ifname, file); } /** @@ -1110,10 +1093,8 @@ virNetDevGetVirtualFunctions(const char *pfname, n_vfname) < 0) goto cleanup; - if (VIR_ALLOC_N(*vfname, *n_vfname) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(*vfname, *n_vfname) < 0) goto cleanup; - } for (i = 0; i < *n_vfname; i++) { @@ -1661,16 +1642,12 @@ virNetDevReplaceVfConfig(const char *pflinkdev, int vf, goto cleanup; if (virAsprintf(&path, "%s/%s_vf%d", - stateDir, pflinkdev, vf) < 0) { - virReportOOMError(); + stateDir, pflinkdev, vf) < 0) goto cleanup; - } if (virAsprintf(&fileData, "%s\n%d\n", - virMacAddrFormat(&oldmac, macstr), oldvlanid) < 0) { - virReportOOMError(); + virMacAddrFormat(&oldmac, macstr), oldvlanid) < 0) goto cleanup; - } if (virFileWriteStr(path, fileData, O_CREAT|O_TRUNC|O_WRONLY) < 0) { virReportSystemError(errno, _("Unable to preserve mac/vlan tag " "for pf = %s, vf = %d"), pflinkdev, vf); @@ -1699,10 +1676,8 @@ virNetDevRestoreVfConfig(const char *pflinkdev, int vf, int ifindex = -1; if (virAsprintf(&path, "%s/%s_vf%d", - stateDir, pflinkdev, vf) < 0) { - virReportOOMError(); + stateDir, pflinkdev, vf) < 0) return rc; - } if (virFileReadAll(path, 128, &fileData) < 0) { goto cleanup; diff --git a/src/util/virnetdevbandwidth.c b/src/util/virnetdevbandwidth.c index 74e6c8c..42b0a50 100644 --- a/src/util/virnetdevbandwidth.c +++ b/src/util/virnetdevbandwidth.c @@ -297,22 +297,17 @@ virNetDevBandwidthCopy(virNetDevBandwidthPtr *dest, return 0; } - if (VIR_ALLOC(*dest) < 0) { - virReportOOMError(); + if (VIR_ALLOC(*dest) < 0) goto cleanup; - } if (src->in) { - if (VIR_ALLOC((*dest)->in) < 0) { - virReportOOMError(); + if (VIR_ALLOC((*dest)->in) < 0) goto cleanup; - } memcpy((*dest)->in, src->in, sizeof(*src->in)); } if (src->out) { if (VIR_ALLOC((*dest)->out) < 0) { - virReportOOMError(); VIR_FREE((*dest)->in); goto cleanup; } @@ -417,10 +412,8 @@ virNetDevBandwidthPlug(const char *brname, virAsprintf(&floor, "%llukbps", bandwidth->in->floor) < 0 || virAsprintf(&ceil, "%llukbps", net_bandwidth->in->peak ? net_bandwidth->in->peak : - net_bandwidth->in->average) < 0) { - virReportOOMError(); + net_bandwidth->in->average) < 0) goto cleanup; - } cmd = virCommandNew(TC); virCommandAddArgList(cmd, "class", "add", "dev", brname, "parent", "1:1", @@ -497,10 +490,8 @@ virNetDevBandwidthUnplug(const char *brname, if (virAsprintf(&class_id, "1:%x", id) < 0 || virAsprintf(&qdisc_id, "%x:", id) < 0 || - virAsprintf(&filter_id, "%u", id) < 0) { - virReportOOMError(); + virAsprintf(&filter_id, "%u", id) < 0) goto cleanup; - } cmd = virCommandNew(TC); virCommandAddArgList(cmd, "qdisc", "del", "dev", brname, @@ -564,10 +555,8 @@ virNetDevBandwidthUpdateRate(const char *ifname, if (virAsprintf(&rate, "%llukbps", new_rate) < 0 || virAsprintf(&ceil, "%llukbps", bandwidth->in->peak ? bandwidth->in->peak : - bandwidth->in->average) < 0) { - virReportOOMError(); + bandwidth->in->average) < 0) goto cleanup; - } cmd = virCommandNew(TC); virCommandAddArgList(cmd, "class", "change", "dev", ifname, diff --git a/src/util/virnetdevbridge.c b/src/util/virnetdevbridge.c index 9d95374..4ff6b24 100644 --- a/src/util/virnetdevbridge.c +++ b/src/util/virnetdevbridge.c @@ -108,10 +108,8 @@ static int virNetDevBridgeSet(const char *brname, char *path = NULL; int ret = -1; - if (virAsprintf(&path, "%s/%s/bridge/%s", SYSFS_NET_DIR, brname, paramname) < 0) { - virReportOOMError(); + if (virAsprintf(&path, "%s/%s/bridge/%s", SYSFS_NET_DIR, brname, paramname) < 0) return -1; - } if (virFileExists(path)) { char valuestr[INT_BUFSIZE_BOUND(value)]; @@ -157,10 +155,8 @@ static int virNetDevBridgeGet(const char *brname, char *path = NULL; int ret = -1; - if (virAsprintf(&path, "%s/%s/bridge/%s", SYSFS_NET_DIR, brname, paramname) < 0) { - virReportOOMError(); + if (virAsprintf(&path, "%s/%s/bridge/%s", SYSFS_NET_DIR, brname, paramname) < 0) return -1; - } if (virFileExists(path)) { char *valuestr; diff --git a/src/util/virnetdevmacvlan.c b/src/util/virnetdevmacvlan.c index a61c45f..9705e1f 100644 --- a/src/util/virnetdevmacvlan.c +++ b/src/util/virnetdevmacvlan.c @@ -764,11 +764,11 @@ virNetDevMacVLanVPortProfileRegisterCallback(const char *ifname, if (virtPortProfile && virNetlinkEventServiceIsRunning(NETLINK_ROUTE)) { if (VIR_ALLOC(calld) < 0) - goto memory_error; + goto error; if (VIR_STRDUP(calld->cr_ifname, ifname) < 0) goto error; if (VIR_ALLOC(calld->virtPortProfile) < 0) - goto memory_error; + goto error; memcpy(calld->virtPortProfile, virtPortProfile, sizeof(*virtPortProfile)); virMacAddrSet(&calld->macaddress, macaddress); if (VIR_STRDUP(calld->linkdev, linkdev) < 0) @@ -785,8 +785,6 @@ virNetDevMacVLanVPortProfileRegisterCallback(const char *ifname, return 0; -memory_error: - virReportOOMError(); error: virNetlinkCallbackDataFree(calld); return -1; diff --git a/src/util/virnetdevopenvswitch.c b/src/util/virnetdevopenvswitch.c index 75b196c..9ade8c5 100644 --- a/src/util/virnetdevopenvswitch.c +++ b/src/util/virnetdevopenvswitch.c @@ -68,17 +68,17 @@ int virNetDevOpenvswitchAddPort(const char *brname, const char *ifname, if (virAsprintf(&attachedmac_ex_id, "external-ids:attached-mac=\"%s\"", macaddrstr) < 0) - goto out_of_memory; + goto cleanup; if (virAsprintf(&ifaceid_ex_id, "external-ids:iface-id=\"%s\"", ifuuidstr) < 0) - goto out_of_memory; + goto cleanup; if (virAsprintf(&vmid_ex_id, "external-ids:vm-id=\"%s\"", vmuuidstr) < 0) - goto out_of_memory; + goto cleanup; if (ovsport->profileID[0] != '\0') { if (virAsprintf(&profile_ex_id, "external-ids:port-profile=\"%s\"", ovsport->profileID) < 0) - goto out_of_memory; + goto cleanup; } cmd = virCommandNew(OVSVSCTL); @@ -118,8 +118,10 @@ int virNetDevOpenvswitchAddPort(const char *brname, const char *ifname, virBufferAsprintf(&buf, "%d", virtVlan->tag[i]); } - if (virBufferError(&buf)) - goto out_of_memory; + if (virBufferError(&buf)) { + virReportOOMError(); + goto cleanup; + } virCommandAddArg(cmd, virBufferCurrentContent(&buf)); } else if (virtVlan->nTags) { virCommandAddArgFormat(cmd, "tag=%d", virtVlan->tag[0]); @@ -161,10 +163,6 @@ cleanup: VIR_FREE(profile_ex_id); virCommandFree(cmd); return ret; - -out_of_memory: - virReportOOMError(); - goto cleanup; } /** diff --git a/src/util/virnetdevtap.c b/src/util/virnetdevtap.c index 4e2f32a..767a5af 100644 --- a/src/util/virnetdevtap.c +++ b/src/util/virnetdevtap.c @@ -314,10 +314,8 @@ int virNetDevTapCreate(char **ifname, int i; for (i = 0; i <= IF_MAXUNIT; i++) { char *newname; - if (virAsprintf(&newname, *ifname, i) < 0) { - virReportOOMError(); + if (virAsprintf(&newname, *ifname, i) < 0) goto cleanup; - } if (virNetDevExists(newname) == 0) { newifname = newname; @@ -339,10 +337,8 @@ int virNetDevTapCreate(char **ifname, if (tapfd) { char *dev_path = NULL; - if (virAsprintf(&dev_path, "/dev/%s", ifr.ifr_name) < 0) { - virReportOOMError(); + if (virAsprintf(&dev_path, "/dev/%s", ifr.ifr_name) < 0) goto cleanup; - } if ((*tapfd = open(dev_path, O_RDWR)) < 0) { virReportSystemError(errno, diff --git a/src/util/virnetdevveth.c b/src/util/virnetdevveth.c index e73c31d..039767f 100644 --- a/src/util/virnetdevveth.c +++ b/src/util/virnetdevveth.c @@ -56,18 +56,14 @@ static int virNetDevVethGetFreeName(char **veth, int startDev) do { VIR_FREE(path); ++devNum; - if (virAsprintf(&path, "/sys/class/net/veth%d/", devNum) < 0) { - virReportOOMError(); + if (virAsprintf(&path, "/sys/class/net/veth%d/", devNum) < 0) return -1; - } VIR_DEBUG("Probe %s", path); } while (virFileExists(path)); VIR_FREE(path); - if (virAsprintf(veth, "veth%d", devNum) < 0) { - virReportOOMError(); + if (virAsprintf(veth, "veth%d", devNum) < 0) return -1; - } return devNum; } diff --git a/src/util/virnetdevvlan.c b/src/util/virnetdevvlan.c index eed32f7..13ddf36 100644 --- a/src/util/virnetdevvlan.c +++ b/src/util/virnetdevvlan.c @@ -86,10 +86,8 @@ virNetDevVlanCopy(virNetDevVlanPtr dst, const virNetDevVlanPtr src) if (!src || src->nTags == 0) return 0; - if (VIR_ALLOC_N(dst->tag, src->nTags) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(dst->tag, src->nTags) < 0) return -1; - } dst->trunk = src->trunk; dst->nTags = src->nTags; diff --git a/src/util/virnetdevvportprofile.c b/src/util/virnetdevvportprofile.c index 0f1b6a1..dc9e5a9 100644 --- a/src/util/virnetdevvportprofile.c +++ b/src/util/virnetdevvportprofile.c @@ -410,10 +410,8 @@ int virNetDevVPortProfileMerge3(virNetDevVPortProfilePtr *result, } /* at least one of the source profiles is non-empty */ - if (VIR_ALLOC(*result) < 0) { - virReportOOMError(); + if (VIR_ALLOC(*result) < 0) return ret; - } /* start with the interface's profile. There are no pointers in a * virtualPortProfile, so a shallow copy is sufficient. diff --git a/src/util/virnetlink.c b/src/util/virnetlink.c index b2ba9df..dd76ebc 100644 --- a/src/util/virnetlink.c +++ b/src/util/virnetlink.c @@ -516,10 +516,8 @@ virNetlinkEventServiceStart(unsigned int protocol, unsigned int groups) VIR_INFO("starting netlink event service with protocol %d", protocol); - if (VIR_ALLOC(srv) < 0) { - virReportOOMError(); + if (VIR_ALLOC(srv) < 0) return -1; - } if (virMutexInit(&srv->lock) < 0) { VIR_FREE(srv); @@ -645,10 +643,8 @@ virNetlinkEventAddClient(virNetlinkEventHandleCallback handleCB, VIR_DEBUG("Used %zu handle slots, adding at least %d more", srv->handlesAlloc, NETLINK_EVENT_ALLOC_EXTENT); if (VIR_RESIZE_N(srv->handles, srv->handlesAlloc, - srv->handlesCount, NETLINK_EVENT_ALLOC_EXTENT) < 0) { - virReportOOMError(); + srv->handlesCount, NETLINK_EVENT_ALLOC_EXTENT) < 0) goto error; - } } r = srv->handlesCount++; diff --git a/src/util/virobject.c b/src/util/virobject.c index 72a5248..61b5413 100644 --- a/src/util/virobject.c +++ b/src/util/virobject.c @@ -132,10 +132,8 @@ virClassPtr virClassNew(virClassPtr parent, return NULL; } - if (VIR_ALLOC(klass) < 0) { - virReportOOMError(); + if (VIR_ALLOC(klass) < 0) goto error; - } klass->parent = parent; if (VIR_STRDUP(klass->name, name) < 0) @@ -191,10 +189,8 @@ void *virObjectNew(virClassPtr klass) if (VIR_ALLOC_VAR(obj, char, - klass->objectSize - sizeof(virObject)) < 0) { - virReportOOMError(); + klass->objectSize - sizeof(virObject)) < 0) return NULL; - } obj->magic = klass->magic; obj->klass = klass; diff --git a/src/util/virpci.c b/src/util/virpci.c index 9ed257e..e42f6fa 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -480,10 +480,8 @@ virPCIDeviceDetectFunctionLevelReset(virPCIDevicePtr dev, int cfgfd) * device is a VF, we just assume FLR works */ - if (virAsprintf(&path, PCI_SYSFS "devices/%s/physfn", dev->name) < 0) { - virReportOOMError(); + if (virAsprintf(&path, PCI_SYSFS "devices/%s/physfn", dev->name) < 0) return -1; - } found = virFileExists(path); VIR_FREE(path); @@ -846,12 +844,7 @@ virPCIDriverDir(char **buffer, const char *driver) { VIR_FREE(*buffer); - if (virAsprintf(buffer, PCI_SYSFS "drivers/%s", driver) < 0) { - virReportOOMError(); - return -1; - } - - return 0; + return virAsprintf(buffer, PCI_SYSFS "drivers/%s", driver); } static int @@ -859,12 +852,7 @@ virPCIDriverFile(char **buffer, const char *driver, const char *file) { VIR_FREE(*buffer); - if (virAsprintf(buffer, PCI_SYSFS "drivers/%s/%s", driver, file) < 0) { - virReportOOMError(); - return -1; - } - - return 0; + return virAsprintf(buffer, PCI_SYSFS "drivers/%s/%s", driver, file); } static int @@ -872,12 +860,7 @@ virPCIFile(char **buffer, const char *device, const char *file) { VIR_FREE(*buffer); - if (virAsprintf(buffer, PCI_SYSFS "devices/%s/%s", device, file) < 0) { - virReportOOMError(); - return -1; - } - - return 0; + return virAsprintf(buffer, PCI_SYSFS "devices/%s/%s", device, file); } @@ -1468,10 +1451,8 @@ virPCIDeviceNew(unsigned int domain, char *vendor = NULL; char *product = NULL; - if (VIR_ALLOC(dev) < 0) { - virReportOOMError(); + if (VIR_ALLOC(dev) < 0) return NULL; - } dev->domain = domain; dev->bus = bus; @@ -1487,10 +1468,8 @@ virPCIDeviceNew(unsigned int domain, goto error; } if (virAsprintf(&dev->path, PCI_SYSFS "devices/%s/config", - dev->name) < 0) { - virReportOOMError(); + dev->name) < 0) goto error; - } if (access(dev->path, F_OK) != 0) { virReportSystemError(errno, @@ -1537,10 +1516,8 @@ virPCIDeviceCopy(virPCIDevicePtr dev) { virPCIDevicePtr copy; - if (VIR_ALLOC(copy) < 0) { - virReportOOMError(); + if (VIR_ALLOC(copy) < 0) return NULL; - } /* shallow copy to take care of most attributes */ *copy = *dev; @@ -1693,10 +1670,8 @@ virPCIDeviceListAdd(virPCIDeviceListPtr list, return -1; } - if (VIR_REALLOC_N(list->devs, list->count+1) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(list->devs, list->count+1) < 0) return -1; - } list->devs[list->count++] = dev; @@ -1835,10 +1810,8 @@ int virPCIDeviceFileIterate(virPCIDevicePtr dev, struct dirent *ent; if (virAsprintf(&pcidir, "/sys/bus/pci/devices/%04x:%02x:%02x.%x", - dev->domain, dev->bus, dev->slot, dev->function) < 0) { - virReportOOMError(); + dev->domain, dev->bus, dev->slot, dev->function) < 0) goto cleanup; - } if (!(dir = opendir(pcidir))) { virReportSystemError(errno, @@ -1855,10 +1828,8 @@ int virPCIDeviceFileIterate(virPCIDevicePtr dev, STRPREFIX(ent->d_name, "resource") || STREQ(ent->d_name, "rom") || STREQ(ent->d_name, "reset")) { - if (virAsprintf(&file, "%s/%s", pcidir, ent->d_name) < 0) { - virReportOOMError(); + if (virAsprintf(&file, "%s/%s", pcidir, ent->d_name) < 0) goto cleanup; - } if ((actor)(dev, file, opaque) < 0) goto cleanup; @@ -1894,10 +1865,8 @@ virPCIDeviceAddressIOMMUGroupIterate(virPCIDeviceAddressPtr orig, if (virAsprintf(&groupPath, PCI_SYSFS "devices/%04x:%02x:%02x.%x/iommu_group/devices", - orig->domain, orig->bus, orig->slot, orig->function) < 0) { - virReportOOMError(); + orig->domain, orig->bus, orig->slot, orig->function) < 0) goto cleanup; - } if (!(groupDir = opendir(groupPath))) { /* just process the original device, nothing more */ @@ -2009,10 +1978,9 @@ virPCIGetIOMMUGroupAddressesAddOne(virPCIDeviceAddressPtr newDevAddr, void *opaq *copyAddr = *newDevAddr; if (VIR_APPEND_ELEMENT(*addrList->iommuGroupDevices, - *addrList->nIommuGroupDevices, copyAddr, false) < 0) { - virReportOOMError(); + *addrList->nIommuGroupDevices, + copyAddr, true) < 0) goto cleanup; - } ret = 0; cleanup: @@ -2063,10 +2031,8 @@ virPCIDeviceAddressGetIOMMUGroupNum(virPCIDeviceAddressPtr addr) int ret = -1; if (virAsprintf(&devName, "%.4x:%.2x:%.2x.%.1x", addr->domain, - addr->bus, addr->slot, addr->function) < 0) { - virReportOOMError(); + addr->bus, addr->slot, addr->function) < 0) goto cleanup; - } if (virPCIFile(&devPath, devName, "iommu_group") < 0) goto cleanup; @@ -2125,10 +2091,8 @@ virPCIDeviceGetIOMMUGroupDev(virPCIDevicePtr dev) goto cleanup; } if (virAsprintf(&groupDev, "/dev/vfio/%s", - last_component(groupPath)) < 0) { - virReportOOMError(); + last_component(groupPath)) < 0) goto cleanup; - } cleanup: VIR_FREE(devPath); VIR_FREE(groupPath); @@ -2354,10 +2318,8 @@ virPCIGetDeviceAddressFromSysfsLink(const char *device_link, } config_address = last_component(device_path); - if (VIR_ALLOC(*bdf) != 0) { - virReportOOMError(); + if (VIR_ALLOC(*bdf) != 0) goto out; - } if (virPCIDeviceAddressParse(config_address, *bdf) != 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -2395,7 +2357,6 @@ virPCIGetPhysicalFunction(const char *vf_sysfs_path, "with sysfs path '%s'", vf_sysfs_path); if (virBuildPath(&device_link, vf_sysfs_path, "physfn") == -1) { - virReportOOMError(); return ret; } else { ret = virPCIGetDeviceAddressFromSysfsLink(device_link, @@ -2460,7 +2421,6 @@ virPCIGetVirtualFunctions(const char *sysfs_path, if (VIR_REALLOC_N(*virtual_functions, *num_virtual_functions + 1) < 0) { - virReportOOMError(); VIR_FREE(config_addr); goto error; } @@ -2498,10 +2458,8 @@ virPCIIsVirtualFunction(const char *vf_sysfs_device_link) int ret = -1; if (virAsprintf(&vf_sysfs_physfn_link, "%s/physfn", - vf_sysfs_device_link) < 0) { - virReportOOMError(); + vf_sysfs_device_link) < 0) return ret; - } ret = virFileExists(vf_sysfs_physfn_link); @@ -2562,27 +2520,17 @@ out: int virPCIGetSysfsFile(char *virPCIDeviceName, char **pci_sysfs_device_link) { - if (virAsprintf(pci_sysfs_device_link, PCI_SYSFS "devices/%s", - virPCIDeviceName) < 0) { - virReportOOMError(); - return -1; - } - - return 0; + return virAsprintf(pci_sysfs_device_link, PCI_SYSFS "devices/%s", + virPCIDeviceName); } int virPCIDeviceAddressGetSysfsFile(virPCIDeviceAddressPtr dev, char **pci_sysfs_device_link) { - if (virAsprintf(pci_sysfs_device_link, - PCI_SYSFS "devices/%04x:%02x:%02x.%x", dev->domain, - dev->bus, dev->slot, dev->function) < 0) { - virReportOOMError(); - return -1; - } - - return 0; + return virAsprintf(pci_sysfs_device_link, + PCI_SYSFS "devices/%04x:%02x:%02x.%x", dev->domain, + dev->bus, dev->slot, dev->function); } /* diff --git a/src/util/virportallocator.c b/src/util/virportallocator.c index c7be10f..d473d2a 100644 --- a/src/util/virportallocator.c +++ b/src/util/virportallocator.c @@ -86,7 +86,6 @@ virPortAllocatorPtr virPortAllocatorNew(unsigned short start, pa->end = end; if (!(pa->bitmap = virBitmapNew((end-start)+1))) { - virReportOOMError(); virObjectUnref(pa); return NULL; } diff --git a/src/util/virprocess.c b/src/util/virprocess.c index bf61127..6747c05 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -429,10 +429,8 @@ realloc: } *map = virBitmapNew(maxcpu); - if (!*map) { - virReportOOMError(); + if (!*map) return -1; - } for (i = 0; i < maxcpu; i++) if (CPU_ISSET_S(i, masklen, mask)) @@ -476,10 +474,8 @@ int virProcessGetAffinity(pid_t pid ATTRIBUTE_UNUSED, virBitmapPtr *map, int maxcpu) { - if (!(*map = virBitmapNew(maxcpu))) { - virReportOOMError(); + if (!(*map = virBitmapNew(maxcpu))) return -1; - } virBitmapSetAll(*map); return 0; @@ -524,15 +520,12 @@ int virProcessGetNamespaces(pid_t pid, if (virAsprintf(&nsfile, "/proc/%llu/ns/%s", (unsigned long long)pid, - ns[i]) < 0) { - virReportOOMError(); + ns[i]) < 0) goto cleanup; - } if ((fd = open(nsfile, O_RDWR)) >= 0) { if (VIR_EXPAND_N(*fdlist, *nfdlist, 1) < 0) { VIR_FORCE_CLOSE(fd); - virReportOOMError(); goto cleanup; } @@ -763,10 +756,8 @@ int virProcessGetStartTime(pid_t pid, char **tokens = NULL; if (virAsprintf(&filename, "/proc/%llu/stat", - (unsigned long long)pid) < 0) { - virReportOOMError(); + (unsigned long long)pid) < 0) return -1; - } if ((len = virFileReadAll(filename, 1024, &buf)) < 0) goto cleanup; diff --git a/src/util/virrandom.c b/src/util/virrandom.c index f46d702..e2d18f8 100644 --- a/src/util/virrandom.c +++ b/src/util/virrandom.c @@ -178,11 +178,6 @@ virRandomGenerateWWN(char **wwn, return -1; } - if (virAsprintf(wwn, "5" "%s%09llx", oui, - (unsigned long long)virRandomBits(36)) < 0) { - virReportOOMError(); - return -1; - } - - return 0; + return virAsprintf(wwn, "5" "%s%09llx", oui, + (unsigned long long)virRandomBits(36)); } diff --git a/src/util/virscsi.c b/src/util/virscsi.c index 4870307..9b60c89 100644 --- a/src/util/virscsi.c +++ b/src/util/virscsi.c @@ -117,10 +117,8 @@ virSCSIDeviceGetSgName(const char *adapter, if (virAsprintf(&path, SYSFS_SCSI_DEVICES "/%d:%d:%d:%d/scsi_generic", - adapter_id, bus, target, unit) < 0) { - virReportOOMError(); + adapter_id, bus, target, unit) < 0) return NULL; - } if (!(dir = opendir(path))) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -162,10 +160,8 @@ virSCSIDeviceGetDevName(const char *adapter, if (virAsprintf(&path, SYSFS_SCSI_DEVICES "/%d:%d:%d:%d/block", - adapter_id, bus, target, unit) < 0) { - virReportOOMError(); + adapter_id, bus, target, unit) < 0) return NULL; - } if (!(dir = opendir(path))) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -201,10 +197,8 @@ virSCSIDeviceNew(const char *adapter, char *vendor = NULL; char *model = NULL; - if (VIR_ALLOC(dev) < 0) { - virReportOOMError(); + if (VIR_ALLOC(dev) < 0) return NULL; - } dev->bus = bus; dev->target = target; @@ -219,10 +213,8 @@ virSCSIDeviceNew(const char *adapter, if (virAsprintf(&dev->name, "%d:%d:%d:%d", dev->adapter, dev->bus, dev->bus, dev->unit) < 0 || - virAsprintf(&dev->sg_path, "/dev/%s", sg) < 0) { - virReportOOMError(); + virAsprintf(&dev->sg_path, "/dev/%s", sg) < 0) goto cleanup; - } if (access(dev->sg_path, F_OK) != 0) { virReportSystemError(errno, @@ -234,10 +226,8 @@ virSCSIDeviceNew(const char *adapter, if (virAsprintf(&vendor_path, SYSFS_SCSI_DEVICES "/%s/vendor", dev->name) < 0 || virAsprintf(&model_path, - SYSFS_SCSI_DEVICES "/%s/model", dev->name) < 0) { - virReportOOMError(); + SYSFS_SCSI_DEVICES "/%s/model", dev->name) < 0) goto cleanup; - } if (virFileReadAll(vendor_path, 1024, &vendor) < 0) goto cleanup; @@ -248,10 +238,8 @@ virSCSIDeviceNew(const char *adapter, virTrimSpaces(vendor, NULL); virTrimSpaces(model, NULL); - if (virAsprintf(&dev->id, "%s:%s", vendor, model) < 0) { - virReportOOMError(); + if (virAsprintf(&dev->id, "%s:%s", vendor, model) < 0) goto cleanup; - } ret = dev; cleanup: @@ -371,10 +359,8 @@ virSCSIDeviceListAdd(virSCSIDeviceListPtr list, return -1; } - if (VIR_REALLOC_N(list->devs, list->count + 1) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(list->devs, list->count + 1) < 0) return -1; - } list->devs[list->count++] = dev; diff --git a/src/util/virsexpr.c b/src/util/virsexpr.c index 7db215a..a4c8997 100644 --- a/src/util/virsexpr.c +++ b/src/util/virsexpr.c @@ -48,10 +48,8 @@ sexpr_new(void) { struct sexpr *ret; - if (VIR_ALLOC(ret) < 0) { - virReportOOMError(); + if (VIR_ALLOC(ret) < 0) return NULL; - } ret->kind = SEXPR_NIL; return ret; } diff --git a/src/util/virsocketaddr.c b/src/util/virsocketaddr.c index 80b5c0b..c105718 100644 --- a/src/util/virsocketaddr.c +++ b/src/util/virsocketaddr.c @@ -290,7 +290,7 @@ virSocketAddrFormatFull(virSocketAddrPtr addr, if (withService) { if (virAsprintf(&addrstr, "127.0.0.1%s0", separator ? separator : ":") < 0) - goto no_memory; + goto error; } else { if (VIR_STRDUP(addrstr, "127.0.0.1") < 0) goto error; @@ -311,7 +311,7 @@ virSocketAddrFormatFull(virSocketAddrPtr addr, if (withService) { if (virAsprintf(&addrstr, "%s%s%s", host, separator, port) == -1) - goto no_memory; + goto error; } else { if (VIR_STRDUP(addrstr, host) < 0) goto error; @@ -319,8 +319,6 @@ virSocketAddrFormatFull(virSocketAddrPtr addr, return addrstr; -no_memory: - virReportOOMError(); error: return NULL; } diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 27aa4fe..d143d58 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -357,10 +357,8 @@ qcowXGetBackingStore(char **res, return BACKING_STORE_INVALID; if (size + 1 == 0) return BACKING_STORE_INVALID; - if (VIR_ALLOC_N(*res, size + 1) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(*res, size + 1) < 0) return BACKING_STORE_ERROR; - } memcpy(*res, buf + offset, size); (*res)[size] = '\0'; @@ -444,10 +442,8 @@ vmdk4GetBackingStore(char **res, size_t len; int ret = BACKING_STORE_ERROR; - if (VIR_ALLOC_N(desc, STORAGE_MAX_HEAD + 1) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(desc, STORAGE_MAX_HEAD + 1) < 0) goto cleanup; - } *res = NULL; /* @@ -526,10 +522,8 @@ qedGetBackingStore(char **res, return BACKING_STORE_OK; if (offset + size > buf_size || offset + size < offset) return BACKING_STORE_INVALID; - if (VIR_ALLOC_N(*res, size + 1) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(*res, size + 1) < 0) return BACKING_STORE_ERROR; - } memcpy(*res, buf + offset, size); (*res)[size] = '\0'; @@ -569,10 +563,8 @@ virFindBackingFile(const char *start, bool start_is_dir, const char *path, start = "."; d_len = 1; } - if (virAsprintf(&combined, "%.*s/%s", (int)d_len, start, path) < 0) { - virReportOOMError(); + if (virAsprintf(&combined, "%.*s/%s", (int)d_len, start, path) < 0) goto cleanup; - } } if (directory && !(*directory = mdir_name(combined))) { @@ -737,10 +729,8 @@ qcow2GetFeatures(virBitmapPtr *features, if (len < QCOW2v3_HDR_SIZE) return -1; - if (!(feat = virBitmapNew(VIR_STORAGE_FILE_FEATURE_LAST))) { - virReportOOMError(); + if (!(feat = virBitmapNew(VIR_STORAGE_FILE_FEATURE_LAST))) return -1; - } /* todo: check for incompatible or autoclear features? */ bits = virReadBufInt64BE(buf + QCOW2v3_HDR_FEATURES_COMPATIBLE); @@ -771,10 +761,8 @@ virStorageFileGetMetadataInternal(const char *path, VIR_DEBUG("path=%s, fd=%d, format=%d", path, fd, format); - if (VIR_ALLOC(meta) < 0) { - virReportOOMError(); + if (VIR_ALLOC(meta) < 0) return NULL; - } if (fstat(fd, &sb) < 0) { virReportSystemError(errno, @@ -792,10 +780,8 @@ virStorageFileGetMetadataInternal(const char *path, goto cleanup; } - if (VIR_ALLOC_N(buf, len) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(buf, len) < 0) goto cleanup; - } if ((len = read(fd, buf, len)) < 0) { virReportSystemError(errno, _("cannot read header '%s'"), path); @@ -940,10 +926,8 @@ virStorageFileProbeFormatFromFD(const char *path, int fd) return VIR_STORAGE_FILE_DIR; } - if (VIR_ALLOC_N(head, len) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(head, len) < 0) return -1; - } if (lseek(fd, 0, SEEK_SET) == (off_t)-1) { virReportSystemError(errno, _("cannot set to start of '%s'"), path); diff --git a/src/util/virstring.c b/src/util/virstring.c index 6fc015b..7794c8e 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -83,7 +83,7 @@ char **virStringSplit(const char *string, size_t len = tmp - remainder; if (VIR_RESIZE_N(tokens, maxtokens, ntokens, 1) < 0) - goto no_memory; + goto error; if (VIR_STRNDUP(tokens[ntokens], remainder, len) < 0) goto error; @@ -94,7 +94,7 @@ char **virStringSplit(const char *string, } if (*string) { if (VIR_RESIZE_N(tokens, maxtokens, ntokens, 1) < 0) - goto no_memory; + goto error; if (VIR_STRDUP(tokens[ntokens], remainder) < 0) goto error; @@ -102,13 +102,11 @@ char **virStringSplit(const char *string, } if (VIR_RESIZE_N(tokens, maxtokens, ntokens, 1) < 0) - goto no_memory; + goto error; tokens[ntokens++] = NULL; return tokens; -no_memory: - virReportOOMError(); error: for (i = 0; i < ntokens; i++) VIR_FREE(tokens[i]); diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c index c6d3a71..14e2e71 100644 --- a/src/util/virsysinfo.c +++ b/src/util/virsysinfo.c @@ -305,10 +305,8 @@ virSysinfoParseProcessor(const char *base, virSysinfoDefPtr ret) eol = strchr(base, '\n'); cur = strchr(base, ':') + 1; - if (VIR_EXPAND_N(ret->processor, ret->nprocessor, 1) < 0) { - virReportOOMError(); + if (VIR_EXPAND_N(ret->processor, ret->nprocessor, 1) < 0) goto error; - } processor = &ret->processor[ret->nprocessor - 1]; virSkipSpaces(&cur); @@ -435,10 +433,8 @@ virSysinfoParseProcessor(const char *base, virSysinfoDefPtr ret) while ((tmp_base = strstr(tmp_base, "processor ")) && (tmp_base = virSysinfoParseLine(tmp_base, "processor ", &procline))) { - if (VIR_EXPAND_N(ret->processor, ret->nprocessor, 1) < 0) { - virReportOOMError(); + if (VIR_EXPAND_N(ret->processor, ret->nprocessor, 1) < 0) goto cleanup; - } processor = &ret->processor[ret->nprocessor - 1]; if (VIR_STRDUP(processor->processor_manufacturer, manufacturer) < 0) goto cleanup; @@ -843,25 +839,25 @@ virSysinfoRead(void) { goto cleanup; if (VIR_ALLOC(ret) < 0) - goto no_memory; + goto error; ret->type = VIR_SYSINFO_SMBIOS; if (virSysinfoParseBIOS(outbuf, ret) < 0) - goto no_memory; + goto error; if (virSysinfoParseSystem(outbuf, ret) < 0) - goto no_memory; + goto error; ret->nprocessor = 0; ret->processor = NULL; if (virSysinfoParseProcessor(outbuf, ret) < 0) - goto no_memory; + goto error; ret->nmemory = 0; ret->memory = NULL; if (virSysinfoParseMemory(outbuf, ret) < 0) - goto no_memory; + goto error; cleanup: VIR_FREE(outbuf); @@ -869,9 +865,7 @@ cleanup: return ret; -no_memory: - virReportOOMError(); - +error: virSysinfoDefFree(ret); ret = NULL; goto cleanup; diff --git a/src/util/virthreadpool.c b/src/util/virthreadpool.c index e657145..b1e2c0c 100644 --- a/src/util/virthreadpool.c +++ b/src/util/virthreadpool.c @@ -169,10 +169,8 @@ virThreadPoolPtr virThreadPoolNew(size_t minWorkers, if (minWorkers > maxWorkers) minWorkers = maxWorkers; - if (VIR_ALLOC(pool) < 0) { - virReportOOMError(); + if (VIR_ALLOC(pool) < 0) return NULL; - } pool->jobList.tail = pool->jobList.head = NULL; @@ -193,10 +191,8 @@ virThreadPoolPtr virThreadPoolNew(size_t minWorkers, pool->maxWorkers = maxWorkers; for (i = 0; i < minWorkers; i++) { - if (VIR_ALLOC(data) < 0) { - virReportOOMError(); + if (VIR_ALLOC(data) < 0) goto error; - } data->pool = pool; data->cond = &pool->cond; @@ -216,10 +212,8 @@ virThreadPoolPtr virThreadPoolNew(size_t minWorkers, goto error; for (i = 0; i < prioWorkers; i++) { - if (VIR_ALLOC(data) < 0) { - virReportOOMError(); + if (VIR_ALLOC(data) < 0) goto error; - } data->pool = pool; data->cond = &pool->prioCond; data->priority = true; @@ -313,14 +307,11 @@ int virThreadPoolSendJob(virThreadPoolPtr pool, if (pool->freeWorkers - pool->jobQueueDepth <= 0 && pool->nWorkers < pool->maxWorkers) { - if (VIR_EXPAND_N(pool->workers, pool->nWorkers, 1) < 0) { - virReportOOMError(); + if (VIR_EXPAND_N(pool->workers, pool->nWorkers, 1) < 0) goto error; - } if (VIR_ALLOC(data) < 0) { pool->nWorkers--; - virReportOOMError(); goto error; } @@ -337,10 +328,8 @@ int virThreadPoolSendJob(virThreadPoolPtr pool, } } - if (VIR_ALLOC(job) < 0) { - virReportOOMError(); + if (VIR_ALLOC(job) < 0) goto error; - } job->data = jobData; job->priority = priority; diff --git a/src/util/virtime.c b/src/util/virtime.c index 37c639c..caa4e24 100644 --- a/src/util/virtime.c +++ b/src/util/virtime.c @@ -303,10 +303,8 @@ char *virTimeStringNow(void) { char *ret; - if (VIR_ALLOC_N(ret, VIR_TIME_STRING_BUFLEN) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(ret, VIR_TIME_STRING_BUFLEN) < 0) return NULL; - } if (virTimeStringNowRaw(ret) < 0) { virReportSystemError(errno, "%s", @@ -334,10 +332,8 @@ char *virTimeStringThen(unsigned long long when) { char *ret; - if (VIR_ALLOC_N(ret, VIR_TIME_STRING_BUFLEN) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(ret, VIR_TIME_STRING_BUFLEN) < 0) return NULL; - } if (virTimeStringThenRaw(when, ret) < 0) { virReportSystemError(errno, "%s", diff --git a/src/util/virtpm.c b/src/util/virtpm.c index b5504b5..f431604 100644 --- a/src/util/virtpm.c +++ b/src/util/virtpm.c @@ -47,10 +47,8 @@ virTPMCreateCancelPath(const char *devpath) if (dev) { dev++; if (virAsprintf(&path, "/sys/class/misc/%s/device/cancel", - dev) < 0) { - virReportOOMError(); + dev) < 0) goto cleanup; - } } else { virReportError(VIR_ERR_INTERNAL_ERROR, _("TPM device path %s is invalid"), devpath); diff --git a/src/util/virtypedparam.c b/src/util/virtypedparam.c index c767e32..f09de03 100644 --- a/src/util/virtypedparam.c +++ b/src/util/virtypedparam.c @@ -137,36 +137,29 @@ virTypedParamsCheck(virTypedParameterPtr params, char * virTypedParameterToString(virTypedParameterPtr param) { - char *value; - int ret = -1; + char *value = NULL; switch (param->type) { case VIR_TYPED_PARAM_INT: - if ((ret = virAsprintf(&value, "%d", param->value.i)) < 0) - virReportOOMError(); + ignore_value(virAsprintf(&value, "%d", param->value.i)); break; case VIR_TYPED_PARAM_UINT: - if ((ret = virAsprintf(&value, "%u", param->value.ui)) < 0) - virReportOOMError(); + ignore_value(virAsprintf(&value, "%u", param->value.ui)); break; case VIR_TYPED_PARAM_LLONG: - if ((ret = virAsprintf(&value, "%lld", param->value.l)) < 0) - virReportOOMError(); + ignore_value(virAsprintf(&value, "%lld", param->value.l)); break; case VIR_TYPED_PARAM_ULLONG: - if ((ret = virAsprintf(&value, "%llu", param->value.ul)) < 0) - virReportOOMError(); + ignore_value(virAsprintf(&value, "%llu", param->value.ul)); break; case VIR_TYPED_PARAM_DOUBLE: - if ((ret = virAsprintf(&value, "%g", param->value.d)) < 0) - virReportOOMError(); + ignore_value(virAsprintf(&value, "%g", param->value.d)); break; case VIR_TYPED_PARAM_BOOLEAN: - if ((ret = virAsprintf(&value, "%d", param->value.b)) < 0) - virReportOOMError(); + ignore_value(virAsprintf(&value, "%d", param->value.b)); break; case VIR_TYPED_PARAM_STRING: - ret = VIR_STRDUP(value, param->value.s); + ignore_value(VIR_STRDUP(value, param->value.s)); break; default: virReportError(VIR_ERR_INTERNAL_ERROR, @@ -174,10 +167,7 @@ virTypedParameterToString(virTypedParameterPtr param) param->type, param->field); } - if (ret < 0) - return NULL; - else - return value; + return value; } /* Assign name, type, and the appropriately typed arg to param; in the @@ -368,10 +358,8 @@ virTypedParamsReplaceString(virTypedParameterPtr *params, } old = param->value.s; } else { - if (VIR_EXPAND_N(*params, n, 1) < 0) { - virReportOOMError(); + if (VIR_EXPAND_N(*params, n, 1) < 0) goto error; - } param = *params + n - 1; } @@ -406,10 +394,8 @@ virTypedParamsCopy(virTypedParameterPtr *dst, if (!src || nparams <= 0) return 0; - if (VIR_ALLOC_N(*dst, nparams) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(*dst, nparams) < 0) return -1; - } for (i = 0; i < nparams; i++) { ignore_value(virStrcpyStatic((*dst)[i].field, src[i].field)); @@ -768,10 +754,8 @@ virTypedParamsAddInt(virTypedParameterPtr *params, virResetLastError(); VIR_TYPED_PARAM_CHECK(); - if (VIR_RESIZE_N(*params, max, n, 1) < 0) { - virReportOOMError(); + if (VIR_RESIZE_N(*params, max, n, 1) < 0) goto error; - } *maxparams = max; if (virTypedParameterAssign(*params + n, name, @@ -818,10 +802,8 @@ virTypedParamsAddUInt(virTypedParameterPtr *params, virResetLastError(); VIR_TYPED_PARAM_CHECK(); - if (VIR_RESIZE_N(*params, max, n, 1) < 0) { - virReportOOMError(); + if (VIR_RESIZE_N(*params, max, n, 1) < 0) goto error; - } *maxparams = max; if (virTypedParameterAssign(*params + n, name, @@ -868,10 +850,8 @@ virTypedParamsAddLLong(virTypedParameterPtr *params, virResetLastError(); VIR_TYPED_PARAM_CHECK(); - if (VIR_RESIZE_N(*params, max, n, 1) < 0) { - virReportOOMError(); + if (VIR_RESIZE_N(*params, max, n, 1) < 0) goto error; - } *maxparams = max; if (virTypedParameterAssign(*params + n, name, @@ -918,10 +898,8 @@ virTypedParamsAddULLong(virTypedParameterPtr *params, virResetLastError(); VIR_TYPED_PARAM_CHECK(); - if (VIR_RESIZE_N(*params, max, n, 1) < 0) { - virReportOOMError(); + if (VIR_RESIZE_N(*params, max, n, 1) < 0) goto error; - } *maxparams = max; if (virTypedParameterAssign(*params + n, name, @@ -968,10 +946,8 @@ virTypedParamsAddDouble(virTypedParameterPtr *params, virResetLastError(); VIR_TYPED_PARAM_CHECK(); - if (VIR_RESIZE_N(*params, max, n, 1) < 0) { - virReportOOMError(); + if (VIR_RESIZE_N(*params, max, n, 1) < 0) goto error; - } *maxparams = max; if (virTypedParameterAssign(*params + n, name, @@ -1018,10 +994,8 @@ virTypedParamsAddBoolean(virTypedParameterPtr *params, virResetLastError(); VIR_TYPED_PARAM_CHECK(); - if (VIR_RESIZE_N(*params, max, n, 1) < 0) { - virReportOOMError(); + if (VIR_RESIZE_N(*params, max, n, 1) < 0) goto error; - } *maxparams = max; if (virTypedParameterAssign(*params + n, name, @@ -1071,10 +1045,8 @@ virTypedParamsAddString(virTypedParameterPtr *params, virResetLastError(); VIR_TYPED_PARAM_CHECK(); - if (VIR_RESIZE_N(*params, max, n, 1) < 0) { - virReportOOMError(); + if (VIR_RESIZE_N(*params, max, n, 1) < 0) goto error; - } *maxparams = max; if (VIR_STRDUP(str, value) < 0) @@ -1131,10 +1103,8 @@ virTypedParamsAddFromString(virTypedParameterPtr *params, virResetLastError(); VIR_TYPED_PARAM_CHECK(); - if (VIR_RESIZE_N(*params, max, n, 1) < 0) { - virReportOOMError(); + if (VIR_RESIZE_N(*params, max, n, 1) < 0) goto error; - } *maxparams = max; if (virTypedParameterAssignFromStr(*params + n, name, type, value) < 0) diff --git a/src/util/viruri.c b/src/util/viruri.c index 9cdb134..4f04450 100644 --- a/src/util/viruri.c +++ b/src/util/viruri.c @@ -40,10 +40,8 @@ virURIParamAppend(virURIPtr uri, if (VIR_STRDUP(pname, name) < 0 || VIR_STRDUP(pvalue, value) < 0) goto error; - if (VIR_RESIZE_N(uri->params, uri->paramsAlloc, uri->paramsCount, 1) < 0) { - virReportOOMError(); + if (VIR_RESIZE_N(uri->params, uri->paramsAlloc, uri->paramsCount, 1) < 0) goto error; - } uri->params[uri->paramsCount].name = pname; uri->params[uri->paramsCount].value = pvalue; @@ -166,10 +164,8 @@ virURIParse(const char *uri) return NULL; } - if (VIR_ALLOC(ret) < 0) { - virReportOOMError(); + if (VIR_ALLOC(ret) < 0) goto error; - } if (VIR_STRDUP(ret->scheme, xmluri->scheme) < 0) goto error; @@ -256,10 +252,8 @@ virURIFormat(virURIPtr uri) if (xmluri.server != NULL && strchr(xmluri.server, ':') != NULL) { - if (virAsprintf(&tmpserver, "[%s]", xmluri.server) < 0) { - virReportOOMError(); + if (virAsprintf(&tmpserver, "[%s]", xmluri.server) < 0) return NULL; - } xmluri.server = tmpserver; } diff --git a/src/util/virusb.c b/src/util/virusb.c index d34e44f..3bcb07c 100644 --- a/src/util/virusb.c +++ b/src/util/virusb.c @@ -96,10 +96,8 @@ static int virUSBSysReadFile(const char *f_name, const char *d_name, char *ignore = NULL; tmp = virAsprintf(&filename, USB_SYSFS "/devices/%s/%s", d_name, f_name); - if (tmp < 0) { - virReportOOMError(); + if (tmp < 0) goto cleanup; - } if (virFileReadAll(filename, 1024, &buf) < 0) goto cleanup; @@ -334,10 +332,8 @@ virUSBDeviceNew(unsigned int bus, { virUSBDevicePtr dev; - if (VIR_ALLOC(dev) < 0) { - virReportOOMError(); + if (VIR_ALLOC(dev) < 0) return NULL; - } dev->bus = bus; dev->dev = devno; @@ -353,7 +349,6 @@ virUSBDeviceNew(unsigned int bus, if (virAsprintf(&dev->path, "%s" USB_DEVFS "%03d/%03d", vroot ? vroot : "", dev->bus, dev->dev) < 0) { - virReportOOMError(); virUSBDeviceFree(dev); return NULL; } @@ -456,10 +451,8 @@ virUSBDeviceListAdd(virUSBDeviceListPtr list, return -1; } - if (VIR_REALLOC_N(list->devs, list->count+1) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(list->devs, list->count+1) < 0) return -1; - } list->devs[list->count++] = dev; diff --git a/src/util/virutil.c b/src/util/virutil.c index 569d035..96f7119 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -192,10 +192,8 @@ virPipeReadUntilEOF(int outfd, int errfd, buf = ((fds[i].fd == outfd) ? outbuf : errbuf); size = (*buf ? strlen(*buf) : 0); - if (VIR_REALLOC_N(*buf, size+got+1) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(*buf, size+got+1) < 0) goto error; - } memmove(*buf+size, data, got); (*buf)[size+got] = '\0'; } @@ -549,10 +547,8 @@ char *virIndexToDiskName(int idx, const char *prefix) offset = strlen(prefix); - if (VIR_ALLOC_N(name, offset + i + 1)) { - virReportOOMError(); + if (VIR_ALLOC_N(name, offset + i + 1)) return NULL; - } strcpy(name, prefix); name[offset + i] = '\0'; @@ -645,8 +641,6 @@ char *virGetHostname(void) freeaddrinfo(info); cleanup: - if (result == NULL) - virReportOOMError(); return result; } @@ -671,10 +665,8 @@ static char *virGetUserEnt(uid_t uid, if (val < 0) strbuflen = 1024; - if (VIR_ALLOC_N(strbuf, strbuflen) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(strbuf, strbuflen) < 0) return NULL; - } /* * From the manpage (terrifying but true): @@ -684,11 +676,9 @@ static char *virGetUserEnt(uid_t uid, * The given name or uid was not found. */ while ((rc = getpwuid_r(uid, &pwbuf, strbuf, strbuflen, &pw)) == ERANGE) { - if (VIR_RESIZE_N(strbuf, strbuflen, strbuflen, strbuflen) < 0) { - virReportOOMError(); + if (VIR_RESIZE_N(strbuf, strbuflen, strbuflen, strbuflen) < 0) VIR_FREE(strbuf); return NULL; - } } if (rc != 0 || pw == NULL) { virReportSystemError(rc, @@ -718,10 +708,8 @@ static char *virGetGroupEnt(gid_t gid) if (val < 0) strbuflen = 1024; - if (VIR_ALLOC_N(strbuf, strbuflen) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(strbuf, strbuflen) < 0) return NULL; - } /* * From the manpage (terrifying but true): @@ -732,7 +720,6 @@ static char *virGetGroupEnt(gid_t gid) */ while ((rc = getgrgid_r(gid, &grbuf, strbuf, strbuflen, &gr)) == ERANGE) { if (VIR_RESIZE_N(strbuf, strbuflen, strbuflen, strbuflen) < 0) { - virReportOOMError(); VIR_FREE(strbuf); return NULL; } @@ -762,20 +749,14 @@ static char *virGetXDGDirectory(const char *xdgenvname, const char *xdgdefdir) char *home = NULL; if (path && path[0]) { - if (virAsprintf(&ret, "%s/libvirt", path) < 0) - goto no_memory; + ignore_value(virAsprintf(&ret, "%s/libvirt", path)); } else { home = virGetUserEnt(geteuid(), VIR_USER_ENT_DIRECTORY); - if (virAsprintf(&ret, "%s/%s/libvirt", home, xdgdefdir) < 0) - goto no_memory; + ignore_value(virAsprintf(&ret, "%s/%s/libvirt", home, xdgdefdir)); } - cleanup: VIR_FREE(home); return ret; - no_memory: - virReportOOMError(); - goto cleanup; } char *virGetUserConfigDirectory(void) @@ -797,11 +778,7 @@ char *virGetUserRuntimeDirectory(void) } else { char *ret; - if (virAsprintf(&ret, "%s/libvirt", path) < 0) { - virReportOOMError(); - return NULL; - } - + ignore_value(virAsprintf(&ret, "%s/libvirt", path)); return ret; } } @@ -834,16 +811,12 @@ virGetUserIDByName(const char *name, uid_t *uid) if (val < 0) strbuflen = 1024; - if (VIR_ALLOC_N(strbuf, strbuflen) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(strbuf, strbuflen) < 0) goto cleanup; - } while ((rc = getpwnam_r(name, &pwbuf, strbuf, strbuflen, &pw)) == ERANGE) { - if (VIR_RESIZE_N(strbuf, strbuflen, strbuflen, strbuflen) < 0) { - virReportOOMError(); + if (VIR_RESIZE_N(strbuf, strbuflen, strbuflen, strbuflen) < 0) goto cleanup; - } } if (!pw) { @@ -918,16 +891,12 @@ virGetGroupIDByName(const char *name, gid_t *gid) if (val < 0) strbuflen = 1024; - if (VIR_ALLOC_N(strbuf, strbuflen) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(strbuf, strbuflen) < 0) goto cleanup; - } while ((rc = getgrnam_r(name, &grbuf, strbuf, strbuflen, &gr)) == ERANGE) { - if (VIR_RESIZE_N(strbuf, strbuflen, strbuflen, strbuflen) < 0) { - virReportOOMError(); + if (VIR_RESIZE_N(strbuf, strbuflen, strbuflen, strbuflen) < 0) goto cleanup; - } } if (!gr) { @@ -1015,14 +984,12 @@ virSetUIDGID(uid_t uid, gid_t gid) bufsize = 16384; if (VIR_ALLOC_N(buf, bufsize) < 0) { - virReportOOMError(); err = ENOMEM; goto error; } while ((rc = getpwuid_r(uid, &pwd, buf, bufsize, &pwd_result)) == ERANGE) { if (VIR_RESIZE_N(buf, bufsize, bufsize, bufsize) < 0) { - virReportOOMError(); err = ENOMEM; goto error; } @@ -1543,13 +1510,9 @@ virGetUnprivSGIOSysfsPath(const char *path, return NULL; } - if (virAsprintf(&sysfs_path, "%s/%d:%d/queue/unpriv_sgio", - sysfs_dir ? sysfs_dir : SYSFS_DEV_BLOCK_PATH, - maj, min) < 0) { - virReportOOMError(); - return NULL; - } - + ignore_value(virAsprintf(&sysfs_path, "%s/%d:%d/queue/unpriv_sgio", + sysfs_dir ? sysfs_dir : SYSFS_DEV_BLOCK_PATH, + maj, min)); return sysfs_path; } @@ -1572,10 +1535,8 @@ virSetDeviceUnprivSGIO(const char *path, goto cleanup; } - if (virAsprintf(&val, "%d", unpriv_sgio) < 0) { - virReportOOMError(); + if (virAsprintf(&val, "%d", unpriv_sgio) < 0) goto cleanup; - } if ((rc = virFileWriteStr(sysfs_path, val, 0)) < 0) { virReportSystemError(-rc, _("failed to set %s"), sysfs_path); @@ -1656,10 +1617,8 @@ virReadFCHost(const char *sysfs_prefix, if (virAsprintf(&sysfs_path, "%s/host%d/%s", sysfs_prefix ? sysfs_prefix : SYSFS_FC_HOST_PATH, - host, entry) < 0) { - virReportOOMError(); + host, entry) < 0) goto cleanup; - } if (virFileReadAll(sysfs_path, 1024, &buf) < 0) goto cleanup; @@ -1691,10 +1650,8 @@ virIsCapableFCHost(const char *sysfs_prefix, if (virAsprintf(&sysfs_path, "%s/host%d", sysfs_prefix ? sysfs_prefix : SYSFS_FC_HOST_PATH, - host) < 0) { - virReportOOMError(); + host) < 0) return false; - } if (access(sysfs_path, F_OK) == 0) ret = true; @@ -1715,19 +1672,15 @@ virIsCapableVport(const char *sysfs_prefix, "%s/host%d/%s", sysfs_prefix ? sysfs_prefix : SYSFS_FC_HOST_PATH, host, - "vport_create") < 0) { - virReportOOMError(); + "vport_create") < 0) return false; - } if (virAsprintf(&scsi_host_path, "%s/host%d/%s", sysfs_prefix ? sysfs_prefix : SYSFS_SCSI_HOST_PATH, host, - "vport_create") < 0) { - virReportOOMError(); + "vport_create") < 0) goto cleanup; - } if ((access(fc_host_path, F_OK) == 0) || (access(scsi_host_path, F_OK) == 0)) @@ -1766,10 +1719,8 @@ virManageVport(const int parent_host, "%s/host%d/%s", SYSFS_FC_HOST_PATH, parent_host, - operation_file) < 0) { - virReportOOMError(); + operation_file) < 0) goto cleanup; - } if (!virFileExists(operation_path)) { VIR_FREE(operation_path); @@ -1777,10 +1728,8 @@ virManageVport(const int parent_host, "%s/host%d/%s", SYSFS_SCSI_HOST_PATH, parent_host, - operation_file) < 0) { - virReportOOMError(); + operation_file) < 0) goto cleanup; - } if (!virFileExists(operation_path)) { virReportError(VIR_ERR_OPERATION_INVALID, @@ -1793,10 +1742,8 @@ virManageVport(const int parent_host, if (virAsprintf(&vport_name, "%s:%s", wwpn, - wwnn) < 0) { - virReportOOMError(); + wwnn) < 0) goto cleanup; - } if (virFileWriteStr(operation_path, vport_name, 0) == 0) ret = 0; @@ -1856,10 +1803,8 @@ virGetFCHostNameByWWN(const char *sysfs_prefix, continue; if (virAsprintf(&wwnn_path, "%s/%s/node_name", prefix, - entry->d_name) < 0) { - virReportOOMError(); + entry->d_name) < 0) goto cleanup; - } if (!virFileExists(wwnn_path)) { VIR_FREE(wwnn_path); @@ -1875,10 +1820,8 @@ virGetFCHostNameByWWN(const char *sysfs_prefix, } if (virAsprintf(&wwpn_path, "%s/%s/port_name", prefix, - entry->d_name) < 0) { - virReportOOMError(); + entry->d_name) < 0) goto cleanup; - } if (!virFileExists(wwpn_path)) { VIR_FREE(wwnn_buf); diff --git a/src/util/virxml.c b/src/util/virxml.c index f8c595e..f652ee0 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -607,7 +607,6 @@ virXPathNodeSet(const char *xpath, ret = obj->nodesetval->nodeNr; if (list != NULL && ret) { if (VIR_ALLOC_N(*list, ret) < 0) { - virReportOOMError(); ret = -1; } else { memcpy(*list, obj->nodesetval->nodeTab, -- 1.8.1.5

On 07/04/13 14:06, Michal Privoznik wrote:
---
in src/util/virbitmap.c: /** * virBitmapNew: * @size: number of bits * * Allocate a bitmap capable of containing @size bits. * * Returns a pointer to the allocated bitmap or NULL if * memory cannot be allocated. This function historically returned only NULL without reporting the OOM error and the callers were supposed to do that. In multiple other patches you removed the call to reporting oom error, but: */ virBitmapPtr virBitmapNew(size_t size) { virBitmapPtr bitmap; size_t sz; if (SIZE_MAX - VIR_BITMAP_BITS_PER_UNIT < size || size == 0) return NULL; ... this condition will not report an error and thus the callers won't either. sz = (size + VIR_BITMAP_BITS_PER_UNIT - 1) / VIR_BITMAP_BITS_PER_UNIT; if (VIR_ALLOC(bitmap) < 0) return NULL; But here it will be correct. if (VIR_ALLOC_N(bitmap->map, sz) < 0) { VIR_FREE(bitmap); return NULL; } bitmap->max_bit = size; bitmap->map_len = sz; return bitmap; } You need to adapt this function to explicitly call virReportOOMError in the place above and note that in the docs. Peter

On 07/04/2013 02:06 PM, Michal Privoznik wrote: [...]
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 13fd162..f7f05fd 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -1212,8 +1211,6 @@ static int virCgroupSetPartitionSuffix(const char *path, char **res)
ret = virCgroupPartitionEscape(&(tokens[i])); if (ret < 0) { - if (ret == -ENOMEM) - virReportOOMError();
virCgroupPartitionEscape() does not report OOMError, either keep it here or change the VIR_INSERT_ELEMENT and others inside that function to report the error. [...]
diff --git a/src/util/virlog.c b/src/util/virlog.c index 064f8e8..1dcbd61 100644 --- a/src/util/virlog.c +++ b/src/util/virlog.c @@ -563,7 +563,7 @@ virLogDefineFilter(const char *match, goto cleanup; } i = virLogNbFilters; - if (VIR_REALLOC_N(virLogFilters, virLogNbFilters + 1)) { + if (VIR_REALLOC_N_QUIET(virLogFilters, virLogNbFilters + 1)) { i = -1; VIR_FREE(mdup); goto cleanup;
There are couple more places in this file where the OOMError wasn't reported and is going to be reported after this series takes place. The problem is that the error would be reported after virLogLock() and that would lead to either a deadlock or infinite recursion (depending on where it would happen). Such occurrences need to be fixed as well. [...]
diff --git a/src/util/virpci.c b/src/util/virpci.c index 9ed257e..e42f6fa 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -2395,7 +2357,6 @@ virPCIGetPhysicalFunction(const char *vf_sysfs_path, "with sysfs path '%s'", vf_sysfs_path);
if (virBuildPath(&device_link, vf_sysfs_path, "physfn") == -1) { - virReportOOMError();
Same problem as with the virCgroupPartitionEscape(). ACK with mentioned things fixed. Martin

--- src/vbox/vbox_MSCOMGlue.c | 8 +-- src/vbox/vbox_XPCOMCGlue.c | 4 +- src/vbox/vbox_tmpl.c | 126 +++++++++++---------------------------------- 3 files changed, 32 insertions(+), 106 deletions(-) diff --git a/src/vbox/vbox_MSCOMGlue.c b/src/vbox/vbox_MSCOMGlue.c index 706f1ba..c87004a 100644 --- a/src/vbox/vbox_MSCOMGlue.c +++ b/src/vbox/vbox_MSCOMGlue.c @@ -372,10 +372,8 @@ vboxLookupRegistryValue(HKEY key, const char *keyName, const char *valueName) } /* +1 for the null-terminator if it's missing */ - if (VIR_ALLOC_N(value, length + 1) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(value, length + 1) < 0) goto cleanup; - } status = RegQueryValueEx(key, valueName, NULL, NULL, (LPBYTE)value, &length); @@ -534,10 +532,8 @@ vboxComInitialize_v2(const char *pszVirtualBoxIID, IVirtualBox **ppVirtualBox, CoInitialize(NULL); if (virAsprintf(&mbsVirtualBoxIID, "{%s}", pszVirtualBoxIID) < 0 || - virAsprintf(&mbsSessionIID, "{%s}", pszSessionIID) < 0) { - virReportOOMError(); + virAsprintf(&mbsSessionIID, "{%s}", pszSessionIID) < 0) goto cleanup; - } if (vboxUtf8ToUtf16(mbsVirtualBoxIID, &wcsVirtualBoxIID) < 0 || vboxUtf8ToUtf16(mbsSessionIID, &wcsSessionIID) < 0) { diff --git a/src/vbox/vbox_XPCOMCGlue.c b/src/vbox/vbox_XPCOMCGlue.c index 271d9ef..f2a9ccb 100644 --- a/src/vbox/vbox_XPCOMCGlue.c +++ b/src/vbox/vbox_XPCOMCGlue.c @@ -94,10 +94,8 @@ tryLoadOne(const char *dir, bool setAppHome, bool ignoreMissing, PFNVBOXGETXPCOMCFUNCTIONS pfnGetFunctions; if (dir != NULL) { - if (virAsprintf(&name, "%s/%s", dir, DYNLIB_NAME) < 0) { - virReportOOMError(); + if (virAsprintf(&name, "%s/%s", dir, DYNLIB_NAME) < 0) return -1; - } if (!virFileExists(name)) { if (!ignoreMissing) { diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index d6d34c1..eafccef 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -1036,10 +1036,8 @@ static virDrvOpenStatus vboxConnectOpen(virConnectPtr conn, } } - if (VIR_ALLOC(data) < 0) { - virReportOOMError(); + if (VIR_ALLOC(data) < 0) return VIR_DRV_OPEN_ERROR; - } if (!(data->caps = vboxCapsInit()) || vboxInitialize(data) < 0 || @@ -2240,10 +2238,8 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) { /* Flags checked by virDomainDefFormat */ - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) goto cleanup; - } vboxIIDFromUUID(&iid, dom->uuid); rc = VBOX_OBJECT_GET_MACHINE(iid.value, &machine); @@ -2420,12 +2416,9 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) { if (VIR_ALLOC(def->videos[0]->accel) >= 0) { def->videos[0]->accel->support3d = accelerate3DEnabled; def->videos[0]->accel->support2d = accelerate2DEnabled; - } else - virReportOOMError(); - } else - virReportOOMError(); - } else - virReportOOMError(); + } + } + } } /* dump display options vrdp/gui/sdl */ @@ -2631,8 +2624,7 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) { def->disks[i]->device = VIR_DOMAIN_DISK_DEVICE_DISK; def->disks[i]->bus = VIR_DOMAIN_DISK_BUS_IDE; def->disks[i]->type = VIR_DOMAIN_DISK_TYPE_FILE; - } else - virReportOOMError(); + } } } @@ -2726,13 +2718,11 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) { if (VIR_ALLOC_N(def->disks, def->ndisks) >= 0) { for (i = 0; i < def->ndisks; i++) { if (VIR_ALLOC(def->disks[i]) < 0) { - virReportOOMError(); error = true; break; } } } else { - virReportOOMError(); error = true; } @@ -2785,7 +2775,6 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) { if (!(def->disks[diskCount]->src)) { VBOX_RELEASE(medium); VBOX_RELEASE(storageController); - virReportOOMError(); error = true; break; } @@ -2861,10 +2850,8 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) { machine->vtbl->GetSharedFolders); if (sharedFolders.count > 0) { - if (VIR_ALLOC_N(def->fss, sharedFolders.count) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(def->fss, sharedFolders.count) < 0) goto sharedFoldersCleanup; - } for (i = 0; i < sharedFolders.count; i++) { ISharedFolder *sharedFolder = sharedFolders.items[i]; @@ -2874,10 +2861,8 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) { char *hostPath = NULL; PRBool writable = PR_FALSE; - if (VIR_ALLOC(def->fss[i]) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def->fss[i]) < 0) goto sharedFoldersCleanup; - } def->fss[i]->type = VIR_DOMAIN_FS_TYPE_MOUNT; @@ -2933,9 +2918,7 @@ sharedFoldersCleanup: /* Allocate memory for the networkcards which are enabled */ if ((def->nnets > 0) && (VIR_ALLOC_N(def->nets, def->nnets) >= 0)) { for (i = 0; i < def->nnets; i++) { - if (VIR_ALLOC(def->nets[i]) >= 0) { - } else - virReportOOMError(); + ignore_value(VIR_ALLOC(def->nets[i])); } } @@ -3082,11 +3065,9 @@ sharedFoldersCleanup: } else { VIR_FREE(def->sounds); def->nsounds = 0; - virReportOOMError(); } } else { def->nsounds = 0; - virReportOOMError(); } } VBOX_RELEASE(audioAdapter); @@ -3122,11 +3103,9 @@ sharedFoldersCleanup: def->ndisks--; } else { def->ndisks--; - virReportOOMError(); } } else { def->ndisks--; - virReportOOMError(); } VBOX_UTF8_FREE(location); @@ -3170,11 +3149,9 @@ sharedFoldersCleanup: def->ndisks--; } else { def->ndisks--; - virReportOOMError(); } } else { def->ndisks--; - virReportOOMError(); } VBOX_UTF8_FREE(location); @@ -3211,9 +3188,7 @@ sharedFoldersCleanup: /* Allocate memory for the serial ports which are enabled */ if ((def->nserials > 0) && (VIR_ALLOC_N(def->serials, def->nserials) >= 0)) { for (i = 0; i < def->nserials; i++) { - if (VIR_ALLOC(def->serials[i]) >= 0) { - } else - virReportOOMError(); + ignore_value(VIR_ALLOC(def->serials[i])); } } @@ -3297,9 +3272,7 @@ sharedFoldersCleanup: /* Allocate memory for the parallel ports which are enabled */ if ((def->nparallels > 0) && (VIR_ALLOC_N(def->parallels, def->nparallels) >= 0)) { for (i = 0; i < def->nparallels; i++) { - if (VIR_ALLOC(def->parallels[i]) >= 0) { - } else - virReportOOMError(); + ignore_value(VIR_ALLOC(def->parallels[i])); } } @@ -3419,12 +3392,10 @@ sharedFoldersCleanup: VBOX_UTF8_FREE(productIdUtf8); USBFilterCount++; - } else - virReportOOMError(); + } } } - } else - virReportOOMError(); + } } } @@ -3628,9 +3599,7 @@ vboxStartMachine(virDomainPtr dom, int i, IMachine *machine, if (guiPresent) { if (guiDisplay) { char *displayutf8; - if (virAsprintf(&displayutf8, "DISPLAY=%s", guiDisplay) < 0) - virReportOOMError(); - else { + if (virAsprintf(&displayutf8, "DISPLAY=%s", guiDisplay) >= 0) { VBOX_UTF8_TO_UTF16(displayutf8, &env); VIR_FREE(displayutf8); } @@ -3643,9 +3612,7 @@ vboxStartMachine(virDomainPtr dom, int i, IMachine *machine, if (sdlPresent) { if (sdlDisplay) { char *displayutf8; - if (virAsprintf(&displayutf8, "DISPLAY=%s", sdlDisplay) < 0) - virReportOOMError(); - else { + if (virAsprintf(&displayutf8, "DISPLAY=%s", sdlDisplay) >= 0) { VBOX_UTF8_TO_UTF16(displayutf8, &env); VIR_FREE(displayutf8); } @@ -4949,9 +4916,7 @@ vboxAttachUSB(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine) /* Zero pad for nice alignment when fewer than 9999 * devices. */ - if (virAsprintf(&filtername, "filter%04d", i) < 0) { - virReportOOMError(); - } else { + if (virAsprintf(&filtername, "filter%04d", i) >= 0) { VBOX_UTF8_TO_UTF16(filtername, &filternameUtf16); VIR_FREE(filtername); USBController->vtbl->CreateDeviceFilter(USBController, @@ -5403,10 +5368,8 @@ static int vboxDomainAttachDeviceImpl(virDomainPtr dom, virDomainDeviceDefPtr dev = NULL; nsresult rc; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return ret; - } if (VIR_STRDUP(def->os.type, "hvm") < 0) goto cleanup; @@ -5634,10 +5597,8 @@ static int vboxDomainDetachDevice(virDomainPtr dom, const char *xml) { virDomainDeviceDefPtr dev = NULL; nsresult rc; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return ret; - } if (VIR_STRDUP(def->os.type, "hvm") < 0) goto cleanup; @@ -5798,10 +5759,8 @@ vboxDomainSnapshotGetAll(virDomainPtr dom, if (count == 0) goto out; - if (VIR_ALLOC_N(list, count) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(list, count) < 0) goto error; - } #if VBOX_API_VERSION < 4000 rc = machine->vtbl->GetSnapshot(machine, empty.value, list); @@ -6066,7 +6025,7 @@ vboxDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot, goto cleanup; if (VIR_ALLOC(def) < 0) - goto no_memory; + goto cleanup; if (VIR_STRDUP(def->name, snapshot->name) < 0) goto cleanup; @@ -6116,7 +6075,7 @@ vboxDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot, VBOX_UTF16_FREE(str16); if (VIR_STRDUP(def->parent, str8) < 0) { VBOX_UTF8_FREE(str8); - goto no_memory; + goto cleanup; } VBOX_UTF8_FREE(str8); } @@ -6143,10 +6102,6 @@ cleanup: VBOX_RELEASE(machine); vboxIIDUnalloc(&domiid); return ret; - -no_memory: - virReportOOMError(); - goto cleanup; } static int @@ -6229,10 +6184,8 @@ vboxDomainSnapshotListNames(virDomainPtr dom, if (flags & VIR_DOMAIN_SNAPSHOT_LIST_ROOTS) { vboxIID empty = VBOX_IID_INITIALIZER; - if (VIR_ALLOC_N(snapshots, 1) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(snapshots, 1) < 0) goto cleanup; - } #if VBOX_API_VERSION < 4000 rc = machine->vtbl->GetSnapshot(machine, empty.value, snapshots); #else /* VBOX_API_VERSION >= 4000 */ @@ -6266,7 +6219,6 @@ vboxDomainSnapshotListNames(virDomainPtr dom, VBOX_UTF16_TO_UTF8(nameUtf16, &name); VBOX_UTF16_FREE(nameUtf16); if (VIR_STRDUP(names[i], name) < 0) { - virReportOOMError(); VBOX_UTF8_FREE(name); goto cleanup; } @@ -7218,7 +7170,6 @@ static IVirtualBoxCallback *vboxAllocCallbackObj(void) { */ if ((VIR_ALLOC(vboxCallback) < 0) || (VIR_ALLOC(vboxCallback->vtbl) < 0)) { VIR_FREE(vboxCallback); - virReportOOMError(); return NULL; } @@ -7795,7 +7746,6 @@ static virNetworkPtr vboxNetworkDefineCreateXML(virConnectPtr conn, const char * if (virAsprintf(&networkNameUtf8, "HostInterfaceNetworking-%s", networkInterfaceNameUtf8) < 0) { VBOX_RELEASE(host); VBOX_RELEASE(networkInterface); - virReportOOMError(); goto cleanup; } } @@ -7951,10 +7901,8 @@ static int vboxNetworkUndefineDestroy(virNetworkPtr network, bool removeinterfac * show up in the net-list in virsh */ - if (virAsprintf(&networkNameUtf8, "HostInterfaceNetworking-%s", network->name) < 0) { - virReportOOMError(); + if (virAsprintf(&networkNameUtf8, "HostInterfaceNetworking-%s", network->name) < 0) goto cleanup; - } VBOX_UTF8_TO_UTF16(network->name, &networkInterfaceNameUtf16); @@ -8040,10 +7988,8 @@ static int vboxNetworkCreate(virNetworkPtr network) { * server by giving the machine static IP */ - if (virAsprintf(&networkNameUtf8, "HostInterfaceNetworking-%s", network->name) < 0) { - virReportOOMError(); + if (virAsprintf(&networkNameUtf8, "HostInterfaceNetworking-%s", network->name) < 0) goto cleanup; - } VBOX_UTF8_TO_UTF16(network->name, &networkInterfaceNameUtf16); @@ -8112,21 +8058,15 @@ static char *vboxNetworkGetXMLDesc(virNetworkPtr network, virCheckFlags(0, NULL); - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) goto cleanup; - } - if (VIR_ALLOC(ipdef) < 0) { - virReportOOMError(); + if (VIR_ALLOC(ipdef) < 0) goto cleanup; - } def->ips = ipdef; def->nips = 1; - if (virAsprintf(&networkNameUtf8, "HostInterfaceNetworking-%s", network->name) < 0) { - virReportOOMError(); + if (virAsprintf(&networkNameUtf8, "HostInterfaceNetworking-%s", network->name) < 0) goto cleanup; - } VBOX_UTF8_TO_UTF16(network->name, &networkInterfaceNameUtf16); @@ -8190,7 +8130,6 @@ static char *vboxNetworkGetXMLDesc(virNetworkPtr network, } } else { ipdef->nranges = 0; - virReportOOMError(); } ipdef->nhosts = 1; @@ -8251,8 +8190,6 @@ static char *vboxNetworkGetXMLDesc(virNetworkPtr network, DEBUGIID("Network UUID", vboxnet0IID.value); vboxIIDUnalloc(&vboxnet0IID); VBOX_UTF16_FREE(networkNameUtf16); - } else { - virReportOOMError(); } } @@ -9182,7 +9119,6 @@ vboxDomainScreenshot(virDomainPtr dom, } if (virAsprintf(&tmp, "%s/cache/libvirt/vbox.screendump.XXXXXX", LOCALSTATEDIR) < 0) { - virReportOOMError(); VBOX_RELEASE(machine); return NULL; } @@ -9303,7 +9239,7 @@ vboxConnectListAllDomains(virConnectPtr conn, !MATCH(VIR_CONNECT_LIST_DOMAINS_NO_MANAGEDSAVE))) { if (domains && VIR_ALLOC_N(*domains, 1) < 0) - goto no_memory; + goto cleanup; ret = 0; goto cleanup; @@ -9318,7 +9254,7 @@ vboxConnectListAllDomains(virConnectPtr conn, if (domains && VIR_ALLOC_N(doms, machines.count + 1) < 0) - goto no_memory; + goto cleanup; for (i = 0; i < machines.count; i++) { IMachine *machine = machines.items[i]; @@ -9419,10 +9355,6 @@ cleanup: vboxArrayRelease(&machines); return ret; - -no_memory: - virReportOOMError(); - goto cleanup; } #undef MATCH -- 1.8.1.5

On 07/04/2013 02:06 PM, Michal Privoznik wrote:
--- src/vbox/vbox_MSCOMGlue.c | 8 +-- src/vbox/vbox_XPCOMCGlue.c | 4 +- src/vbox/vbox_tmpl.c | 126 +++++++++++---------------------------------- 3 files changed, 32 insertions(+), 106 deletions(-)
ACK Jan

--- src/vmware/vmware_conf.c | 33 +++++++-------------------------- src/vmware/vmware_driver.c | 4 +--- 2 files changed, 8 insertions(+), 29 deletions(-) diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c index 9d3d37e..b6d20ea 100644 --- a/src/vmware/vmware_conf.c +++ b/src/vmware/vmware_conf.c @@ -77,10 +77,8 @@ vmwareCapsInit(void) NULL, NULL, 0, NULL) == NULL) goto error; - if (VIR_ALLOC(cpu) < 0) { - virReportOOMError(); + if (VIR_ALLOC(cpu) < 0) goto error; - } if (!(cpu->arch = caps->host.arch)) { virReportOOMError(); @@ -315,18 +313,9 @@ error: int vmwareConstructVmxPath(char *directoryName, char *name, char **vmxPath) { - if (directoryName != NULL) { - if (virAsprintf(vmxPath, "%s/%s.vmx", directoryName, name) < 0) { - virReportOOMError(); - return -1; - } - } else { - if (virAsprintf(vmxPath, "%s.vmx", name) < 0) { - virReportOOMError(); - return -1; - } - } - return 0; + if (directoryName != NULL) + return virAsprintf(vmxPath, "%s/%s.vmx", directoryName, name); + return virAsprintf(vmxPath, "%s.vmx", name); } int @@ -385,10 +374,8 @@ vmwareVmxPath(virDomainDefPtr vmdef, char **vmxPath) goto cleanup; } - if (vmwareConstructVmxPath(directoryName, vmdef->name, vmxPath) < 0) { - virReportOOMError(); + if (vmwareConstructVmxPath(directoryName, vmdef->name, vmxPath) < 0) goto cleanup; - } ret = 0; @@ -427,11 +414,7 @@ vmwareMoveFile(char *srcFile, char *dstFile) int vmwareMakePath(char *srcDir, char *srcName, char *srcExt, char **outpath) { - if (virAsprintf(outpath, "%s/%s.%s", srcDir, srcName, srcExt) < 0) { - virReportOOMError(); - return -1; - } - return 0; + return virAsprintf(outpath, "%s/%s.%s", srcDir, srcName, srcExt); } int @@ -448,10 +431,8 @@ vmwareExtractPid(const char * vmxPath) goto cleanup; if (virAsprintf(&logFilePath, "%s/vmware.log", - vmxDir) < 0) { - virReportOOMError(); + vmxDir) < 0) goto cleanup; - } if ((logFile = fopen(logFilePath, "r")) == NULL) goto cleanup; diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c index ca6615f..988552f 100644 --- a/src/vmware/vmware_driver.c +++ b/src/vmware/vmware_driver.c @@ -126,10 +126,8 @@ vmwareConnectOpen(virConnectPtr conn, VIR_FREE(vmrun); } - if (VIR_ALLOC(driver) < 0) { - virReportOOMError(); + if (VIR_ALLOC(driver) < 0) return VIR_DRV_OPEN_ERROR; - } if (virMutexInit(&driver->lock) < 0) goto cleanup; -- 1.8.1.5

On 07/04/13 14:06, Michal Privoznik wrote:
--- src/vmware/vmware_conf.c | 33 +++++++-------------------------- src/vmware/vmware_driver.c | 4 +--- 2 files changed, 8 insertions(+), 29 deletions(-)
diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c index 9d3d37e..b6d20ea 100644 --- a/src/vmware/vmware_conf.c +++ b/src/vmware/vmware_conf.c
ACK, Peter

--- src/vmx/vmx.c | 92 +++++++++++++++-------------------------------------------- 1 file changed, 23 insertions(+), 69 deletions(-) diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index 5464d13..64bf4be 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -553,10 +553,8 @@ virVMXEscapeHex(const char *string, char escape, const char *special) ++length; } - if (VIR_ALLOC_N(escaped, length) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(escaped, length) < 0) return NULL; - } tmp1 = string; /* reading from this one */ tmp2 = escaped; /* writing to this one */ @@ -1121,10 +1119,8 @@ virVMXGatherSCSIControllers(virVMXContext *ctx, virDomainDefPtr def, int count = 0; int *autodetectedModels; - if (VIR_ALLOC_N(autodetectedModels, def->ndisks) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(autodetectedModels, def->ndisks) < 0) return -1; - } for (i = 0; i < def->ncontrollers; ++i) { controller = def->controllers[i]; @@ -1287,10 +1283,8 @@ virVMXParseConfig(virVMXContext *ctx, } /* Allocate domain def */ - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) goto cleanup; - } def->virtType = VIR_DOMAIN_VIRT_VMWARE; def->id = -1; @@ -1432,10 +1426,8 @@ virVMXParseConfig(virVMXContext *ctx, cpumasklen = 0; def->cpumask = virBitmapNew(VIR_DOMAIN_CPUMASK_LEN); - if (!def->cpumask) { - virReportOOMError(); + if (!def->cpumask) goto cleanup; - } while (*current != '\0') { virSkipSpaces(¤t); @@ -1551,10 +1543,8 @@ virVMXParseConfig(virVMXContext *ctx, /* FIXME */ /* def:graphics */ - if (VIR_ALLOC_N(def->graphics, 1) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(def->graphics, 1) < 0) goto cleanup; - } def->ngraphics = 0; @@ -1567,10 +1557,8 @@ virVMXParseConfig(virVMXContext *ctx, } /* def:disks: 4 * 15 scsi + 2 * 2 ide + 2 floppy = 66 */ - if (VIR_ALLOC_N(def->disks, 66) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(def->disks, 66) < 0) goto cleanup; - } def->ndisks = 0; @@ -1692,10 +1680,8 @@ virVMXParseConfig(virVMXContext *ctx, if (sharedFolder_maxNum > 0) { int number; - if (VIR_ALLOC_N(def->fss, sharedFolder_maxNum) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(def->fss, sharedFolder_maxNum) < 0) goto cleanup; - } def->nfss = 0; @@ -1713,10 +1699,8 @@ virVMXParseConfig(virVMXContext *ctx, } /* def:nets */ - if (VIR_ALLOC_N(def->nets, 4) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(def->nets, 4) < 0) goto cleanup; - } def->nnets = 0; @@ -1735,10 +1719,8 @@ virVMXParseConfig(virVMXContext *ctx, /* FIXME */ /* def:videos */ - if (VIR_ALLOC_N(def->videos, 1) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(def->videos, 1) < 0) goto cleanup; - } def->nvideos = 0; @@ -1755,10 +1737,8 @@ virVMXParseConfig(virVMXContext *ctx, /* FIXME */ /* def:serials */ - if (VIR_ALLOC_N(def->serials, 4) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(def->serials, 4) < 0) goto cleanup; - } def->nserials = 0; @@ -1774,10 +1754,8 @@ virVMXParseConfig(virVMXContext *ctx, } /* def:parallels */ - if (VIR_ALLOC_N(def->parallels, 3) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(def->parallels, 3) < 0) goto cleanup; - } def->nparallels = 0; @@ -1832,10 +1810,8 @@ virVMXParseVNC(virConfPtr conf, virDomainGraphicsDefPtr *def) return 0; } - if (VIR_ALLOC(*def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(*def) < 0) goto failure; - } (*def)->type = VIR_DOMAIN_GRAPHICS_TYPE_VNC; @@ -2006,10 +1982,8 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con return -1; } - if (VIR_ALLOC(*def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(*def) < 0) return -1; - } (*def)->device = device; (*def)->bus = busType; @@ -2032,10 +2006,8 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con goto cleanup; } - if (virAsprintf(&prefix, "scsi%d:%d", controllerOrBus, unit) < 0) { - virReportOOMError(); + if (virAsprintf(&prefix, "scsi%d:%d", controllerOrBus, unit) < 0) goto cleanup; - } (*def)->dst = virIndexToDiskName @@ -2058,10 +2030,8 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con goto cleanup; } - if (virAsprintf(&prefix, "ide%d:%d", controllerOrBus, unit) < 0) { - virReportOOMError(); + if (virAsprintf(&prefix, "ide%d:%d", controllerOrBus, unit) < 0) goto cleanup; - } (*def)->dst = virIndexToDiskName(controllerOrBus * 2 + unit, "hd"); @@ -2091,10 +2061,8 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con goto cleanup; } - if (virAsprintf(&prefix, "floppy%d", unit) < 0) { - virReportOOMError(); + if (virAsprintf(&prefix, "floppy%d", unit) < 0) goto cleanup; - } (*def)->dst = virIndexToDiskName(unit, "fd"); @@ -2347,10 +2315,8 @@ int virVMXParseFileSystem(virConfPtr conf, int number, virDomainFSDefPtr *def) return -1; } - if (VIR_ALLOC(*def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(*def) < 0) return -1; - } (*def)->type = VIR_DOMAIN_FS_TYPE_MOUNT; @@ -2472,10 +2438,8 @@ virVMXParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def) return -1; } - if (VIR_ALLOC(*def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(*def) < 0) return -1; - } snprintf(prefix, sizeof(prefix), "ethernet%d", controller); @@ -2691,10 +2655,8 @@ virVMXParseSerial(virVMXContext *ctx, virConfPtr conf, int port, return -1; } - if (VIR_ALLOC(*def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(*def) < 0) return -1; - } (*def)->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL; @@ -2782,10 +2744,8 @@ virVMXParseSerial(virVMXContext *ctx, virConfPtr conf, int port, goto cleanup; if (virAsprintf(&(*def)->source.data.tcp.service, "%d", - parsedUri->port) < 0) { - virReportOOMError(); + parsedUri->port) < 0) goto cleanup; - } /* See vSphere API documentation about VirtualSerialPortURIBackingInfo */ if (parsedUri->scheme == NULL || @@ -2884,10 +2844,8 @@ virVMXParseParallel(virVMXContext *ctx, virConfPtr conf, int port, return -1; } - if (VIR_ALLOC(*def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(*def) < 0) return -1; - } (*def)->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL; @@ -2982,10 +2940,8 @@ virVMXParseSVGA(virConfPtr conf, virDomainVideoDefPtr *def) return -1; } - if (VIR_ALLOC(*def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(*def) < 0) return -1; - } (*def)->type = VIR_DOMAIN_VIDEO_TYPE_VMVGA; @@ -3342,10 +3298,8 @@ virVMXFormatConfig(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virDomainDe } /* Get final VMX output */ - if (virBufferError(&buffer)) { - virReportOOMError(); + if (virBufferError(&buffer)) goto cleanup; - } vmx = virBufferContentAndReset(&buffer); -- 1.8.1.5

On 07/04/13 14:06, Michal Privoznik wrote:
--- src/vmx/vmx.c | 92 +++++++++++++++-------------------------------------------- 1 file changed, 23 insertions(+), 69 deletions(-)
diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index 5464d13..64bf4be 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c
...
@@ -3342,10 +3298,8 @@ virVMXFormatConfig(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virDomainDe }
/* Get final VMX output */ - if (virBufferError(&buffer)) { - virReportOOMError(); + if (virBufferError(&buffer))
virBufferError isn't adapted to report errors, thus this hunk would remove the error. NACK to this hunk.
goto cleanup; - }
vmx = virBufferContentAndReset(&buffer);
ACK to the rest of this patch. Peter

--- src/xen/block_stats.c | 8 ++------ src/xen/xen_driver.c | 42 +++++++++++------------------------------- src/xen/xen_hypervisor.c | 17 ++++++----------- src/xen/xen_inotify.c | 4 +--- src/xen/xend_internal.c | 38 ++++++++++---------------------------- src/xen/xm_internal.c | 24 ++++++------------------ src/xen/xs_internal.c | 24 ++++++------------------ 7 files changed, 42 insertions(+), 115 deletions(-) diff --git a/src/xen/block_stats.c b/src/xen/block_stats.c index ebb91ea..5824518 100644 --- a/src/xen/block_stats.c +++ b/src/xen/block_stats.c @@ -114,10 +114,8 @@ read_bd_stat(int device, int domid, const char *str) int64_t r; for (i = 0; i < ARRAY_CARDINALITY(paths); ++i) { - if (virAsprintf(&path, paths[i], domid, device, str) < 0) { - virReportOOMError(); + if (virAsprintf(&path, paths[i], domid, device, str) < 0) return -1; - } r = read_stat(path); @@ -296,10 +294,8 @@ xenLinuxDomainDeviceID(int domid, const char *path) if (VIR_STRDUP(mod_path, path) < 0) return -1; } else { - if (virAsprintf(&mod_path, "/dev/%s", path) < 0) { - virReportOOMError(); + if (virAsprintf(&mod_path, "/dev/%s", path) < 0) return -1; - } } retval = -1; diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c index f69feb5..19ad755 100644 --- a/src/xen/xen_driver.c +++ b/src/xen/xen_driver.c @@ -208,20 +208,14 @@ xenDomainUsedCpus(virDomainPtr dom) if (xenUnifiedNodeGetInfo(dom->conn, &nodeinfo) < 0) return NULL; - if (!(cpulist = virBitmapNew(priv->nbNodeCpus))) { - virReportOOMError(); + if (!(cpulist = virBitmapNew(priv->nbNodeCpus))) goto done; - } - if (VIR_ALLOC_N(cpuinfo, nb_vcpu) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(cpuinfo, nb_vcpu) < 0) goto done; - } cpumaplen = VIR_CPU_MAPLEN(VIR_NODEINFO_MAXCPUS(nodeinfo)); if (xalloc_oversized(nb_vcpu, cpumaplen) || - VIR_ALLOC_N(cpumap, nb_vcpu * cpumaplen) < 0) { - virReportOOMError(); + VIR_ALLOC_N(cpumap, nb_vcpu * cpumaplen) < 0) goto done; - } if ((ncpus = xenUnifiedDomainGetVcpus(dom, cpuinfo, nb_vcpu, cpumap, cpumaplen)) >= 0) { @@ -415,10 +409,8 @@ xenUnifiedConnectOpen(virConnectPtr conn, virConnectAuthPtr auth, unsigned int f return VIR_DRV_OPEN_ERROR; /* Allocate per-connection private data. */ - if (VIR_ALLOC(priv) < 0) { - virReportOOMError(); + if (VIR_ALLOC(priv) < 0) return VIR_DRV_OPEN_ERROR; - } if (virMutexInit(&priv->lock) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot initialize mutex")); @@ -856,10 +848,8 @@ xenUnifiedDomainIsPersistent(virDomainPtr dom) /* If its running there's no official way to tell, so we * go behind xend's back & look at the config dir */ virUUIDFormat(dom->uuid, uuidstr); - if (virAsprintf(&path, "%s/%s", XEND_DOMAINS_DIR, uuidstr) < 0) { - virReportOOMError(); + if (virAsprintf(&path, "%s/%s", XEND_DOMAINS_DIR, uuidstr) < 0) goto cleanup; - } if (access(path, R_OK) == 0) ret = 1; else if (errno == ENOENT) @@ -1202,10 +1192,8 @@ xenUnifiedDomainManagedSavePath(xenUnifiedPrivatePtr priv, { char *ret; - if (virAsprintf(&ret, "%s/%s.save", priv->saveDir, def->name) < 0) { - virReportOOMError(); + if (virAsprintf(&ret, "%s/%s.save", priv->saveDir, def->name) < 0) return NULL; - } VIR_DEBUG("managed save image: %s", ret); return ret; @@ -1617,10 +1605,8 @@ xenUnifiedConnectDomainXMLToNative(virConnectPtr conn, if (!conf) goto cleanup; - if (VIR_ALLOC_N(ret, len) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(ret, len) < 0) goto cleanup; - } if (virConfWriteMem(ret, &len, conf) < 0) { VIR_FREE(ret); @@ -2473,10 +2459,8 @@ xenUnifiedNodeDeviceAssignedDomainId(virNodeDevicePtr dev) return ret; } if (numdomains > 0){ - if (VIR_ALLOC_N(ids, numdomains) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(ids, numdomains) < 0) goto out; - } if ((numdomains = xenUnifiedConnectListDomains(conn, &ids[0], numdomains)) < 0) { goto out; } @@ -2487,10 +2471,8 @@ xenUnifiedNodeDeviceAssignedDomainId(virNodeDevicePtr dev) goto out; if (virAsprintf(&bdf, "%04x:%02x:%02x.%0x", - domain, bus, slot, function) < 0) { - virReportOOMError(); + domain, bus, slot, function) < 0) goto out; - } xenUnifiedLock(priv); /* Check if bdf is assigned to one of active domains */ @@ -2824,7 +2806,7 @@ xenUnifiedAddDomainInfo(xenUnifiedDomainInfoListPtr list, } if (VIR_ALLOC(info) < 0) - goto memory_error; + goto error; if (VIR_STRDUP(info->name, name) < 0) goto error; @@ -2834,14 +2816,12 @@ xenUnifiedAddDomainInfo(xenUnifiedDomainInfoListPtr list, /* Make space on list */ n = list->count; if (VIR_REALLOC_N(list->doms, n + 1) < 0) { - goto memory_error; + goto error; } list->doms[n] = info; list->count++; return 0; -memory_error: - virReportOOMError(); error: if (info) VIR_FREE(info->name); diff --git a/src/xen/xen_hypervisor.c b/src/xen/xen_hypervisor.c index 9d9c3ee..8ce5d48 100644 --- a/src/xen/xen_hypervisor.c +++ b/src/xen/xen_hypervisor.c @@ -1509,10 +1509,8 @@ virXen_setvcpumap(int handle, /* The allocated memory to cpumap must be 'sizeof(uint64_t)' byte * * for Xen, and also nr_cpus must be 'sizeof(uint64_t) * 8' */ if (maplen < 8) { - if (VIR_ALLOC_N(new, sizeof(uint64_t)) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(new, sizeof(uint64_t)) < 0) return -1; - } memcpy(new, cpumap, maplen); bitmap = new; nr_cpus = sizeof(uint64_t) * 8; @@ -1829,10 +1827,8 @@ xenHypervisorInit(struct xenHypervisorVersions *override_versions) */ hv_versions.hypervisor = 2; - if (VIR_ALLOC(ipt) < 0) { - virReportOOMError(); + if (VIR_ALLOC(ipt) < 0) return -1; - } /* Currently consider RHEL5.0 Fedora7, xen-3.1, and xen-unstable */ hv_versions.sys_interface = 2; /* XEN_SYSCTL_INTERFACE_VERSION */ if (virXen_getdomaininfo(fd, 0, &info) == 1) { @@ -2265,11 +2261,10 @@ xenHypervisorMakeCapabilitiesSunOS(virConnectPtr conn) } } - if ((caps = xenHypervisorBuildCapabilities(conn, - virArchFromHost(), - pae, hvm, - guest_arches, i)) == NULL) - virReportOOMError(); + caps = xenHypervisorBuildCapabilities(conn, + virArchFromHost(), + pae, hvm, + guest_arches, i); return caps; } diff --git a/src/xen/xen_inotify.c b/src/xen/xen_inotify.c index 8266576..04ac083 100644 --- a/src/xen/xen_inotify.c +++ b/src/xen/xen_inotify.c @@ -360,10 +360,8 @@ xenInotifyOpen(virConnectPtr conn, priv->configDir = XEND_DOMAINS_DIR; priv->useXenConfigCache = 0; - if (VIR_ALLOC(priv->configInfoList) < 0) { - virReportOOMError(); + if (VIR_ALLOC(priv->configInfoList) < 0) return -1; - } /* populate initial list */ if (!(dh = opendir(priv->configDir))) { diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c index 3c05dff..70718ff 100644 --- a/src/xen/xend_internal.c +++ b/src/xen/xend_internal.c @@ -283,10 +283,8 @@ xend_req(int fd, char **content) int content_length = 0; int retcode = 0; - if (VIR_ALLOC_N(buffer, buffer_size) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(buffer, buffer_size) < 0) return -1; - } while (sreads(fd, buffer, buffer_size) > 0) { if (STREQ(buffer, "\r\n")) @@ -315,10 +313,8 @@ xend_req(int fd, char **content) /* Allocate one byte beyond the end of the largest buffer we will read. Combined with the fact that VIR_ALLOC_N zeros the returned buffer, this guarantees that "content" will always be NUL-terminated. */ - if (VIR_ALLOC_N(*content, content_length + 1) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(*content, content_length + 1) < 0) return -1; - } ret = sread(fd, *content, content_length); if (ret < 0) @@ -762,10 +758,8 @@ xenDaemonListDomainsOld(virConnectPtr xend) count++; } - if (VIR_ALLOC_N(ret, count + 1) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(ret, count + 1) < 0) goto error; - } i = 0; for (_for_i = root, node = root->u.s.car; _for_i->kind == SEXPR_CONS; @@ -1073,7 +1067,7 @@ sexpr_to_xend_topology(const struct sexpr *root, virCapsPtr caps) if (STRPREFIX(cur, "no cpus")) { nb_cpus = 0; if (!(cpuset = virBitmapNew(numCpus))) - goto memory_error; + goto error; } else { nb_cpus = virBitmapParse(cur, 'n', &cpuset, numCpus); if (nb_cpus < 0) @@ -1082,7 +1076,7 @@ sexpr_to_xend_topology(const struct sexpr *root, virCapsPtr caps) if (VIR_ALLOC_N(cpuInfo, numCpus) < 0) { virBitmapFree(cpuset); - goto memory_error; + goto error; } for (n = 0, cpu = 0; cpu < numCpus; cpu++) { @@ -1095,7 +1089,7 @@ sexpr_to_xend_topology(const struct sexpr *root, virCapsPtr caps) virBitmapFree(cpuset); if (virCapabilitiesAddHostNUMACell(caps, cell, nb_cpus, 0, cpuInfo) < 0) - goto memory_error; + goto error; cpuInfo = NULL; } @@ -1107,10 +1101,6 @@ sexpr_to_xend_topology(const struct sexpr *root, virCapsPtr caps) virCapabilitiesClearHostNUMACellCPUTopology(cpuInfo, nb_cpus); VIR_FREE(cpuInfo); return -1; - - memory_error: - virReportOOMError(); - goto error; } @@ -1219,10 +1209,8 @@ xenDaemonOpen(virConnectPtr conn, goto failed; } else if (STRCASEEQ(conn->uri->scheme, "http")) { if (conn->uri->port && - virAsprintf(&port, "%d", conn->uri->port) == -1) { - virReportOOMError(); + virAsprintf(&port, "%d", conn->uri->port) == -1) goto failed; - } if (xenDaemonOpen_tcp(conn, conn->uri->server ? conn->uri->server : "localhost", @@ -1895,10 +1883,8 @@ xenDaemonDomainPinVcpu(virConnectPtr conn, if (ret == 0) { if (!def->cputune.vcpupin) { - if (VIR_ALLOC(def->cputune.vcpupin) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def->cputune.vcpupin) < 0) goto cleanup; - } def->cputune.nvcpupin = 0; } if (virDomainVcpuPinAdd(&def->cputune.vcpupin, @@ -2302,10 +2288,8 @@ xenDaemonAttachDeviceFlags(virConnectPtr conn, PCIAddr = dev->data.hostdev->source.subsys.u.pci.addr; if (virAsprintf(&target, "PCI device: %.4x:%.2x:%.2x", - PCIAddr.domain, PCIAddr.bus, PCIAddr.slot) < 0) { - virReportOOMError(); + PCIAddr.domain, PCIAddr.bus, PCIAddr.slot) < 0) goto cleanup; - } } else { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("unsupported device type")); @@ -3393,10 +3377,8 @@ virDomainXMLDevID(virConnectPtr conn, hostdef->source.subsys.u.pci.addr.domain, hostdef->source.subsys.u.pci.addr.bus, hostdef->source.subsys.u.pci.addr.slot, - hostdef->source.subsys.u.pci.addr.function) < 0) { - virReportOOMError(); + hostdef->source.subsys.u.pci.addr.function) < 0) return -1; - } strcpy(class, "pci"); diff --git a/src/xen/xm_internal.c b/src/xen/xm_internal.c index 7c05911..096f24f 100644 --- a/src/xen/xm_internal.c +++ b/src/xen/xm_internal.c @@ -237,10 +237,8 @@ xenXMConfigCacheAddFile(virConnectPtr conn, const char *filename) entry->def = NULL; } else { /* Completely new entry */ newborn = 1; - if (VIR_ALLOC(entry) < 0) { - virReportOOMError(); + if (VIR_ALLOC(entry) < 0) return -1; - } if (VIR_STRDUP(entry->filename, filename) < 0) { VIR_FREE(entry); return -1; @@ -1030,10 +1028,8 @@ xenXMDomainDefineXML(virConnectPtr conn, virDomainDefPtr def) if (virConfWriteFile(filename, conf) < 0) goto error; - if (VIR_ALLOC(entry) < 0) { - virReportOOMError(); + if (VIR_ALLOC(entry) < 0) goto error; - } if ((entry->refreshedAt = time(NULL)) == ((time_t)-1)) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -1257,20 +1253,16 @@ xenXMDomainAttachDeviceFlags(virConnectPtr conn, switch (dev->type) { case VIR_DOMAIN_DEVICE_DISK: { - if (virDomainDiskInsert(def, dev->data.disk) < 0) { - virReportOOMError(); + if (virDomainDiskInsert(def, dev->data.disk) < 0) goto cleanup; - } dev->data.disk = NULL; } break; case VIR_DOMAIN_DEVICE_NET: { - if (VIR_REALLOC_N(def->nets, def->nnets+1) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(def->nets, def->nnets+1) < 0) goto cleanup; - } def->nets[def->nnets++] = dev->data.net; dev->data.net = NULL; break; @@ -1444,10 +1436,8 @@ xenXMDomainGetAutostart(virDomainDefPtr def, char *config = xenXMDomainConfigName(def); int ret = -1; - if (!linkname || !config) { - virReportOOMError(); + if (!linkname || !config) goto cleanup; - } *autostart = virFileLinkPointsTo(linkname, config); if (*autostart < 0) { @@ -1474,10 +1464,8 @@ xenXMDomainSetAutostart(virDomainDefPtr def, char *config = xenXMDomainConfigName(def); int ret = -1; - if (!linkname || !config) { - virReportOOMError(); + if (!linkname || !config) goto cleanup; - } if (autostart) { if (symlink(config, linkname) < 0 && diff --git a/src/xen/xs_internal.c b/src/xen/xs_internal.c index cc55fde..e579453 100644 --- a/src/xen/xs_internal.c +++ b/src/xen/xs_internal.c @@ -132,18 +132,14 @@ xenStoreOpen(virConnectPtr conn, } /* Init activeDomainList */ - if (VIR_ALLOC(priv->activeDomainList) < 0) { - virReportOOMError(); + if (VIR_ALLOC(priv->activeDomainList) < 0) return -1; - } /* Init watch list before filling in domInfoList, so we can know if it is the first time through when the callback fires */ - if (VIR_ALLOC(priv->xsWatchList) < 0) { - virReportOOMError(); + if (VIR_ALLOC(priv->xsWatchList) < 0) return -1; - } /* This will get called once at start */ if (xenStoreAddWatch(conn, "@releaseDomain", @@ -656,10 +652,8 @@ xenStoreAddWatch(virConnectPtr conn, } } - if (VIR_ALLOC(watch) < 0) { - virReportOOMError(); + if (VIR_ALLOC(watch) < 0) goto error; - } watch->cb = cb; watch->opaque = opaque; @@ -669,10 +663,8 @@ xenStoreAddWatch(virConnectPtr conn, /* Make space on list */ n = list->count; - if (VIR_REALLOC_N(list->watches, n + 1) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(list->watches, n + 1) < 0) goto error; - } list->watches[n] = watch; list->count++; @@ -817,10 +809,8 @@ retry: if (new_domain_cnt < 0) return -1; - if (VIR_ALLOC_N(new_domids,new_domain_cnt) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(new_domids,new_domain_cnt) < 0) return -1; - } nread = xenStoreDoListDomains(conn, priv, new_domids, new_domain_cnt); if (nread != new_domain_cnt) { /* mismatch. retry this read */ @@ -901,10 +891,8 @@ retry: if (new_domain_cnt < 0) return -1; - if (VIR_ALLOC_N(new_domids,new_domain_cnt) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(new_domids,new_domain_cnt) < 0) return -1; - } nread = xenStoreDoListDomains(conn, priv, new_domids, new_domain_cnt); if (nread != new_domain_cnt) { /* mismatch. retry this read */ -- 1.8.1.5

On 07/04/13 14:06, Michal Privoznik wrote:
--- src/xen/block_stats.c | 8 ++------ src/xen/xen_driver.c | 42 +++++++++++------------------------------- src/xen/xen_hypervisor.c | 17 ++++++----------- src/xen/xen_inotify.c | 4 +--- src/xen/xend_internal.c | 38 ++++++++++---------------------------- src/xen/xm_internal.c | 24 ++++++------------------ src/xen/xs_internal.c | 24 ++++++------------------ 7 files changed, 42 insertions(+), 115 deletions(-)
ACK, Peter

--- src/xenapi/xenapi_driver.c | 29 ++++++++--------------------- src/xenapi/xenapi_utils.c | 11 ++++------- 2 files changed, 12 insertions(+), 28 deletions(-) diff --git a/src/xenapi/xenapi_driver.c b/src/xenapi/xenapi_driver.c index cc8da49..869ec76 100644 --- a/src/xenapi/xenapi_driver.c +++ b/src/xenapi/xenapi_driver.c @@ -77,10 +77,8 @@ getCapsObject(void) virCapsGuestDomainPtr domain1, domain2; virCapsPtr caps = virCapabilitiesNew(virArchFromHost(), 0, 0); - if (!caps) { - virReportOOMError(); + if (!caps) return NULL; - } guest1 = virCapabilitiesAddGuest(caps, "hvm", VIR_ARCH_X86_64, "", "", 0, NULL); if (!guest1) goto error_cleanup; @@ -155,15 +153,11 @@ xenapiConnectOpen(virConnectPtr conn, virConnectAuthPtr auth, goto error; } - if (VIR_ALLOC(privP) < 0) { - virReportOOMError(); + if (VIR_ALLOC(privP) < 0) goto error; - } - if (virAsprintf(&privP->url, "https://%s", conn->uri->server) < 0) { - virReportOOMError(); + if (virAsprintf(&privP->url, "https://%s", conn->uri->server) < 0) goto error; - } if (xenapiUtil_ParseQuery(conn, conn->uri, &privP->noVerify) < 0) goto error; @@ -409,12 +403,9 @@ xenapiNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info) if (xen_host_cpu_get_all(session, &host_cpu_set)) { host_cpu = host_cpu_set->contents[0]; xen_host_cpu_get_modelname(session, &modelname, host_cpu); - if (!virStrncpy(info->model, modelname, LIBVIRT_MODELNAME_LEN - 1, LIBVIRT_MODELNAME_LEN)) { - virReportOOMError(); - xen_host_cpu_set_free(host_cpu_set); - VIR_FREE(modelname); - return -1; - } + ignore_value(virStrncpy(info->model, modelname, + LIBVIRT_MODELNAME_LEN - 1, + LIBVIRT_MODELNAME_LEN)); xen_host_cpu_get_speed(session, &mhz, host_cpu); info->mhz = (unsigned long)mhz; info->cpus = host_cpu_set->size; @@ -1372,7 +1363,6 @@ xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) return NULL; } if (VIR_ALLOC(defPtr) < 0) { - virReportOOMError(); xen_vm_set_free(vms); return NULL; } @@ -1502,12 +1492,12 @@ xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) defPtr->nnets = vif_set->size; if (VIR_ALLOC_N(defPtr->nets, vif_set->size) < 0) { xen_vif_set_free(vif_set); - goto error_cleanup; + goto error; } for (i = 0; i < vif_set->size; i++) { if (VIR_ALLOC(defPtr->nets[i]) < 0) { xen_vif_set_free(vif_set); - goto error_cleanup; + goto error; } defPtr->nets[i]->type = VIR_DOMAIN_NET_TYPE_BRIDGE; vif = vif_set->contents[i]; @@ -1534,13 +1524,10 @@ xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) virDomainDefFree(defPtr); return xml; - error_cleanup: - virReportOOMError(); error: xen_vm_set_free(vms); virDomainDefFree(defPtr); return NULL; - } /* diff --git a/src/xenapi/xenapi_utils.c b/src/xenapi/xenapi_utils.c index 46e1aea..bf3dcaf 100644 --- a/src/xenapi/xenapi_utils.c +++ b/src/xenapi/xenapi_utils.c @@ -347,10 +347,8 @@ allocStringMap(xen_string_string_map **strings, char *key, char *val) int sz = ((*strings) == NULL) ? 0 : (*strings)->size; sz++; if (VIR_REALLOC_N(*strings, sizeof(xen_string_string_map) + - sizeof(xen_string_string_map_contents) * sz) < 0) { - virReportOOMError(); + sizeof(xen_string_string_map_contents) * sz) < 0) return -1; - } (*strings)->size = sz; if (VIR_STRDUP((*strings)->contents[sz-1].key, key) < 0 || VIR_STRDUP((*strings)->contents[sz-1].val, val) < 0) @@ -545,22 +543,21 @@ createVMRecordFromXml(virConnectPtr conn, virDomainDefPtr def, char *mac; if (VIR_ALLOC_N(mac, VIR_MAC_STRING_BUFLEN) < 0) - goto error_cleanup; + goto error; virMacAddrFormat(&def->nets[i]->mac, mac); if (createVifNetwork(conn, *vm, device_number, def->nets[i]->data.bridge.brname, mac) < 0) { VIR_FREE(mac); - goto error_cleanup; + virReportOOMError(); + goto error; } device_number++; } } return 0; - error_cleanup: - virReportOOMError(); error: xen_vm_record_free(*record); return -1; -- 1.8.1.5

On 07/04/2013 02:06 PM, Michal Privoznik wrote:
--- src/xenapi/xenapi_driver.c | 29 ++++++++--------------------- src/xenapi/xenapi_utils.c | 11 ++++------- 2 files changed, 12 insertions(+), 28 deletions(-)
diff --git a/src/xenapi/xenapi_driver.c b/src/xenapi/xenapi_driver.c index cc8da49..869ec76 100644 --- a/src/xenapi/xenapi_driver.c +++ b/src/xenapi/xenapi_driver.c @@ -409,12 +403,9 @@ xenapiNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info) if (xen_host_cpu_get_all(session, &host_cpu_set)) { host_cpu = host_cpu_set->contents[0]; xen_host_cpu_get_modelname(session, &modelname, host_cpu); - if (!virStrncpy(info->model, modelname, LIBVIRT_MODELNAME_LEN - 1, LIBVIRT_MODELNAME_LEN)) { - virReportOOMError(); - xen_host_cpu_set_free(host_cpu_set); - VIR_FREE(modelname); - return -1; - } + ignore_value(virStrncpy(info->model, modelname, + LIBVIRT_MODELNAME_LEN - 1, + LIBVIRT_MODELNAME_LEN)); xen_host_cpu_get_speed(session, &mhz, host_cpu); info->mhz = (unsigned long)mhz; info->cpus = host_cpu_set->size;
I think this hunk should be a separate commit, since you didn't add OOM error reporting to virStrncpy.
@@ -545,22 +543,21 @@ createVMRecordFromXml(virConnectPtr conn, virDomainDefPtr def, char *mac;
if (VIR_ALLOC_N(mac, VIR_MAC_STRING_BUFLEN) < 0) - goto error_cleanup; + goto error; virMacAddrFormat(&def->nets[i]->mac, mac);
if (createVifNetwork(conn, *vm, device_number, def->nets[i]->data.bridge.brname, mac) < 0) { VIR_FREE(mac); - goto error_cleanup; + virReportOOMError();
This can result in double OOM Error reporting if createVifNetwork fails on virAsprintf, we should use virAsprintfQuiet there instead.
+ goto error; } device_number++; } } return 0;
- error_cleanup: - virReportOOMError(); error: xen_vm_record_free(*record); return -1;
ACK Jan

--- src/xenxs/xen_sxpr.c | 112 ++++++++++++---------------- src/xenxs/xen_xm.c | 204 ++++++++++++++++++++++----------------------------- 2 files changed, 135 insertions(+), 181 deletions(-) diff --git a/src/xenxs/xen_sxpr.c b/src/xenxs/xen_sxpr.c index 394b814..13f9f32 100644 --- a/src/xenxs/xen_sxpr.c +++ b/src/xenxs/xen_sxpr.c @@ -89,10 +89,10 @@ xenParseSxprOS(const struct sexpr *node, { if (hvm) { if (sexpr_node_copy(node, "domain/image/hvm/loader", &def->os.loader) < 0) - goto no_memory; + goto error; if (def->os.loader == NULL) { if (sexpr_node_copy(node, "domain/image/hvm/kernel", &def->os.loader) < 0) - goto no_memory; + goto error; if (def->os.loader == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -101,23 +101,23 @@ xenParseSxprOS(const struct sexpr *node, } } else { if (sexpr_node_copy(node, "domain/image/hvm/kernel", &def->os.kernel) < 0) - goto no_memory; + goto error; if (sexpr_node_copy(node, "domain/image/hvm/ramdisk", &def->os.initrd) < 0) - goto no_memory; + goto error; if (sexpr_node_copy(node, "domain/image/hvm/args", &def->os.cmdline) < 0) - goto no_memory; + goto error; if (sexpr_node_copy(node, "domain/image/hvm/root", &def->os.root) < 0) - goto no_memory; + goto error; } } else { if (sexpr_node_copy(node, "domain/image/linux/kernel", &def->os.kernel) < 0) - goto no_memory; + goto error; if (sexpr_node_copy(node, "domain/image/linux/ramdisk", &def->os.initrd) < 0) - goto no_memory; + goto error; if (sexpr_node_copy(node, "domain/image/linux/args", &def->os.cmdline) < 0) - goto no_memory; + goto error; if (sexpr_node_copy(node, "domain/image/linux/root", &def->os.root) < 0) - goto no_memory; + goto error; } /* If HVM kenrel == loader, then old xend, so kill off kernel */ @@ -162,8 +162,7 @@ xenParseSxprOS(const struct sexpr *node, return 0; -no_memory: - virReportOOMError(); +error: return -1; } @@ -367,7 +366,7 @@ xenParseSxprDisks(virDomainDefPtr def, } if (VIR_ALLOC(disk) < 0) - goto no_memory; + goto error; if (dst == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -401,7 +400,7 @@ xenParseSxprDisks(virDomainDefPtr def, goto error; } else { if (VIR_ALLOC_N(disk->driverName, (offset-src)+1) < 0) - goto no_memory; + goto error; if (virStrncpy(disk->driverName, src, offset-src, (offset-src)+1) == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -498,7 +497,7 @@ xenParseSxprDisks(virDomainDefPtr def, disk->shared = true; if (VIR_REALLOC_N(def->disks, def->ndisks+1) < 0) - goto no_memory; + goto error; /* re-order disks if there is a bootable device */ if (STREQ_NULLABLE(bootable, "1")) { @@ -513,9 +512,6 @@ xenParseSxprDisks(virDomainDefPtr def, return 0; -no_memory: - virReportOOMError(); - error: virDomainDiskDefFree(disk); return -1; @@ -550,7 +546,7 @@ xenParseSxprNets(virDomainDefPtr def, type = sexpr_node(node, "device/vif/type"); if (VIR_ALLOC(net) < 0) - goto no_memory; + goto cleanup; if (tmp != NULL || (tmp2 != NULL && STREQ(tmp2, DEFAULT_VIF_SCRIPT))) { @@ -583,7 +579,7 @@ xenParseSxprNets(virDomainDefPtr def, goto cleanup; } else if (def->id != -1) { if (virAsprintf(&net->ifname, "vif%d.%d", def->id, vif_index) < 0) - goto no_memory; + goto cleanup; } tmp = sexpr_node(node, "device/vif/mac"); @@ -603,7 +599,7 @@ xenParseSxprNets(virDomainDefPtr def, goto cleanup; if (VIR_REALLOC_N(def->nets, def->nnets + 1) < 0) - goto no_memory; + goto cleanup; def->nets[def->nnets++] = net; vif_index++; @@ -612,8 +608,6 @@ xenParseSxprNets(virDomainDefPtr def, return 0; -no_memory: - virReportOOMError(); cleanup: virDomainNetDefFree(net); return -1; @@ -651,13 +645,13 @@ xenParseSxprSound(virDomainDefPtr def, if (VIR_ALLOC_N(def->sounds, VIR_DOMAIN_SOUND_MODEL_ES1370 + 1) < 0) - goto no_memory; + goto error; for (i = 0; i < (VIR_DOMAIN_SOUND_MODEL_ES1370 + 1); i++) { virDomainSoundDefPtr sound; if (VIR_ALLOC(sound) < 0) - goto no_memory; + goto error; sound->model = i; def->sounds[def->nsounds++] = sound; } @@ -681,7 +675,7 @@ xenParseSxprSound(virDomainDefPtr def, } if (VIR_ALLOC(sound) < 0) - goto no_memory; + goto error; if ((sound->model = virDomainSoundModelTypeFromString(model)) < 0) { VIR_FREE(sound); @@ -690,7 +684,7 @@ xenParseSxprSound(virDomainDefPtr def, if (VIR_REALLOC_N(def->sounds, def->nsounds+1) < 0) { virDomainSoundDefFree(sound); - goto no_memory; + goto error; } def->sounds[def->nsounds++] = sound; @@ -700,8 +694,6 @@ xenParseSxprSound(virDomainDefPtr def, return 0; -no_memory: - virReportOOMError(); error: return -1; } @@ -732,7 +724,7 @@ xenParseSxprUSB(virDomainDefPtr def, STREQ(tmp, "mouse")) { virDomainInputDefPtr input; if (VIR_ALLOC(input) < 0) - goto no_memory; + goto error; input->bus = VIR_DOMAIN_INPUT_BUS_USB; if (STREQ(tmp, "tablet")) input->type = VIR_DOMAIN_INPUT_TYPE_TABLET; @@ -741,7 +733,7 @@ xenParseSxprUSB(virDomainDefPtr def, if (VIR_REALLOC_N(def->inputs, def->ninputs+1) < 0) { VIR_FREE(input); - goto no_memory; + goto error; } def->inputs[def->ninputs++] = input; } else { @@ -752,8 +744,7 @@ xenParseSxprUSB(virDomainDefPtr def, } return 0; -no_memory: - virReportOOMError(); +error: return -1; } @@ -791,7 +782,7 @@ xenParseSxprGraphicsOld(virDomainDefPtr def, port = vncport; if (VIR_ALLOC(graphics) < 0) - goto no_memory; + goto error; graphics->type = VIR_DOMAIN_GRAPHICS_TYPE_VNC; /* For Xen >= 3.0.3, don't generate a fixed port mapping @@ -818,7 +809,7 @@ xenParseSxprGraphicsOld(virDomainDefPtr def, goto error; if (VIR_ALLOC_N(def->graphics, 1) < 0) - goto no_memory; + goto error; def->graphics[0] = graphics; def->ngraphics = 1; graphics = NULL; @@ -829,7 +820,7 @@ xenParseSxprGraphicsOld(virDomainDefPtr def, const char *xauth = sexpr_fmt_node(root, "domain/image/%s/xauthority", hvm ? "hvm" : "linux"); if (VIR_ALLOC(graphics) < 0) - goto no_memory; + goto error; graphics->type = VIR_DOMAIN_GRAPHICS_TYPE_SDL; if (VIR_STRDUP(graphics->data.sdl.display, display) < 0) @@ -838,7 +829,7 @@ xenParseSxprGraphicsOld(virDomainDefPtr def, goto error; if (VIR_ALLOC_N(def->graphics, 1) < 0) - goto no_memory; + goto error; def->graphics[0] = graphics; def->ngraphics = 1; graphics = NULL; @@ -846,8 +837,6 @@ xenParseSxprGraphicsOld(virDomainDefPtr def, return 0; -no_memory: - virReportOOMError(); error: virDomainGraphicsDefFree(graphics); return -1; @@ -889,7 +878,7 @@ xenParseSxprGraphicsNew(virDomainDefPtr def, } if (VIR_ALLOC(graphics) < 0) - goto no_memory; + goto error; if ((graphics->type = virDomainGraphicsTypeFromString(tmp)) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -940,7 +929,7 @@ xenParseSxprGraphicsNew(virDomainDefPtr def, } if (VIR_ALLOC_N(def->graphics, 1) < 0) - goto no_memory; + goto error; def->graphics[0] = graphics; def->ngraphics = 1; graphics = NULL; @@ -950,8 +939,6 @@ xenParseSxprGraphicsNew(virDomainDefPtr def, return 0; -no_memory: - virReportOOMError(); error: virDomainGraphicsDefFree(graphics); return -1; @@ -1067,7 +1054,7 @@ xenParseSxprPCI(virDomainDefPtr def, if (VIR_REALLOC_N(def->hostdevs, def->nhostdevs+1) < 0) { virDomainHostdevDefFree(dev); - goto no_memory; + goto error; } def->hostdevs[def->nhostdevs++] = dev; @@ -1075,9 +1062,6 @@ xenParseSxprPCI(virDomainDefPtr def, return 0; -no_memory: - virReportOOMError(); - error: virDomainHostdevDefFree(dev); return -1; @@ -1108,7 +1092,7 @@ xenParseSxpr(const struct sexpr *root, int hvm = 0, vmlocaltime; if (VIR_ALLOC(def) < 0) - goto no_memory; + goto error; tmp = sexpr_node(root, "domain/domid"); if (tmp == NULL && xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) { /* domid was mandatory */ @@ -1123,7 +1107,7 @@ xenParseSxpr(const struct sexpr *root, def->id = -1; if (sexpr_node_copy(root, "domain/name", &def->name) < 0) - goto no_memory; + goto error; if (def->name == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("domain information incomplete, missing name")); @@ -1140,13 +1124,13 @@ xenParseSxpr(const struct sexpr *root, goto error; if (sexpr_node_copy(root, "domain/description", &def->description) < 0) - goto no_memory; + goto error; hvm = sexpr_lookup(root, "domain/image/hvm") ? 1 : 0; if (!hvm) { if (sexpr_node_copy(root, "domain/bootloader", &def->os.bootloader) < 0) - goto no_memory; + goto error; if (!def->os.bootloader && sexpr_has(root, "domain/bootloader") && @@ -1156,7 +1140,7 @@ xenParseSxpr(const struct sexpr *root, if (def->os.bootloader && sexpr_node_copy(root, "domain/bootloader_args", &def->os.bootloaderArgs) < 0) - goto no_memory; + goto error; } if (VIR_STRDUP(def->os.type, hvm ? "hvm" : "linux") < 0) @@ -1263,10 +1247,8 @@ xenParseSxpr(const struct sexpr *root, virDomainTimerDefPtr timer; if (VIR_ALLOC_N(def->clock.timers, 1) < 0 || - VIR_ALLOC(timer) < 0) { - virReportOOMError(); + VIR_ALLOC(timer) < 0) goto error; - } timer->name = VIR_DOMAIN_TIMER_NAME_HPET; timer->present = sexpr_int(root, "domain/image/hvm/hpet"); @@ -1296,7 +1278,7 @@ xenParseSxpr(const struct sexpr *root, "domain/image/hvm/device_model" : "domain/image/linux/device_model", &def->emulator) < 0) - goto no_memory; + goto error; /* append block devices */ if (xenParseSxprDisks(def, root, hvm, xendConfigVersion) < 0) @@ -1326,7 +1308,7 @@ xenParseSxpr(const struct sexpr *root, if ((tmp != NULL) && (tmp[0] != 0)) { virDomainDiskDefPtr disk; if (VIR_ALLOC(disk) < 0) - goto no_memory; + goto error; if (VIR_STRDUP(disk->src, tmp) < 0) { virDomainDiskDefFree(disk); goto error; @@ -1346,7 +1328,7 @@ xenParseSxpr(const struct sexpr *root, if (VIR_REALLOC_N(def->disks, def->ndisks+1) < 0) { virDomainDiskDefFree(disk); - goto no_memory; + goto error; } def->disks[def->ndisks++] = disk; } @@ -1362,7 +1344,7 @@ xenParseSxpr(const struct sexpr *root, if ((tmp != NULL) && (tmp[0] != 0)) { virDomainDiskDefPtr disk; if (VIR_ALLOC(disk) < 0) - goto no_memory; + goto error; if (VIR_STRDUP(disk->src, tmp) < 0) { VIR_FREE(disk); goto error; @@ -1381,7 +1363,7 @@ xenParseSxpr(const struct sexpr *root, if (VIR_REALLOC_N(def->disks, def->ndisks+1) < 0) { virDomainDiskDefFree(disk); - goto no_memory; + goto error; } def->disks[def->ndisks++] = disk; } @@ -1415,7 +1397,7 @@ xenParseSxpr(const struct sexpr *root, goto error; if (VIR_REALLOC_N(def->serials, def->nserials+1) < 0) { virDomainChrDefFree(chr); - goto no_memory; + goto error; } chr->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL; chr->target.port = def->nserials + ports_skipped; @@ -1437,7 +1419,7 @@ xenParseSxpr(const struct sexpr *root, goto error; if (VIR_REALLOC_N(def->serials, def->nserials+1) < 0) { virDomainChrDefFree(chr); - goto no_memory; + goto error; } chr->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL; chr->target.port = 0; @@ -1453,7 +1435,7 @@ xenParseSxpr(const struct sexpr *root, goto error; if (VIR_REALLOC_N(def->parallels, def->nparallels+1) < 0) { virDomainChrDefFree(chr); - goto no_memory; + goto error; } chr->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL; chr->target.port = 0; @@ -1462,7 +1444,7 @@ xenParseSxpr(const struct sexpr *root, } else if (def->id != 0) { def->nconsoles = 1; if (VIR_ALLOC_N(def->consoles, 1) < 0) - goto no_memory; + goto error; /* Fake a paravirt console, since that's not in the sexpr */ if (!(def->consoles[0] = xenParseSxprChar("pty", tty))) goto error; @@ -1483,8 +1465,6 @@ xenParseSxpr(const struct sexpr *root, return def; -no_memory: - virReportOOMError(); error: VIR_FREE(tty); virDomainDefFree(def); diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index 9905f9d..f3e6e44 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -265,10 +265,8 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, char *script = NULL; char *listenAddr = NULL; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } def->virtType = VIR_DOMAIN_VIRT_XEN; def->id = -1; @@ -424,10 +422,8 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, virDomainTimerDefPtr timer; if (VIR_ALLOC_N(def->clock.timers, 1) < 0 || - VIR_ALLOC(timer) < 0) { - virReportOOMError(); + VIR_ALLOC(timer) < 0) goto cleanup; - } timer->name = VIR_DOMAIN_TIMER_NAME_HPET; timer->present = val; @@ -482,7 +478,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, head = list->str; if (VIR_ALLOC(disk) < 0) - goto no_memory; + goto cleanup; /* * Disks have 3 components, SOURCE,DEST-DEVICE,MODE @@ -500,7 +496,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, disk->src = NULL; /* No source file given, eg CDROM with no media */ } else { if (VIR_ALLOC_N(disk->src, (offset - head) + 1) < 0) - goto no_memory; + goto cleanup; if (virStrncpy(disk->src, head, offset - head, (offset - head) + 1) == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -519,7 +515,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, if (!(offset = strchr(head, ','))) goto skipdisk; if (VIR_ALLOC_N(disk->dst, (offset - head) + 1) < 0) - goto no_memory; + goto cleanup; if (virStrncpy(disk->dst, head, offset - head, (offset - head) + 1) == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -534,7 +530,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, /* The main type phy:, file:, tap: ... */ if ((tmp = strchr(disk->src, ':')) != NULL) { if (VIR_ALLOC_N(disk->driverName, (tmp - disk->src) + 1) < 0) - goto no_memory; + goto cleanup; if (virStrncpy(disk->driverName, disk->src, (tmp - disk->src), (tmp - disk->src) + 1) == NULL) { @@ -613,7 +609,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, /* Maintain list in sorted order according to target device name */ if (VIR_REALLOC_N(def->disks, def->ndisks+1) < 0) - goto no_memory; + goto cleanup; def->disks[def->ndisks++] = disk; disk = NULL; @@ -628,7 +624,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, goto cleanup; if (str) { if (VIR_ALLOC(disk) < 0) - goto no_memory; + goto cleanup; disk->type = VIR_DOMAIN_DISK_TYPE_FILE; disk->device = VIR_DOMAIN_DISK_DEVICE_CDROM; @@ -642,7 +638,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, disk->readonly = true; if (VIR_REALLOC_N(def->disks, def->ndisks+1) < 0) - goto no_memory; + goto cleanup; def->disks[def->ndisks++] = disk; disk = NULL; } @@ -739,7 +735,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, } if (VIR_ALLOC(net) < 0) - goto no_memory; + goto cleanup; if (mac[0]) { if (virMacAddrParse(mac, &net->mac) < 0) { @@ -772,7 +768,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, if (model[0] && VIR_STRDUP(net->model, model) < 0) - goto no_memory; + goto cleanup; if (!model[0] && type[0] && STREQ(type, "netfront") && VIR_STRDUP(net->model, "netfront") < 0) @@ -783,7 +779,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, goto cleanup; if (VIR_REALLOC_N(def->nets, def->nnets+1) < 0) - goto no_memory; + goto cleanup; def->nets[def->nnets++] = net; net = NULL; @@ -875,7 +871,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, if (VIR_REALLOC_N(def->hostdevs, def->nhostdevs+1) < 0) { virDomainHostdevDefFree(hostdev); - goto no_memory; + goto cleanup; } def->hostdevs[def->nhostdevs++] = hostdev; hostdev = NULL; @@ -893,14 +889,14 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, STREQ(str, "mouse"))) { virDomainInputDefPtr input; if (VIR_ALLOC(input) < 0) - goto no_memory; + goto cleanup; input->bus = VIR_DOMAIN_INPUT_BUS_USB; input->type = STREQ(str, "tablet") ? VIR_DOMAIN_INPUT_TYPE_TABLET : VIR_DOMAIN_INPUT_TYPE_MOUSE; if (VIR_ALLOC_N(def->inputs, 1) < 0) { virDomainInputDefFree(input); - goto no_memory; + goto cleanup; } def->inputs[0] = input; def->ninputs = 1; @@ -914,7 +910,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, if (val) { if (VIR_ALLOC(graphics) < 0) - goto no_memory; + goto cleanup; graphics->type = VIR_DOMAIN_GRAPHICS_TYPE_VNC; if (xenXMConfigGetBool(conf, "vncunused", &val, 1) < 0) goto cleanup; @@ -942,7 +938,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, goto cleanup; if (VIR_ALLOC_N(def->graphics, 1) < 0) - goto no_memory; + goto cleanup; def->graphics[0] = graphics; def->ngraphics = 1; graphics = NULL; @@ -951,14 +947,14 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, goto cleanup; if (val) { if (VIR_ALLOC(graphics) < 0) - goto no_memory; + goto cleanup; graphics->type = VIR_DOMAIN_GRAPHICS_TYPE_SDL; if (xenXMConfigCopyStringOpt(conf, "display", &graphics->data.sdl.display) < 0) goto cleanup; if (xenXMConfigCopyStringOpt(conf, "xauthority", &graphics->data.sdl.xauth) < 0) goto cleanup; if (VIR_ALLOC_N(def->graphics, 1) < 0) - goto no_memory; + goto cleanup; def->graphics[0] = graphics; def->ngraphics = 1; graphics = NULL; @@ -982,7 +978,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, } if (VIR_ALLOC(graphics) < 0) - goto no_memory; + goto cleanup; if (strstr(key, "type=sdl")) graphics->type = VIR_DOMAIN_GRAPHICS_TYPE_SDL; @@ -1034,7 +1030,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, key = nextkey; } if (VIR_ALLOC_N(def->graphics, 1) < 0) - goto no_memory; + goto cleanup; def->graphics[0] = graphics; def->ngraphics = 1; graphics = NULL; @@ -1053,7 +1049,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, if (chr) { if (VIR_ALLOC_N(def->parallels, 1) < 0) { virDomainChrDefFree(chr); - goto no_memory; + goto cleanup; } chr->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL; chr->target.port = 0; @@ -1085,7 +1081,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, goto cleanup; if (VIR_REALLOC_N(def->serials, def->nserials+1) < 0) - goto no_memory; + goto cleanup; chr->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL; chr->target.port = portnum; @@ -1105,7 +1101,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, if (chr) { if (VIR_ALLOC_N(def->serials, 1) < 0) { virDomainChrDefFree(chr); - goto no_memory; + goto cleanup; } chr->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL; chr->target.port = 0; @@ -1116,7 +1112,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, } else { def->nconsoles = 1; if (VIR_ALLOC_N(def->consoles, 1) < 0) - goto no_memory; + goto cleanup; if (!(def->consoles[0] = xenParseSxprChar("pty", NULL))) goto cleanup; def->consoles[0]->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE; @@ -1136,9 +1132,6 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, VIR_FREE(script); return def; -no_memory: - virReportOOMError(); - /* fallthrough */ cleanup: virDomainGraphicsDefFree(graphics); virDomainNetDefFree(net); @@ -1159,10 +1152,8 @@ int xenXMConfigSetInt(virConfPtr conf, const char *setting, long long l) { l, setting); return -1; } - if (VIR_ALLOC(value) < 0) { - virReportOOMError(); + if (VIR_ALLOC(value) < 0) return -1; - } value->type = VIR_CONF_LONG; value->next = NULL; @@ -1176,10 +1167,8 @@ static int xenXMConfigSetString(virConfPtr conf, const char *setting, const char *str) { virConfValuePtr value = NULL; - if (VIR_ALLOC(value) < 0) { - virReportOOMError(); + if (VIR_ALLOC(value) < 0) return -1; - } value->type = VIR_CONF_STRING; value->next = NULL; @@ -1253,10 +1242,8 @@ static int xenFormatXMDisk(virConfValuePtr list, goto cleanup; } - if (VIR_ALLOC(val) < 0) { - virReportOOMError(); + if (VIR_ALLOC(val) < 0) goto cleanup; - } val->type = VIR_CONF_STRING; val->str = virBufferContentAndReset(&buf); @@ -1284,10 +1271,8 @@ static int xenFormatXMSerial(virConfValuePtr list, if (serial) { ret = xenFormatSxprChr(serial, &buf); - if (ret < 0) { - virReportOOMError(); + if (ret < 0) goto cleanup; - } } else { virBufferAddLit(&buf, "none"); } @@ -1296,10 +1281,8 @@ static int xenFormatXMSerial(virConfValuePtr list, goto cleanup; } - if (VIR_ALLOC(val) < 0) { - virReportOOMError(); + if (VIR_ALLOC(val) < 0) goto cleanup; - } val->type = VIR_CONF_STRING; val->str = virBufferContentAndReset(&buf); @@ -1404,10 +1387,8 @@ static int xenFormatXMNet(virConnectPtr conn, goto cleanup; } - if (VIR_ALLOC(val) < 0) { - virReportOOMError(); + if (VIR_ALLOC(val) < 0) goto cleanup; - } val->type = VIR_CONF_STRING; val->str = virBufferContentAndReset(&buf); @@ -1445,10 +1426,8 @@ xenFormatXMPCI(virConfPtr conf, if (!hasPCI) return 0; - if (VIR_ALLOC(pciVal) < 0) { - virReportOOMError(); + if (VIR_ALLOC(pciVal) < 0) return -1; - } pciVal->type = VIR_CONF_LIST; pciVal->list = NULL; @@ -1463,14 +1442,11 @@ xenFormatXMPCI(virConfPtr conf, def->hostdevs[i]->source.subsys.u.pci.addr.domain, def->hostdevs[i]->source.subsys.u.pci.addr.bus, def->hostdevs[i]->source.subsys.u.pci.addr.slot, - def->hostdevs[i]->source.subsys.u.pci.addr.function) < 0) { - virReportOOMError(); + def->hostdevs[i]->source.subsys.u.pci.addr.function) < 0) goto error; - } if (VIR_ALLOC(val) < 0) { VIR_FREE(buf); - virReportOOMError(); goto error; } val->type = VIR_CONF_STRING; @@ -1521,27 +1497,27 @@ virConfPtr xenFormatXM(virConnectPtr conn, if (xenXMConfigSetString(conf, "name", def->name) < 0) - goto no_memory; + goto cleanup; virUUIDFormat(def->uuid, uuid); if (xenXMConfigSetString(conf, "uuid", uuid) < 0) - goto no_memory; + goto cleanup; if (xenXMConfigSetInt(conf, "maxmem", VIR_DIV_UP(def->mem.max_balloon, 1024)) < 0) - goto no_memory; + goto cleanup; if (xenXMConfigSetInt(conf, "memory", VIR_DIV_UP(def->mem.cur_balloon, 1024)) < 0) - goto no_memory; + goto cleanup; if (xenXMConfigSetInt(conf, "vcpus", def->maxvcpus) < 0) - goto no_memory; + goto cleanup; /* Computing the vcpu_avail bitmask works because MAX_VIRT_CPUS is either 32, or 64 on a platform where long is big enough. */ if (def->vcpus < def->maxvcpus && xenXMConfigSetInt(conf, "vcpu_avail", (1UL << def->vcpus) - 1) < 0) - goto no_memory; + goto cleanup; if ((def->cpumask != NULL) && ((cpus = virBitmapFormat(def->cpumask)) == NULL)) { @@ -1550,7 +1526,7 @@ virConfPtr xenFormatXM(virConnectPtr conn, if (cpus && xenXMConfigSetString(conf, "cpus", cpus) < 0) - goto no_memory; + goto cleanup; VIR_FREE(cpus); hvm = STREQ(def->os.type, "hvm") ? 1 : 0; @@ -1558,11 +1534,11 @@ virConfPtr xenFormatXM(virConnectPtr conn, if (hvm) { char boot[VIR_DOMAIN_BOOT_LAST+1]; if (xenXMConfigSetString(conf, "builder", "hvm") < 0) - goto no_memory; + goto cleanup; if (def->os.loader && xenXMConfigSetString(conf, "kernel", def->os.loader) < 0) - goto no_memory; + goto cleanup; for (i = 0; i < def->os.nBootDevs; i++) { switch (def->os.bootDevs[i]) { @@ -1589,33 +1565,33 @@ virConfPtr xenFormatXM(virConnectPtr conn, } if (xenXMConfigSetString(conf, "boot", boot) < 0) - goto no_memory; + goto cleanup; if (xenXMConfigSetInt(conf, "pae", (def->features & (1 << VIR_DOMAIN_FEATURE_PAE)) ? 1 : 0) < 0) - goto no_memory; + goto cleanup; if (xenXMConfigSetInt(conf, "acpi", (def->features & (1 << VIR_DOMAIN_FEATURE_ACPI)) ? 1 : 0) < 0) - goto no_memory; + goto cleanup; if (xenXMConfigSetInt(conf, "apic", (def->features & (1 << VIR_DOMAIN_FEATURE_APIC)) ? 1 : 0) < 0) - goto no_memory; + goto cleanup; if (xendConfigVersion >= XEND_CONFIG_VERSION_3_0_4) { if (xenXMConfigSetInt(conf, "hap", (def->features & (1 << VIR_DOMAIN_FEATURE_HAP)) ? 1 : 0) < 0) - goto no_memory; + goto cleanup; if (xenXMConfigSetInt(conf, "viridian", (def->features & (1 << VIR_DOMAIN_FEATURE_VIRIDIAN)) ? 1 : 0) < 0) - goto no_memory; + goto cleanup; } for (i = 0; i < def->clock.ntimers; i++) { @@ -1633,7 +1609,7 @@ virConfPtr xenFormatXM(virConnectPtr conn, def->disks[i]->src) { if (xenXMConfigSetString(conf, "cdrom", def->disks[i]->src) < 0) - goto no_memory; + goto cleanup; break; } } @@ -1643,19 +1619,19 @@ virConfPtr xenFormatXM(virConnectPtr conn, } else { if (def->os.bootloader && xenXMConfigSetString(conf, "bootloader", def->os.bootloader) < 0) - goto no_memory; + goto cleanup; if (def->os.bootloaderArgs && xenXMConfigSetString(conf, "bootargs", def->os.bootloaderArgs) < 0) - goto no_memory; + goto cleanup; if (def->os.kernel && xenXMConfigSetString(conf, "kernel", def->os.kernel) < 0) - goto no_memory; + goto cleanup; if (def->os.initrd && xenXMConfigSetString(conf, "ramdisk", def->os.initrd) < 0) - goto no_memory; + goto cleanup; if (def->os.cmdline && xenXMConfigSetString(conf, "extra", def->os.cmdline) < 0) - goto no_memory; + goto cleanup; } /* !hvm */ @@ -1708,7 +1684,7 @@ virConfPtr xenFormatXM(virConnectPtr conn, goto cleanup; } if (xenXMConfigSetInt(conf, "rtc_timeoffset", rtc_timeoffset) < 0) - goto no_memory; + goto cleanup; } else { /* >=3.1 PV: UTC and LOCALTIME */ switch (def->clock.offset) { @@ -1727,7 +1703,7 @@ virConfPtr xenFormatXM(virConnectPtr conn, } /* !hvm */ } if (xenXMConfigSetInt(conf, "localtime", vmlocaltime) < 0) - goto no_memory; + goto cleanup; if (!(lifecycle = virDomainLifecycleTypeToString(def->onPoweroff))) { @@ -1736,7 +1712,7 @@ virConfPtr xenFormatXM(virConnectPtr conn, goto cleanup; } if (xenXMConfigSetString(conf, "on_poweroff", lifecycle) < 0) - goto no_memory; + goto cleanup; if (!(lifecycle = virDomainLifecycleTypeToString(def->onReboot))) { @@ -1745,7 +1721,7 @@ virConfPtr xenFormatXM(virConnectPtr conn, goto cleanup; } if (xenXMConfigSetString(conf, "on_reboot", lifecycle) < 0) - goto no_memory; + goto cleanup; if (!(lifecycle = virDomainLifecycleCrashTypeToString(def->onCrash))) { @@ -1754,23 +1730,23 @@ virConfPtr xenFormatXM(virConnectPtr conn, goto cleanup; } if (xenXMConfigSetString(conf, "on_crash", lifecycle) < 0) - goto no_memory; + goto cleanup; if (hvm) { if (def->emulator && xenXMConfigSetString(conf, "device_model", def->emulator) < 0) - goto no_memory; + goto cleanup; for (i = 0; i < def->ninputs; i++) { if (def->inputs[i]->bus == VIR_DOMAIN_INPUT_BUS_USB) { if (xenXMConfigSetInt(conf, "usb", 1) < 0) - goto no_memory; + goto cleanup; if (xenXMConfigSetString(conf, "usbdevice", def->inputs[i]->type == VIR_DOMAIN_INPUT_TYPE_MOUSE ? "mouse" : "tablet") < 0) - goto no_memory; + goto cleanup; break; } } @@ -1780,43 +1756,43 @@ virConfPtr xenFormatXM(virConnectPtr conn, if (hvm || (xendConfigVersion < XEND_CONFIG_MIN_VERS_PVFB_NEWCONF)) { if (def->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_SDL) { if (xenXMConfigSetInt(conf, "sdl", 1) < 0) - goto no_memory; + goto cleanup; if (xenXMConfigSetInt(conf, "vnc", 0) < 0) - goto no_memory; + goto cleanup; if (def->graphics[0]->data.sdl.display && xenXMConfigSetString(conf, "display", def->graphics[0]->data.sdl.display) < 0) - goto no_memory; + goto cleanup; if (def->graphics[0]->data.sdl.xauth && xenXMConfigSetString(conf, "xauthority", def->graphics[0]->data.sdl.xauth) < 0) - goto no_memory; + goto cleanup; } else { const char *listenAddr; if (xenXMConfigSetInt(conf, "sdl", 0) < 0) - goto no_memory; + goto cleanup; if (xenXMConfigSetInt(conf, "vnc", 1) < 0) - goto no_memory; + goto cleanup; if (xenXMConfigSetInt(conf, "vncunused", def->graphics[0]->data.vnc.autoport ? 1 : 0) < 0) - goto no_memory; + goto cleanup; if (!def->graphics[0]->data.vnc.autoport && xenXMConfigSetInt(conf, "vncdisplay", def->graphics[0]->data.vnc.port - 5900) < 0) - goto no_memory; + goto cleanup; listenAddr = virDomainGraphicsListenGetAddress(def->graphics[0], 0); if (listenAddr && xenXMConfigSetString(conf, "vnclisten", listenAddr) < 0) - goto no_memory; + goto cleanup; if (def->graphics[0]->data.vnc.auth.passwd && xenXMConfigSetString(conf, "vncpasswd", def->graphics[0]->data.vnc.auth.passwd) < 0) - goto no_memory; + goto cleanup; if (def->graphics[0]->data.vnc.keymap && xenXMConfigSetString(conf, "keymap", def->graphics[0]->data.vnc.keymap) < 0) - goto no_memory; + goto cleanup; } } else { virConfValuePtr vfb, disp; @@ -1851,20 +1827,21 @@ virConfPtr xenFormatXM(virConnectPtr conn, } if (virBufferError(&buf)) { virBufferFreeAndReset(&buf); - goto no_memory; + virReportOOMError(); + goto cleanup; } vfbstr = virBufferContentAndReset(&buf); if (VIR_ALLOC(vfb) < 0) { VIR_FREE(vfbstr); - goto no_memory; + goto cleanup; } if (VIR_ALLOC(disp) < 0) { VIR_FREE(vfb); VIR_FREE(vfbstr); - goto no_memory; + goto cleanup; } vfb->type = VIR_CONF_LIST; @@ -1873,13 +1850,13 @@ virConfPtr xenFormatXM(virConnectPtr conn, disp->str = vfbstr; if (virConfSetValue(conf, "vfb", vfb) < 0) - goto no_memory; + goto cleanup; } } /* analyze of the devices */ if (VIR_ALLOC(diskVal) < 0) - goto no_memory; + goto cleanup; diskVal->type = VIR_CONF_LIST; diskVal->list = NULL; @@ -1901,12 +1878,12 @@ virConfPtr xenFormatXM(virConnectPtr conn, int ret = virConfSetValue(conf, "disk", diskVal); diskVal = NULL; if (ret < 0) - goto no_memory; + goto cleanup; } VIR_FREE(diskVal); if (VIR_ALLOC(netVal) < 0) - goto no_memory; + goto cleanup; netVal->type = VIR_CONF_LIST; netVal->list = NULL; @@ -1919,7 +1896,7 @@ virConfPtr xenFormatXM(virConnectPtr conn, int ret = virConfSetValue(conf, "vif", netVal); netVal = NULL; if (ret < 0) - goto no_memory; + goto cleanup; } VIR_FREE(netVal); @@ -1938,10 +1915,10 @@ virConfPtr xenFormatXM(virConnectPtr conn, ret = xenXMConfigSetString(conf, "parallel", str); VIR_FREE(str); if (ret < 0) - goto no_memory; + goto cleanup; } else { if (xenXMConfigSetString(conf, "parallel", "none") < 0) - goto no_memory; + goto cleanup; } if (def->nserials) { @@ -1956,14 +1933,14 @@ virConfPtr xenFormatXM(virConnectPtr conn, ret = xenXMConfigSetString(conf, "serial", str); VIR_FREE(str); if (ret < 0) - goto no_memory; + goto cleanup; } else { int j = 0; int maxport = -1; virConfValuePtr serialVal = NULL; if (VIR_ALLOC(serialVal) < 0) - goto no_memory; + goto cleanup; serialVal->type = VIR_CONF_LIST; serialVal->list = NULL; @@ -1987,13 +1964,13 @@ virConfPtr xenFormatXM(virConnectPtr conn, int ret = virConfSetValue(conf, "serial", serialVal); serialVal = NULL; if (ret < 0) - goto no_memory; + goto cleanup; } VIR_FREE(serialVal); } } else { if (xenXMConfigSetString(conf, "serial", "none") < 0) - goto no_memory; + goto cleanup; } @@ -2007,15 +1984,12 @@ virConfPtr xenFormatXM(virConnectPtr conn, VIR_FREE(str); if (ret < 0) - goto no_memory; + goto cleanup; } } return conf; -no_memory: - virReportOOMError(); - cleanup: virConfFreeValue(diskVal); virConfFreeValue(netVal); -- 1.8.1.5

On 07/04/2013 02:06 PM, Michal Privoznik wrote:
--- src/xenxs/xen_sxpr.c | 112 ++++++++++++---------------- src/xenxs/xen_xm.c | 204 ++++++++++++++++++++++----------------------------- 2 files changed, 135 insertions(+), 181 deletions(-)
ACK Jan

--- src/fdstream.c | 4 +--- src/libvirt.c | 21 ++++++--------------- src/nodeinfo.c | 58 ++++++++++++++-------------------------------------------- 3 files changed, 21 insertions(+), 62 deletions(-) diff --git a/src/fdstream.c b/src/fdstream.c index d5e5aaf..30f1729 100644 --- a/src/fdstream.c +++ b/src/fdstream.c @@ -488,10 +488,8 @@ static int virFDStreamOpenInternal(virStreamPtr st, virSetNonBlock(fd) < 0) return -1; - if (VIR_ALLOC(fdst) < 0) { - virReportOOMError(); + if (VIR_ALLOC(fdst) < 0) return -1; - } fdst->fd = fd; fdst->cmd = cmd; diff --git a/src/libvirt.c b/src/libvirt.c index bc1694a..619e691 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -275,7 +275,7 @@ static int virTLSMutexInit(void **priv) { virMutexPtr lock = NULL; - if (VIR_ALLOC(lock) < 0) + if (VIR_ALLOC_QUIET(lock) < 0) return ENOMEM; if (virMutexInit(lock) < 0) { @@ -947,26 +947,21 @@ virConnectGetConfigFilePath(void) if (geteuid() == 0) { if (virAsprintf(&path, "%s/libvirt/libvirt.conf", SYSCONFDIR) < 0) - goto no_memory; + return NULL; } else { char *userdir = virGetUserConfigDirectory(); if (!userdir) - goto error; + return NULL; if (virAsprintf(&path, "%s/libvirt.conf", userdir) < 0) { VIR_FREE(userdir); - goto no_memory; + return NULL; } VIR_FREE(userdir); } return path; - -no_memory: - virReportOOMError(); -error: - return NULL; } static int @@ -16974,10 +16969,8 @@ int virStreamSendAll(virStreamPtr stream, goto cleanup; } - if (VIR_ALLOC_N(bytes, want) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(bytes, want) < 0) goto cleanup; - } for (;;) { int got, offset = 0; @@ -17074,10 +17067,8 @@ int virStreamRecvAll(virStreamPtr stream, } - if (VIR_ALLOC_N(bytes, want) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(bytes, want) < 0) goto cleanup; - } for (;;) { int got, offset = 0; diff --git a/src/nodeinfo.c b/src/nodeinfo.c index a50f892..0e94f30 100644 --- a/src/nodeinfo.c +++ b/src/nodeinfo.c @@ -118,10 +118,8 @@ virNodeGetCpuValue(const char *dir, unsigned int cpu, const char *file, char value_str[INT_BUFSIZE_BOUND(value)]; char *tmp; - if (virAsprintf(&path, "%s/cpu%u/%s", dir, cpu, file) < 0) { - virReportOOMError(); + if (virAsprintf(&path, "%s/cpu%u/%s", dir, cpu, file) < 0) return -1; - } pathfp = fopen(path, "r"); if (pathfp == NULL) { @@ -160,10 +158,8 @@ virNodeCountThreadSiblings(const char *dir, unsigned int cpu) int i; if (virAsprintf(&path, "%s/cpu%u/topology/thread_siblings", - dir, cpu) < 0) { - virReportOOMError(); + dir, cpu) < 0) return 0; - } pathfp = fopen(path, "r"); if (pathfp == NULL) { @@ -297,10 +293,8 @@ virNodeParseNode(const char *node, sock_max++; /* allocate cpu maps for each socket */ - if (VIR_ALLOC_N(core_maps, sock_max) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(core_maps, sock_max) < 0) goto cleanup; - } for (i = 0; i < sock_max; i++) CPU_ZERO(&core_maps[i]); @@ -481,10 +475,8 @@ int linuxNodeInfoCPUPopulate(FILE *cpuinfo, /* OK, we've parsed clock speed out of /proc/cpuinfo. Get the * core, node, socket, thread and topology information from /sys */ - if (virAsprintf(&sysfs_nodedir, "%s/node", sysfs_dir) < 0) { - virReportOOMError(); + if (virAsprintf(&sysfs_nodedir, "%s/node", sysfs_dir) < 0) goto cleanup; - } if (!(nodedir = opendir(sysfs_nodedir))) { /* the host isn't probably running a NUMA architecture */ @@ -499,10 +491,8 @@ int linuxNodeInfoCPUPopulate(FILE *cpuinfo, nodeinfo->nodes++; if (virAsprintf(&sysfs_cpudir, "%s/node/%s", - sysfs_dir, nodedirent->d_name) < 0) { - virReportOOMError(); + sysfs_dir, nodedirent->d_name) < 0) goto cleanup; - } if ((cpus = virNodeParseNode(sysfs_cpudir, &socks, &cores, &threads, &offline)) < 0) @@ -535,10 +525,8 @@ int linuxNodeInfoCPUPopulate(FILE *cpuinfo, fallback: VIR_FREE(sysfs_cpudir); - if (virAsprintf(&sysfs_cpudir, "%s/cpu", sysfs_dir) < 0) { - virReportOOMError(); + if (virAsprintf(&sysfs_cpudir, "%s/cpu", sysfs_dir) < 0) goto cleanup; - } if ((cpus = virNodeParseNode(sysfs_cpudir, &socks, &cores, &threads, &offline)) < 0) @@ -848,10 +836,8 @@ linuxParseCPUmap(int max_cpuid, const char *path) virBitmapPtr map = NULL; char *str = NULL; - if (virFileReadAll(path, 5 * VIR_DOMAIN_CPUMASK_LEN, &str) < 0) { - virReportOOMError(); + if (virFileReadAll(path, 5 * VIR_DOMAIN_CPUMASK_LEN, &str) < 0) goto error; - } if (virBitmapParse(str, 0, &map, max_cpuid) < 0) goto error; @@ -1005,10 +991,8 @@ int nodeGetMemoryStats(int cellNum ATTRIBUTE_UNUSED, # endif if (virAsprintf(&meminfo_path, "%s/node/node%d/meminfo", - SYSFS_SYSTEM_PATH, cellNum) < 0) { - virReportOOMError(); + SYSFS_SYSTEM_PATH, cellNum) < 0) return -1; - } } meminfo = fopen(meminfo_path, "r"); @@ -1050,10 +1034,8 @@ nodeGetCPUCount(void) i++; VIR_FREE(cpupath); if (virAsprintf(&cpupath, "%s/cpu/cpu%d", - SYSFS_SYSTEM_PATH, i) < 0) { - virReportOOMError(); + SYSFS_SYSTEM_PATH, i) < 0) return -1; - } } while (virFileExists(cpupath)); } else { /* no cpu/cpu0: we give up */ @@ -1090,10 +1072,8 @@ nodeGetCPUBitmap(int *max_id ATTRIBUTE_UNUSED) int i; cpumap = virBitmapNew(present); - if (!cpumap) { - virReportOOMError(); + if (!cpumap) return NULL; - } for (i = 0; i < present; i++) { int online = virNodeGetCpuValue(SYSFS_SYSTEM_PATH, i, "online", 1); if (online < 0) { @@ -1128,13 +1108,11 @@ nodeSetMemoryParameterValue(virTypedParameterPtr param) field++; if (virAsprintf(&path, "%s/%s", SYSFS_MEMORY_SHARED_PATH, field) < 0) { - virReportOOMError(); ret = -2; goto cleanup; } if (virAsprintf(&strval, "%u", param->value.ui) == -1) { - virReportOOMError(); ret = -2; goto cleanup; } @@ -1165,10 +1143,8 @@ nodeMemoryParametersIsAllSupported(virTypedParameterPtr params, sa_assert(field); field++; if (virAsprintf(&path, "%s/%s", - SYSFS_MEMORY_SHARED_PATH, field) < 0) { - virReportOOMError(); + SYSFS_MEMORY_SHARED_PATH, field) < 0) return false; - } if (!virFileExists(path)) { virReportError(VIR_ERR_OPERATION_INVALID, @@ -1238,10 +1214,8 @@ nodeGetMemoryParameterValue(const char *field, int rc = -1; if (virAsprintf(&path, "%s/%s", - SYSFS_MEMORY_SHARED_PATH, field) < 0) { - virReportOOMError(); + SYSFS_MEMORY_SHARED_PATH, field) < 0) goto cleanup; - } if (!virFileExists(path)) { ret = -2; @@ -1472,10 +1446,8 @@ nodeCapsInitNUMAFake(virCapsPtr caps ATTRIBUTE_UNUSED) ncpus = VIR_NODEINFO_MAXCPUS(nodeinfo); - if (VIR_ALLOC_N(cpus, ncpus) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(cpus, ncpus) < 0) return -1; - } id = 0; for (s = 0; s < nodeinfo.sockets; s++) { @@ -1569,10 +1541,8 @@ virNodeGetSiblingsList(const char *dir, int cpu_id) virBitmapPtr ret = NULL; if (virAsprintf(&path, "%s/cpu%u/topology/thread_siblings_list", - dir, cpu_id) < 0) { - virReportOOMError(); + dir, cpu_id) < 0) goto cleanup; - } if (virFileReadAll(path, SYSFS_THREAD_SIBLINGS_LIST_LENGTH_MAX, &buf) < 0) goto cleanup; -- 1.8.1.5

On 07/04/2013 02:06 PM, Michal Privoznik wrote:
--- src/fdstream.c | 4 +--- src/libvirt.c | 21 ++++++--------------- src/nodeinfo.c | 58 ++++++++++++++-------------------------------------------- 3 files changed, 21 insertions(+), 62 deletions(-)
ACK Jan

--- tests/commandtest.c | 8 ++------ tests/libvirtdconftest.c | 4 +--- tests/qemumonitortestutils.c | 17 +++++------------ tests/securityselinuxlabeltest.c | 21 +++++---------------- tests/securityselinuxtest.c | 8 +++----- tests/virnetmessagetest.c | 20 +++++--------------- tests/virstoragetest.c | 5 +---- 7 files changed, 22 insertions(+), 61 deletions(-) diff --git a/tests/commandtest.c b/tests/commandtest.c index ec69dbd..62f0277 100644 --- a/tests/commandtest.c +++ b/tests/commandtest.c @@ -820,10 +820,8 @@ static int test20(const void *unused ATTRIBUTE_UNUSED) sigaction(SIGPIPE, &sig_action, NULL); - if (virAsprintf(&buf, "1\n%100000d\n", 2) < 0) { - virReportOOMError(); + if (virAsprintf(&buf, "1\n%100000d\n", 2) < 0) goto cleanup; - } virCommandSetInputBuffer(cmd, buf); if (virCommandRun(cmd, NULL) < 0) { @@ -996,10 +994,8 @@ mymain(void) return EXIT_FAILURE; virEventRegisterDefaultImpl(); - if (VIR_ALLOC(test) < 0) { - virReportOOMError(); + if (VIR_ALLOC(test) < 0) goto cleanup; - } if (virMutexInit(&test->lock) < 0) { printf("Unable to init mutex: %d\n", errno); diff --git a/tests/libvirtdconftest.c b/tests/libvirtdconftest.c index d45c31a..ba61a0f 100644 --- a/tests/libvirtdconftest.c +++ b/tests/libvirtdconftest.c @@ -78,10 +78,8 @@ munge_param(const char *datain, strlen(replace) + strlen(eol) + 1; - if (VIR_ALLOC_N(dataout, dataoutlen) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(dataout, dataoutlen) < 0) return NULL; - } memcpy(dataout, datain, (eq - datain) + 1); memcpy(dataout + (eq - datain) + 1, replace, strlen(replace)); diff --git a/tests/qemumonitortestutils.c b/tests/qemumonitortestutils.c index 1a4bb88..56368a2 100644 --- a/tests/qemumonitortestutils.c +++ b/tests/qemumonitortestutils.c @@ -87,10 +87,8 @@ static int qemuMonitorTestAddReponse(qemuMonitorTestPtr test, if (have < want) { size_t need = want - have; - if (VIR_EXPAND_N(test->outgoing, test->outgoingCapacity, need) < 0) { - virReportOOMError(); + if (VIR_EXPAND_N(test->outgoing, test->outgoingCapacity, need) < 0) return -1; - } } want -= 2; @@ -403,7 +401,7 @@ qemuMonitorTestAddItem(qemuMonitorTestPtr test, qemuMonitorTestItemPtr item; if (VIR_ALLOC(item) < 0) - goto no_memory; + goto error; if (VIR_STRDUP(item->command_name, command_name) < 0 || VIR_STRDUP(item->response, response) < 0) @@ -412,7 +410,7 @@ qemuMonitorTestAddItem(qemuMonitorTestPtr test, virMutexLock(&test->lock); if (VIR_EXPAND_N(test->items, test->nitems, 1) < 0) { virMutexUnlock(&test->lock); - goto no_memory; + goto error; } test->items[test->nitems - 1] = item; @@ -420,8 +418,6 @@ qemuMonitorTestAddItem(qemuMonitorTestPtr test, return 0; -no_memory: - virReportOOMError(); error: qemuMonitorTestItemFree(item); return -1; @@ -457,7 +453,7 @@ qemuMonitorTestPtr qemuMonitorTestNew(bool json, virDomainXMLOptionPtr xmlopt) char *tmpdir_template = NULL; if (VIR_ALLOC(test) < 0) - goto no_memory; + goto error; if (virMutexInit(&test->lock) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -478,7 +474,7 @@ qemuMonitorTestPtr qemuMonitorTestNew(bool json, virDomainXMLOptionPtr xmlopt) tmpdir_template = NULL; if (virAsprintf(&path, "%s/qemumonitorjsontest.sock", test->tmpdir) < 0) - goto no_memory; + goto error; test->json = json; if (!(test->vm = virDomainObjNew(xmlopt))) @@ -538,9 +534,6 @@ cleanup: VIR_FREE(path); return test; -no_memory: - virReportOOMError(); - error: VIR_FREE(tmpdir_template); qemuMonitorTestFree(test); diff --git a/tests/securityselinuxlabeltest.c b/tests/securityselinuxlabeltest.c index 5ae4f57..8a492ba 100644 --- a/tests/securityselinuxlabeltest.c +++ b/tests/securityselinuxlabeltest.c @@ -61,10 +61,8 @@ testSELinuxMungePath(char **path) char *tmp; if (virAsprintf(&tmp, "%s/securityselinuxlabeldata%s", - abs_builddir, *path) < 0) { - virReportOOMError(); + abs_builddir, *path) < 0) return -1; - } VIR_FREE(*path); *path = tmp; @@ -84,10 +82,8 @@ testSELinuxLoadFileList(const char *testname, *nfiles = 0; if (virAsprintf(&path, "%s/securityselinuxlabeldata/%s.txt", - abs_srcdir, testname) < 0) { - virReportOOMError(); + abs_srcdir, testname) < 0) goto cleanup; - } if (!(fp = fopen(path, "r"))) { goto cleanup; @@ -96,10 +92,8 @@ testSELinuxLoadFileList(const char *testname, while (!feof(fp)) { char *line; char *file, *context; - if (VIR_ALLOC_N(line, 1024) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(line, 1024) < 0) goto cleanup; - } if (!fgets(line, 1024, fp)) { if (!feof(fp)) goto cleanup; @@ -112,7 +106,6 @@ testSELinuxLoadFileList(const char *testname, if (virAsprintf(&file, "%s/securityselinuxlabeldata%s", abs_builddir, line) < 0) { VIR_FREE(line); - virReportOOMError(); goto cleanup; } if (*tmp != '\0' && *tmp != '\n') { @@ -128,10 +121,8 @@ testSELinuxLoadFileList(const char *testname, context = NULL; } - if (VIR_EXPAND_N(*files, *nfiles, 1) < 0) { - virReportOOMError(); + if (VIR_EXPAND_N(*files, *nfiles, 1) < 0) goto cleanup; - } (*files)[(*nfiles)-1].file = file; (*files)[(*nfiles)-1].context = context; @@ -155,10 +146,8 @@ testSELinuxLoadDef(const char *testname) size_t i; if (virAsprintf(&xmlfile, "%s/securityselinuxlabeldata/%s.xml", - abs_srcdir, testname) < 0) { - virReportOOMError(); + abs_srcdir, testname) < 0) goto cleanup; - } if (virFileReadAll(xmlfile, 1024*1024, &xmlstr) < 0) { goto cleanup; diff --git a/tests/securityselinuxtest.c b/tests/securityselinuxtest.c index 8d85c68..e2806c1 100644 --- a/tests/securityselinuxtest.c +++ b/tests/securityselinuxtest.c @@ -69,13 +69,13 @@ testBuildDomainDef(bool dynamic, virSecurityLabelDefPtr secdef; if (VIR_ALLOC(def) < 0) - goto no_memory; + goto error; if (VIR_ALLOC_N(def->seclabels, 1) < 0) - goto no_memory; + goto error; if (VIR_ALLOC(secdef) < 0) - goto no_memory; + goto error; def->virtType = VIR_DOMAIN_VIRT_KVM; def->seclabels[0] = secdef; @@ -91,8 +91,6 @@ testBuildDomainDef(bool dynamic, return def; -no_memory: - virReportOOMError(); error: virDomainDefFree(def); return NULL; diff --git a/tests/virnetmessagetest.c b/tests/virnetmessagetest.c index 062c3ff..1aa4c25 100644 --- a/tests/virnetmessagetest.c +++ b/tests/virnetmessagetest.c @@ -49,10 +49,8 @@ static int testMessageHeaderEncode(const void *args ATTRIBUTE_UNUSED) unsigned long msg_buf_size = VIR_NET_MESSAGE_INITIAL + VIR_NET_MESSAGE_LEN_MAX; int ret = -1; - if (!msg) { - virReportOOMError(); + if (!msg) return -1; - } msg->header.prog = 0x11223344; msg->header.vers = 0x01; @@ -101,16 +99,12 @@ static int testMessageHeaderDecode(const void *args ATTRIBUTE_UNUSED) }; int ret = -1; - if (!msg) { - virReportOOMError(); + if (!msg) return -1; - } msg->bufferLength = 4; - if (VIR_ALLOC_N(msg->buffer, msg->bufferLength) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(msg->buffer, msg->bufferLength) < 0) goto cleanup; - } memcpy(msg->buffer, input_buf, msg->bufferLength); msg->header.prog = 0x11223344; @@ -225,10 +219,8 @@ static int testMessagePayloadEncode(const void *args ATTRIBUTE_UNUSED) 0x00, 0x00, 0x00, 0x00, /* Error network pointer */ }; - if (!msg) { - virReportOOMError(); + if (!msg) return -1; - } memset(&err, 0, sizeof(err)); @@ -336,10 +328,8 @@ static int testMessagePayloadDecode(const void *args ATTRIBUTE_UNUSED) int ret = -1; msg->bufferLength = 4; - if (VIR_ALLOC_N(msg->buffer, msg->bufferLength) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(msg->buffer, msg->bufferLength) < 0) goto cleanup; - } memcpy(msg->buffer, input_buffer, msg->bufferLength); memset(&err, 0, sizeof(err)); diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c index fef4b37..61d36f7 100644 --- a/tests/virstoragetest.c +++ b/tests/virstoragetest.c @@ -98,10 +98,8 @@ testPrepImages(void) virAsprintf(&absqcow2, "%s/qcow2", datadir) < 0 || virAsprintf(&abswrap, "%s/wrap", datadir) < 0 || virAsprintf(&absqed, "%s/qed", datadir) < 0 || - virAsprintf(&abslink2, "%s/sub/link2", datadir) < 0) { - virReportOOMError(); + virAsprintf(&abslink2, "%s/sub/link2", datadir) < 0) goto cleanup; - } if (virFileMakePath(datadir "/sub") < 0) { fprintf(stderr, "unable to create directory %s\n", datadir "/sub"); @@ -271,7 +269,6 @@ testStorageChain(const void *args) NULLSTR(elt->directory), elt->backingStoreFormat, elt->backingStoreIsFile, elt->capacity, elt->encrypted) < 0) { - virReportOOMError(); VIR_FREE(expect); VIR_FREE(actual); goto cleanup; -- 1.8.1.5

On 07/04/2013 02:06 PM, Michal Privoznik wrote:
--- tests/commandtest.c | 8 ++------ tests/libvirtdconftest.c | 4 +--- tests/qemumonitortestutils.c | 17 +++++------------ tests/securityselinuxlabeltest.c | 21 +++++---------------- tests/securityselinuxtest.c | 8 +++----- tests/virnetmessagetest.c | 20 +++++--------------- tests/virstoragetest.c | 5 +---- 7 files changed, 22 insertions(+), 61 deletions(-)
tests/commandhelper.c:80: if (VIR_ALLOC_N(newenv, n) < 0) tests/commandhelper.c-81- return EXIT_FAILURE; tests/testutils.c:106: if (virVasprintf(&str, msg, vargs) == 0) { tests/testutils.c-107- fprintf(stderr, "%s", str); tests/testutils.c-108- VIR_FREE(str); tests/testutils.c-109- } tests/virhashtest.c:21: if (virAsprintf(&str, __VA_ARGS__) == 0) { \ tests/virhashtest.c-22- fprintf(stderr, "%s", str); \ tests/virhashtest.c-23- VIR_FREE(str); \ tests/virhashtest.c-24- } These don't need to log an error (and this list isn't exhaustive). I'm looking forward to v2. Jan

--- tools/console.c | 6 +----- tools/virsh-domain-monitor.c | 4 +--- tools/virsh-domain.c | 28 ++++++++-------------------- tools/virsh.c | 1 - 4 files changed, 10 insertions(+), 29 deletions(-) diff --git a/tools/console.c b/tools/console.c index 9abfb58..6c24fcf 100644 --- a/tools/console.c +++ b/tools/console.c @@ -128,7 +128,6 @@ virConsoleEventOnStream(virStreamPtr st, if (avail < 1024) { if (VIR_REALLOC_N(con->streamToTerminal.data, con->streamToTerminal.length + 1024) < 0) { - virReportOOMError(); virConsoleShutdown(con); return; } @@ -204,7 +203,6 @@ virConsoleEventOnStdin(int watch ATTRIBUTE_UNUSED, if (avail < 1024) { if (VIR_REALLOC_N(con->terminalToStream.data, con->terminalToStream.length + 1024) < 0) { - virReportOOMError(); virConsoleShutdown(con); return; } @@ -357,10 +355,8 @@ int vshRunConsole(virDomainPtr dom, old_sigpipe = signal(SIGPIPE, do_signal); got_signal = 0; - if (VIR_ALLOC(con) < 0) { - virReportOOMError(); + if (VIR_ALLOC(con) < 0) goto cleanup; - } con->escapeChar = vshGetEscapeChar(escape_seq); con->st = virStreamNew(virDomainGetConnect(dom), diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index 58d6d40..f7f7fb6 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -709,10 +709,8 @@ cmdDomIfGetLink(vshControl *ctl, const vshCmd *cmd) if (virAsprintf(&xpath, "/domain/devices/interface[(mac/@address = '%s') or " " (target/@dev = '%s')]", - macstr, iface) < 0) { - virReportOOMError(); + macstr, iface) < 0) goto cleanup; - } if ((ninterfaces = virXPathNodeSet(xpath, ctxt, &interfaces)) < 0) { vshError(ctl, _("Failed to extract interface information")); diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 5257416..1eb8ff8 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -6275,7 +6275,7 @@ cmdCPUStats(vshControl *ctl, const vshCmd *cmd) } if (VIR_ALLOC_N(params, nparams * MIN(show_count, 128)) < 0) - goto no_memory; + goto cleanup; while (show_count) { int ncpus = MIN(show_count, 128); @@ -6324,7 +6324,7 @@ do_show_total: } if (VIR_ALLOC_N(params, nparams) < 0) - goto no_memory; + goto cleanup; /* passing start_cpu == -1 gives us domain's total status */ if ((nparams = virDomainGetCPUStats(dom, params, nparams, -1, 1, flags)) < 0) @@ -6354,10 +6354,6 @@ cleanup: virDomainFree(dom); return ret; -no_memory: - virReportOOMError(); - goto cleanup; - failed_stats: vshError(ctl, _("Failed to retrieve CPU statistics for domain '%s'"), virDomainGetName(dom)); @@ -8843,7 +8839,7 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd) for (iter = 0; scheme[iter] != NULL; iter++) { /* Create our XPATH lookup for the current display's port */ if (virAsprintf(&xpath, xpath_fmt, scheme[iter], "port") < 0) - goto no_memory; + goto cleanup; /* Attempt to get the port number for the current graphics scheme */ tmp = virXPathInt(xpath, ctxt, &port); @@ -8856,7 +8852,7 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd) /* Create our XPATH lookup for the current display's address */ if (virAsprintf(&xpath, xpath_fmt, scheme[iter], "listen") < 0) - goto no_memory; + goto cleanup; /* Attempt to get the listening addr if set for the current * graphics scheme */ @@ -8870,7 +8866,7 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd) /* Create our XPATH lookup for the password */ if (virAsprintf(&xpath, xpath_fmt, scheme[iter], "passwd") < 0) - goto no_memory; + goto cleanup; /* Attempt to get the password */ passwd = virXPathString(xpath, ctxt); @@ -8885,7 +8881,7 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd) /* Create our XPATH lookup for TLS Port (automatically skipped * for unsupported schemes */ if (virAsprintf(&xpath, xpath_fmt, scheme[iter], "tlsPort") < 0) - goto no_memory; + goto cleanup; /* Attempt to get the TLS port number */ tmp = virXPathInt(xpath, ctxt, &tls_port); @@ -8951,10 +8947,6 @@ cleanup: xmlFreeDoc(xml); virDomainFree(dom); return ret; - -no_memory: - virReportOOMError(); - goto cleanup; } /* @@ -9192,10 +9184,8 @@ vshNodeIsSuperset(xmlNodePtr n1, xmlNodePtr n2) if (n1_child_size == 0 && n2_child_size == 0) return true; - if (!(bitmap = virBitmapNew(n1_child_size))) { - virReportOOMError(); + if (!(bitmap = virBitmapNew(n1_child_size))) return false; - } child2 = n2->children; while (child2) { @@ -9841,10 +9831,8 @@ cleanup: VIR_FREE(disk_type); if (xml_buf) { int len = xmlBufferLength(xml_buf); - if (VIR_ALLOC_N(ret, len + 1) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(ret, len + 1) < 0) return NULL; - } memcpy(ret, (char *)xmlBufferContent(xml_buf), len); ret[len] = '\0'; xmlBufferFree(xml_buf); diff --git a/tools/virsh.c b/tools/virsh.c index af2bb76..a7e7f0c 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -197,7 +197,6 @@ vshStringToArray(const char *str, } if (VIR_ALLOC_N(arr, nstr_tokens) < 0) { - virReportOOMError(); VIR_FREE(str_copied); return -1; } -- 1.8.1.5

On 07/04/13 14:07, Michal Privoznik wrote:
--- tools/console.c | 6 +----- tools/virsh-domain-monitor.c | 4 +--- tools/virsh-domain.c | 28 ++++++++-------------------- tools/virsh.c | 1 - 4 files changed, 10 insertions(+), 29 deletions(-)
...
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 5257416..1eb8ff8 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c /* @@ -9192,10 +9184,8 @@ vshNodeIsSuperset(xmlNodePtr n1, xmlNodePtr n2) if (n1_child_size == 0 && n2_child_size == 0) return true;
- if (!(bitmap = virBitmapNew(n1_child_size))) { - virReportOOMError(); + if (!(bitmap = virBitmapNew(n1_child_size))) return false; - }
see my comment in patch 28/37 why this would be problematic if you don't adapt virBitmapNew fully.
child2 = n2->children; while (child2) {
ACK to this patch though, src/util/virbitmap.c needs a change, not this patch. Peter
participants (5)
-
Ján Tomko
-
Laine Stump
-
Martin Kletzander
-
Michal Privoznik
-
Peter Krempa