--- HACKING | 24 +- daemon/libvirtd-config.c | 29 +-- daemon/libvirtd.c | 32 +-- daemon/remote.c | 292 +++++++--------------- daemon/stream.c | 4 +- docs/hacking.html.in | 24 +- src/conf/cpu_conf.c | 35 +-- src/conf/domain_conf.c | 370 +++++++++------------------- src/conf/domain_event.c | 26 +- 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 | 78 ++---- src/conf/node_device_conf.c | 26 +- src/conf/nwfilter_conf.c | 38 +-- src/conf/nwfilter_ipaddrmap.c | 8 +- src/conf/nwfilter_params.c | 43 +--- src/conf/secret_conf.c | 4 +- src/conf/snapshot_conf.c | 45 +--- src/conf/storage_conf.c | 40 +--- src/conf/storage_encryption_conf.c | 12 +- src/conf/virchrdev.c | 12 +- src/cpu/cpu.c | 4 +- src/cpu/cpu_arm.c | 4 +- src/cpu/cpu_generic.c | 14 +- src/cpu/cpu_powerpc.c | 27 +-- src/cpu/cpu_s390.c | 4 +- src/cpu/cpu_x86.c | 60 ++--- src/datatypes.c | 9 - src/esx/esx_driver.c | 91 ++----- src/esx/esx_interface_driver.c | 4 +- src/esx/esx_network_driver.c | 32 +-- src/esx/esx_storage_backend_iscsi.c | 21 +- src/esx/esx_storage_backend_vmfs.c | 92 ++----- src/esx/esx_util.c | 28 +-- src/esx/esx_vi.c | 84 ++----- src/esx/esx_vi_types.c | 16 +- src/fdstream.c | 4 +- src/hyperv/hyperv_driver.c | 51 +--- src/hyperv/hyperv_util.c | 12 +- src/hyperv/hyperv_wmi.c | 8 +- src/interface/interface_backend_netcf.c | 12 +- src/interface/interface_backend_udev.c | 53 ++-- src/libvirt.c | 18 +- src/libxl/libxl_conf.c | 78 ++---- src/libxl/libxl_driver.c | 69 ++---- src/locking/lock_daemon.c | 52 ++-- src/locking/lock_daemon_config.c | 14 +- src/locking/lock_daemon_dispatch.c | 4 +- src/locking/lock_driver_lockd.c | 46 ++-- src/locking/lock_driver_sanlock.c | 32 +-- src/locking/lock_manager.c | 20 +- src/lxc/lxc_conf.c | 11 +- src/lxc/lxc_container.c | 125 +++------- src/lxc/lxc_controller.c | 45 +--- src/lxc/lxc_driver.c | 97 ++------ src/lxc/lxc_fuse.c | 12 +- src/lxc/lxc_monitor.c | 4 +- src/lxc/lxc_process.c | 24 +- src/network/bridge_driver.c | 142 +++-------- src/node_device/node_device_driver.c | 19 +- src/node_device/node_device_udev.c | 54 +---- src/nodeinfo.c | 58 ++--- src/nwfilter/nwfilter_dhcpsnoop.c | 33 +-- src/nwfilter/nwfilter_driver.c | 16 +- src/nwfilter/nwfilter_ebiptables_driver.c | 25 +- src/nwfilter/nwfilter_gentech_driver.c | 25 +- src/nwfilter/nwfilter_learnipaddr.c | 16 +- src/openvz/openvz_conf.c | 70 +++--- src/openvz/openvz_driver.c | 15 +- src/parallels/parallels_driver.c | 88 +++---- src/parallels/parallels_network.c | 38 +-- src/parallels/parallels_storage.c | 90 ++----- src/parallels/parallels_utils.c | 4 +- src/phyp/phyp_driver.c | 124 +++------- src/qemu/qemu_agent.c | 24 +- src/qemu/qemu_capabilities.c | 74 ++---- src/qemu/qemu_command.c | 386 ++++++++++++------------------ src/qemu/qemu_conf.c | 99 +++----- src/qemu/qemu_domain.c | 42 +--- src/qemu/qemu_driver.c | 175 ++++---------- src/qemu/qemu_hotplug.c | 76 ++---- src/qemu/qemu_migration.c | 105 +++----- src/qemu/qemu_monitor.c | 35 +-- src/qemu/qemu_monitor_json.c | 140 +++-------- src/qemu/qemu_monitor_text.c | 241 +++++-------------- src/qemu/qemu_process.c | 65 ++--- src/remote/remote_driver.c | 155 ++++-------- src/rpc/gendispatch.pl | 18 +- src/rpc/virnetclient.c | 29 +-- src/rpc/virnetclientprogram.c | 12 +- src/rpc/virnetclientstream.c | 4 +- src/rpc/virnetmessage.c | 16 +- src/rpc/virnetsaslcontext.c | 4 +- src/rpc/virnetserver.c | 23 +- src/rpc/virnetserverclient.c | 26 +- src/rpc/virnetservermdns.c | 22 +- src/rpc/virnetserverprogram.c | 8 +- src/rpc/virnetserverservice.c | 12 +- src/rpc/virnetsocket.c | 16 +- src/rpc/virnetsshsession.c | 20 +- src/rpc/virnettlscontext.c | 13 +- src/secret/secret_driver.c | 46 +--- src/security/security_apparmor.c | 41 +--- src/security/security_dac.c | 16 +- src/security/security_manager.c | 8 +- src/security/security_nop.c | 4 +- src/security/security_selinux.c | 88 ++----- src/security/security_stack.c | 8 +- src/storage/storage_backend.c | 50 +--- src/storage/storage_backend_disk.c | 41 +--- src/storage/storage_backend_fs.c | 57 ++--- src/storage/storage_backend_iscsi.c | 33 +-- src/storage/storage_backend_logical.c | 60 ++--- src/storage/storage_backend_mpath.c | 24 +- src/storage/storage_backend_rbd.c | 20 +- src/storage/storage_backend_scsi.c | 27 +-- src/storage/storage_backend_sheepdog.c | 8 +- src/storage/storage_driver.c | 33 +-- src/test/test_driver.c | 135 +++-------- src/uml/uml_conf.c | 36 +-- src/uml/uml_driver.c | 40 +--- src/util/iohelper.c | 4 +- src/util/virauth.c | 17 +- src/util/virauthconfig.c | 24 +- src/util/vircommand.c | 13 +- src/util/virconf.c | 11 +- src/util/virdnsmasq.c | 35 +-- src/util/vireventpoll.c | 4 +- src/util/virfile.c | 12 +- src/util/virhash.c | 11 +- src/util/viridentity.c | 8 +- src/util/virinitctl.c | 12 +- src/util/viriptables.c | 11 +- src/util/virjson.c | 3 +- src/util/virkeyfile.c | 4 +- src/util/virlockspace.c | 50 +--- src/util/virnetdev.c | 44 +--- src/util/virnetdevbandwidth.c | 21 +- src/util/virnetdevbridge.c | 8 +- src/util/virnetdevmacvlan.c | 15 +- src/util/virnetdevopenvswitch.c | 12 +- src/util/virnetdevtap.c | 4 +- src/util/virnetdevveth.c | 8 +- src/util/virnetdevvlan.c | 4 +- src/util/virnetdevvportprofile.c | 5 +- src/util/virnetlink.c | 8 +- src/util/virobject.c | 5 +- src/util/virpci.c | 82 ++----- src/util/virportallocator.c | 1 - src/util/virprocess.c | 20 +- src/util/virrandom.c | 4 +- src/util/virsexpr.c | 8 +- src/util/virsocketaddr.c | 1 - src/util/virstoragefile.c | 37 +-- src/util/virstring.c | 13 +- src/util/virsysinfo.c | 6 +- src/util/virthreadpool.c | 21 +- src/util/virtime.c | 8 +- src/util/virtypedparam.c | 44 +--- src/util/viruri.c | 23 +- src/util/virusb.c | 13 +- src/util/virutil.c | 134 +++-------- src/util/virxml.c | 4 - src/vbox/vbox_MSCOMGlue.c | 8 +- src/vbox/vbox_XPCOMCGlue.c | 8 +- src/vbox/vbox_tmpl.c | 242 ++++--------------- src/vmware/vmware_conf.c | 44 +--- src/vmware/vmware_driver.c | 13 +- src/vmx/vmx.c | 108 +++------ src/xen/block_stats.c | 8 +- src/xen/xen_driver.c | 37 +-- src/xen/xen_hypervisor.c | 39 +-- src/xen/xen_inotify.c | 10 +- src/xen/xend_internal.c | 84 ++----- src/xen/xm_internal.c | 30 +-- src/xen/xs_internal.c | 31 +-- src/xenapi/xenapi_driver.c | 30 +-- src/xenapi/xenapi_utils.c | 8 +- src/xenxs/xen_sxpr.c | 149 +++++------- src/xenxs/xen_xm.c | 228 ++++++++---------- tests/commandtest.c | 8 +- tests/libvirtdconftest.c | 4 +- tests/qemumonitortestutils.c | 5 +- 185 files changed, 2130 insertions(+), 5646 deletions(-) diff --git a/HACKING b/HACKING index c511cab..3d8c611 100644 --- a/HACKING +++ b/HACKING @@ -501,16 +501,16 @@ Low level memory management Use of the malloc/free/realloc/calloc APIs is deprecated in the libvirt codebase, because they encourage a number of serious coding bugs and do not enable compile time verification of checks for NULL. Instead of these -routines, use the macros from memory.h. +routines, use the macros from memory.h. Note, that these functions +automatically report OOM error. If you want to suppress such behaviour, use +VIR_ALLOCNOOM() and variants. - To allocate a single object: virDomainPtr domain; - if (VIR_ALLOC(domain) < 0) { - virReportOOMError(); + if (VIR_ALLOC(domain) < 0) return NULL; - } @@ -519,10 +519,8 @@ routines, use the macros from memory.h. virDomainPtr domains; size_t ndomains = 10; - if (VIR_ALLOC_N(domains, ndomains) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(domains, ndomains) < 0) return NULL; - } @@ -531,10 +529,8 @@ routines, use the macros from memory.h. virDomainPtr *domains; size_t ndomains = 10; - if (VIR_ALLOC_N(domains, ndomains) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(domains, ndomains) < 0) return NULL; - } @@ -545,10 +541,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; @@ -560,10 +554,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/daemon/libvirtd-config.c b/daemon/libvirtd-config.c index 915c7f3..0c0d7be 100644 --- a/daemon/libvirtd-config.c +++ b/daemon/libvirtd-config.c @@ -146,10 +146,8 @@ checkType(virConfValuePtr p, const char *filename, if (checkType(p, filename, #var_name, VIR_CONF_STRING) < 0) \ goto error; \ VIR_FREE(data->var_name); \ - if (!(data->var_name = VIR_STRDUP(p->str))) { \ - virReportOOMError(); \ + if (!(data->var_name = VIR_STRDUP(p->str))) \ goto error; \ - } \ } \ } while (0) @@ -201,7 +199,7 @@ daemonConfigFilePath(bool privileged, char **configfile) { if (privileged) { if (!(*configfile = VIR_STRDUP(SYSCONFDIR "/libvirt/libvirtd.conf"))) - goto no_memory; + goto error; } else { char *configdir = NULL; @@ -210,15 +208,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; } @@ -230,18 +226,16 @@ 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; if (!(data->tls_port = VIR_STRDUP(LIBVIRTD_TLS_PORT))) - goto no_memory; + goto error; if (!(data->tcp_port = VIR_STRDUP(LIBVIRTD_TCP_PORT))) - goto no_memory; + goto error; /* Only default to PolicyKit if running as root */ #if WITH_POLKIT @@ -263,7 +257,7 @@ daemonConfigNew(bool privileged ATTRIBUTE_UNUSED) data->unix_sock_ro_perms = VIR_STRDUP("0777"); /* Always allow world */ if (!data->unix_sock_ro_perms || !data->unix_sock_rw_perms) - goto no_memory; + goto error; #if WITH_SASL data->auth_tcp = REMOTE_AUTH_SASL; @@ -309,12 +303,11 @@ 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; } @@ -382,10 +375,8 @@ daemonConfigLoadOptions(struct daemonConfig *data, */ if (data->auth_unix_rw == REMOTE_AUTH_POLKIT) { VIR_FREE(data->unix_sock_rw_perms); - if (!(data->unix_sock_rw_perms = VIR_STRDUP("0777"))) { - virReportOOMError(); + if (!(data->unix_sock_rw_perms = VIR_STRDUP("0777"))) goto error; - } } #endif if (remoteConfigGetAuth(conf, "auth_unix_ro", &data->auth_unix_ro, filename) < 0) diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c index c9af4dc..6095fbf 100644 --- a/daemon/libvirtd.c +++ b/daemon/libvirtd.c @@ -243,7 +243,7 @@ daemonPidFilePath(bool privileged, { if (privileged) { if (!(*pidfile = VIR_STRDUP(LOCALSTATEDIR "/run/libvirtd.pid"))) - goto no_memory; + goto error; } else { char *rundir = NULL; mode_t old_umask; @@ -260,7 +260,7 @@ daemonPidFilePath(bool privileged, if (virAsprintf(pidfile, "%s/libvirtd.pid", rundir) < 0) { VIR_FREE(rundir); - goto no_memory; + goto error; } VIR_FREE(rundir); @@ -268,8 +268,6 @@ daemonPidFilePath(bool privileged, return 0; -no_memory: - virReportOOMError(); error: return -1; } @@ -282,16 +280,16 @@ 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 (!(*sockfile = VIR_STRDUP(LOCALSTATEDIR "/run/libvirt/libvirt-sock"))) - goto no_memory; + goto error; if (!(*rosockfile = VIR_STRDUP(LOCALSTATEDIR "/run/libvirt/libvirt-sock-ro"))) - goto no_memory; + goto error; } else { char *rundir = NULL; mode_t old_umask; @@ -308,7 +306,7 @@ daemonUnixSocketPaths(struct daemonConfig *config, if (virAsprintf(sockfile, "%s/libvirt-sock", rundir) < 0) { VIR_FREE(rundir); - goto no_memory; + goto error; } VIR_FREE(rundir); @@ -316,8 +314,6 @@ daemonUnixSocketPaths(struct daemonConfig *config, } return 0; -no_memory: - virReportOOMError(); error: return -1; } @@ -658,7 +654,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); } @@ -676,7 +672,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; @@ -694,13 +690,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); @@ -714,8 +710,6 @@ daemonSetupLogging(struct daemonConfig *config, return 0; -no_memory: - virReportOOMError(); error: return -1; } @@ -1297,10 +1291,8 @@ int main(int argc, char **argv) { goto cleanup; } } - if (!run_dir) { - virReportOOMError(); + if (!run_dir) goto cleanup; - } if (privileged) old_umask = umask(022); diff --git a/daemon/remote.c b/daemon/remote.c index 318a32b..b851e29 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -238,10 +238,10 @@ static int remoteRelayDomainEventIOError(virConnectPtr conn ATTRIBUTE_UNUSED, memset(&data, 0, sizeof(data)); data.srcPath = VIR_STRDUP(srcPath); if (data.srcPath == NULL) - goto mem_error; + goto error; data.devAlias = VIR_STRDUP(devAlias); if (data.devAlias == NULL) - goto mem_error; + goto error; make_nonnull_domain(&data.dom, dom); data.action = action; @@ -250,8 +250,7 @@ static int remoteRelayDomainEventIOError(virConnectPtr conn ATTRIBUTE_UNUSED, (xdrproc_t)xdr_remote_domain_event_io_error_msg, &data); return 0; -mem_error: - virReportOOMError(); +error: VIR_FREE(data.srcPath); VIR_FREE(data.devAlias); return -1; @@ -279,14 +278,14 @@ static int remoteRelayDomainEventIOErrorReason(virConnectPtr conn ATTRIBUTE_UNUS memset(&data, 0, sizeof(data)); data.srcPath = VIR_STRDUP(srcPath); if (data.srcPath == NULL) - goto mem_error; + goto error; data.devAlias = VIR_STRDUP(devAlias); if (data.devAlias == NULL) - goto mem_error; + goto error; data.action = action; data.reason = VIR_STRDUP(reason); if (data.reason == NULL) - goto mem_error; + goto error; make_nonnull_domain(&data.dom, dom); @@ -296,8 +295,7 @@ static int remoteRelayDomainEventIOErrorReason(virConnectPtr conn ATTRIBUTE_UNUS return 0; -mem_error: - virReportOOMError(); +error: VIR_FREE(data.srcPath); VIR_FREE(data.devAlias); VIR_FREE(data.reason); @@ -338,33 +336,33 @@ static int remoteRelayDomainEventGraphics(virConnectPtr conn ATTRIBUTE_UNUSED, data.remote.family = remote->family; data.authScheme = VIR_STRDUP(authScheme); if (data.authScheme == NULL) - goto mem_error; + goto error; data.local.node = VIR_STRDUP(local->node); if (data.local.node == NULL) - goto mem_error; + goto error; data.local.service = VIR_STRDUP(local->service); if (data.local.service == NULL) - goto mem_error; + goto error; data.remote.node = VIR_STRDUP(remote->node); if (data.remote.node == NULL) - goto mem_error; + goto error; data.remote.service = VIR_STRDUP(remote->service); if (data.remote.service == NULL) - goto mem_error; + goto error; data.subject.subject_len = subject->nidentity; if (VIR_ALLOC_N(data.subject.subject_val, data.subject.subject_len) < 0) - goto mem_error; + goto error; for (i = 0 ; i < data.subject.subject_len ; i++) { data.subject.subject_val[i].type = VIR_STRDUP(subject->identities[i].type); if (data.subject.subject_val[i].type == NULL) - goto mem_error; + goto error; data.subject.subject_val[i].name = VIR_STRDUP(subject->identities[i].name); if (data.subject.subject_val[i].name == NULL) - goto mem_error; + goto error; } make_nonnull_domain(&data.dom, dom); @@ -374,8 +372,7 @@ static int remoteRelayDomainEventGraphics(virConnectPtr conn ATTRIBUTE_UNUSED, return 0; -mem_error: - virReportOOMError(); +error: VIR_FREE(data.authScheme); VIR_FREE(data.local.node); VIR_FREE(data.local.service); @@ -411,7 +408,7 @@ static int remoteRelayDomainEventBlockJob(virConnectPtr conn ATTRIBUTE_UNUSED, memset(&data, 0, sizeof(data)); data.path = VIR_STRDUP(path); if (data.path == NULL) - goto mem_error; + goto error; data.type = type; data.status = status; make_nonnull_domain(&data.dom, dom); @@ -422,8 +419,7 @@ static int remoteRelayDomainEventBlockJob(virConnectPtr conn ATTRIBUTE_UNUSED, return 0; -mem_error: - virReportOOMError(); +error: VIR_FREE(data.path); return -1; } @@ -476,17 +472,17 @@ static int remoteRelayDomainEventDiskChange(virConnectPtr conn ATTRIBUTE_UNUSED, if (oldSrcPath && ((VIR_ALLOC(oldSrcPath_p) < 0) || !(*oldSrcPath_p = VIR_STRDUP(oldSrcPath)))) - goto mem_error; + goto error; if (newSrcPath && ((VIR_ALLOC(newSrcPath_p) < 0) || !(*newSrcPath_p = VIR_STRDUP(newSrcPath)))) - goto mem_error; + goto error; data.oldSrcPath = oldSrcPath_p; data.newSrcPath = newSrcPath_p; if (!(data.devAlias = VIR_STRDUP(devAlias))) - goto mem_error; + goto error; data.reason = reason; make_nonnull_domain(&data.dom, dom); @@ -497,10 +493,9 @@ static int remoteRelayDomainEventDiskChange(virConnectPtr conn ATTRIBUTE_UNUSED, return 0; -mem_error: +error: VIR_FREE(oldSrcPath_p); VIR_FREE(newSrcPath_p); - virReportOOMError(); return -1; } @@ -522,10 +517,8 @@ static int remoteRelayDomainEventTrayChange(virConnectPtr conn ATTRIBUTE_UNUSED, /* build return data */ memset(&data, 0, sizeof(data)); - if (!(data.devAlias = VIR_STRDUP(devAlias))) { - virReportOOMError(); + if (!(data.devAlias = VIR_STRDUP(devAlias))) return -1; - } data.reason = reason; make_nonnull_domain(&data.dom, dom); @@ -699,14 +692,11 @@ 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(); return NULL; } @@ -836,10 +826,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 @@ -853,10 +841,8 @@ remoteSerializeTypedParameters(virTypedParameterPtr params, /* remoteDispatchClientRequest will free this: */ val[j].field = VIR_STRDUP(params[i].field); - if (val[j].field == NULL) { - virReportOOMError(); + if (val[j].field == NULL) goto cleanup; - } val[j].value.type = params[i].type; switch (params[i].type) { case VIR_TYPED_PARAM_INT: @@ -880,10 +866,8 @@ remoteSerializeTypedParameters(virTypedParameterPtr params, case VIR_TYPED_PARAM_STRING: val[j].value.remote_typed_param_value_u.s = VIR_STRDUP(params[i].value.s); - if (val[j].value.remote_typed_param_value_u.s == NULL) { - virReportOOMError(); + if (val[j].value.remote_typed_param_value_u.s == NULL) goto cleanup; - } break; default: virReportError(VIR_ERR_RPC, _("unknown parameter type: %d"), @@ -925,10 +909,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; @@ -970,10 +952,8 @@ remoteDeserializeTypedParameters(remote_typed_param *args_params_val, case VIR_TYPED_PARAM_STRING: params[i].value.s = VIR_STRDUP(args_params_val[i].value.remote_typed_param_value_u.s); - if (params[i].value.s == NULL) { - virReportOOMError(); + if (params[i].value.s == NULL) goto cleanup; - } break; default: virReportError(VIR_ERR_INTERNAL_ERROR, _("unknown parameter type: %d"), @@ -1017,7 +997,7 @@ remoteDispatchDomainGetSchedulerParameters(virNetServerPtr server ATTRIBUTE_UNUS goto cleanup; } if (nparams && VIR_ALLOC_N(params, nparams) < 0) - goto no_memory; + goto cleanup; if (!(dom = get_nonnull_domain(priv->conn, args->dom))) goto cleanup; @@ -1040,10 +1020,6 @@ cleanup: if (dom) virDomainFree(dom); return rv; - -no_memory: - virReportOOMError(); - goto cleanup; } static int @@ -1071,10 +1047,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; @@ -1125,7 +1099,7 @@ remoteDispatchDomainGetSchedulerParametersFlags(virNetServerPtr server ATTRIBUTE goto cleanup; } if (nparams && VIR_ALLOC_N(params, nparams) < 0) - goto no_memory; + goto cleanup; if (!(dom = get_nonnull_domain(priv->conn, args->dom))) goto cleanup; @@ -1149,10 +1123,6 @@ cleanup: if (dom) virDomainFree(dom); return rv; - -no_memory: - virReportOOMError(); - goto cleanup; } static int @@ -1185,20 +1155,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++) { @@ -1253,10 +1219,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) @@ -1304,10 +1268,8 @@ remoteDispatchDomainBlockStatsFlags(virNetServerPtr server ATTRIBUTE_UNUSED, virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too large")); goto cleanup; } - if (nparams && VIR_ALLOC_N(params, nparams) < 0) { - virReportOOMError(); + if (nparams && VIR_ALLOC_N(params, nparams) < 0) goto cleanup; - } if (virDomainBlockStatsFlags(dom, path, params, &nparams, flags) < 0) goto cleanup; @@ -1373,10 +1335,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) @@ -1416,19 +1376,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; @@ -1472,18 +1428,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")); @@ -1528,17 +1480,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; @@ -1586,7 +1534,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, @@ -1613,10 +1561,6 @@ cleanup: if (dom) virDomainFree(dom); return rv; - -no_memory: - virReportOOMError(); - goto cleanup; } static int @@ -1682,7 +1626,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, @@ -1704,10 +1648,6 @@ cleanup: if (dom) virDomainFree(dom); return rv; - -no_memory: - virReportOOMError(); - goto cleanup; } static int @@ -1747,10 +1687,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, @@ -1760,7 +1700,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; @@ -1789,10 +1729,6 @@ cleanup: if (dom) virDomainFree(dom); return rv; - -no_memory: - virReportOOMError(); - goto cleanup; } static int @@ -1821,10 +1757,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, @@ -1878,10 +1812,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, @@ -1931,10 +1863,8 @@ remoteDispatchDomainGetMemoryParameters(virNetServerPtr server ATTRIBUTE_UNUSED, virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too large")); goto cleanup; } - if (nparams && VIR_ALLOC_N(params, nparams) < 0) { - virReportOOMError(); + if (nparams && VIR_ALLOC_N(params, nparams) < 0) goto cleanup; - } if (!(dom = get_nonnull_domain(priv->conn, args->dom))) goto cleanup; @@ -1995,10 +1925,8 @@ remoteDispatchDomainGetNumaParameters(virNetServerPtr server ATTRIBUTE_UNUSED, virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too large")); goto cleanup; } - if (nparams && VIR_ALLOC_N(params, nparams) < 0) { - virReportOOMError(); + if (nparams && VIR_ALLOC_N(params, nparams) < 0) goto cleanup; - } if (!(dom = get_nonnull_domain(priv->conn, args->dom))) goto cleanup; @@ -2059,10 +1987,8 @@ remoteDispatchDomainGetBlkioParameters(virNetServerPtr server ATTRIBUTE_UNUSED, virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too large")); goto cleanup; } - if (nparams && VIR_ALLOC_N(params, nparams) < 0) { - virReportOOMError(); + if (nparams && VIR_ALLOC_N(params, nparams) < 0) goto cleanup; - } if (!(dom = get_nonnull_domain(priv->conn, args->dom))) goto cleanup; @@ -2124,10 +2050,8 @@ remoteDispatchNodeGetCPUStats(virNetServerPtr server ATTRIBUTE_UNUSED, virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too large")); goto cleanup; } - if (VIR_ALLOC_N(params, nparams) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(params, nparams) < 0) goto cleanup; - } if (virNodeGetCPUStats(priv->conn, cpuNum, params, &nparams, flags) < 0) goto cleanup; @@ -2143,13 +2067,13 @@ 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: */ ret->params.params_val[i].field = VIR_STRDUP(params[i].field); if (ret->params.params_val[i].field == NULL) - goto no_memory; + goto cleanup; ret->params.params_val[i].value = params[i].value; } @@ -2168,10 +2092,6 @@ cleanup: } VIR_FREE(params); return rv; - -no_memory: - virReportOOMError(); - goto cleanup; } static int @@ -2202,10 +2122,8 @@ remoteDispatchNodeGetMemoryStats(virNetServerPtr server ATTRIBUTE_UNUSED, virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too large")); goto cleanup; } - if (VIR_ALLOC_N(params, nparams) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(params, nparams) < 0) goto cleanup; - } if (virNodeGetMemoryStats(priv->conn, cellNum, params, &nparams, flags) < 0) goto cleanup; @@ -2221,13 +2139,13 @@ 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: */ ret->params.params_val[i].field = VIR_STRDUP(params[i].field); if (ret->params.params_val[i].field == NULL) - goto no_memory; + goto cleanup; ret->params.params_val[i].value = params[i].value; } @@ -2246,10 +2164,6 @@ cleanup: } VIR_FREE(params); return rv; - -no_memory: - virReportOOMError(); - goto cleanup; } static int @@ -2318,10 +2232,8 @@ remoteDispatchDomainGetBlockIoTune(virNetServerPtr server ATTRIBUTE_UNUSED, goto cleanup; } - if (nparams && VIR_ALLOC_N(params, nparams) < 0) { - virReportOOMError(); + if (nparams && VIR_ALLOC_N(params, nparams) < 0) goto cleanup; - } if (!(dom = get_nonnull_domain(priv->conn, args->dom))) goto cleanup; @@ -2385,10 +2297,8 @@ remoteDispatchAuthList(virNetServerPtr server ATTRIBUTE_UNUSED, } else if (callerUid == 0) { char *ident; if (virAsprintf(&ident, "pid:%lld,uid:%d", - (long long) callerPid, callerUid) < 0) { - virReportOOMError(); + (long long) callerPid, callerUid) < 0) goto cleanup; - } VIR_INFO("Bypass polkit auth for privileged client %s", ident); virNetServerClientSetAuth(client, 0); auth = VIR_NET_SERVER_SERVICE_AUTH_NONE; @@ -2397,10 +2307,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: @@ -2841,10 +2749,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; @@ -2945,10 +2851,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; @@ -3098,13 +3002,10 @@ 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 (!(*parent_p = VIR_STRDUP(parent))) { VIR_FREE(parent_p); - virReportOOMError(); goto cleanup; } ret->parent = parent_p; @@ -3521,10 +3422,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, @@ -3819,10 +3718,8 @@ remoteDispatchDomainGetInterfaceParameters(virNetServerPtr server ATTRIBUTE_UNUS virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too large")); goto cleanup; } - if (nparams && VIR_ALLOC_N(params, nparams) < 0) { - virReportOOMError(); + if (nparams && VIR_ALLOC_N(params, nparams) < 0) goto cleanup; - } if (!(dom = get_nonnull_domain(priv->conn, args->dom))) goto cleanup; @@ -3886,10 +3783,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; @@ -3960,10 +3855,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, @@ -4022,10 +3915,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; @@ -4086,10 +3977,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; @@ -4144,10 +4033,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; @@ -4202,10 +4089,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; @@ -4256,10 +4141,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; @@ -4310,10 +4193,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; @@ -4364,10 +4245,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; @@ -4418,10 +4297,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; @@ -4472,10 +4349,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; @@ -4527,10 +4402,8 @@ remoteDispatchNodeGetMemoryParameters(virNetServerPtr server ATTRIBUTE_UNUSED, virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too large")); goto cleanup; } - if (nparams && VIR_ALLOC_N(params, nparams) < 0) { - virReportOOMError(); + if (nparams && VIR_ALLOC_N(params, nparams) < 0) goto cleanup; - } if (virNodeGetMemoryParameters(priv->conn, params, &nparams, flags) < 0) @@ -4844,11 +4717,11 @@ remoteSerializeDomainDiskErrors(virDomainDiskErrorPtr errors, int i = 0; if (VIR_ALLOC_N(val, nerrors) < 0) - goto no_memory; + goto error; for (i = 0; i < nerrors; i++) { if (!(val[i].disk = VIR_STRDUP(errors[i].disk))) - goto no_memory; + goto error; val[i].error = errors[i].error; } @@ -4857,13 +4730,12 @@ remoteSerializeDomainDiskErrors(virDomainDiskErrorPtr errors, return 0; -no_memory: +error: if (val) { int j; for (j = 0; j < i; j++) VIR_FREE(val[j].disk); VIR_FREE(val); } - virReportOOMError(); return -1; } diff --git a/daemon/stream.c b/daemon/stream.c index 4df1145..9cf484a 100644 --- a/daemon/stream.c +++ b/daemon/stream.c @@ -317,10 +317,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; diff --git a/docs/hacking.html.in b/docs/hacking.html.in index 531681b..0f2160f 100644 --- a/docs/hacking.html.in +++ b/docs/hacking.html.in @@ -614,7 +614,9 @@ Use of the malloc/free/realloc/calloc APIs is deprecated in the libvirt codebase, because they encourage a number of serious coding bugs and do not enable compile time verification of checks for NULL. Instead of these - routines, use the macros from memory.h. + routines, use the macros from memory.h. Note, that these functions + automatically report OOM error. If you want to suppress such behaviour, + use VIR_ALLOCNOOM() and variants. </p> <ul> @@ -623,10 +625,8 @@ <pre> virDomainPtr domain; - if (VIR_ALLOC(domain) < 0) { - virReportOOMError(); + if (VIR_ALLOC(domain) < 0) return NULL; - } </pre> </li> @@ -635,10 +635,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> @@ -647,10 +645,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> @@ -662,10 +658,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> @@ -678,10 +672,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> diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c index 6f6ed0e..fd5a402 100644 --- a/src/conf/cpu_conf.c +++ b/src/conf/cpu_conf.c @@ -103,7 +103,7 @@ virCPUDefCopyModel(virCPUDefPtr dst, || (src->vendor && !(dst->vendor = VIR_STRDUP(src->vendor))) || (src->vendor_id && !(dst->vendor_id = VIR_STRDUP(src->vendor_id))) || VIR_ALLOC_N(dst->features, src->nfeatures) < 0) - goto no_memory; + goto cleanup; dst->nfeatures_max = dst->nfeatures = src->nfeatures; for (i = 0; i < dst->nfeatures; i++) { @@ -119,13 +119,12 @@ virCPUDefCopyModel(virCPUDefPtr dst, } if (!(dst->features[i].name = VIR_STRDUP(src->features[i].name))) - goto no_memory; + goto cleanup; } return 0; -no_memory: - virReportOOMError(); +cleanup: return -1; } @@ -139,7 +138,7 @@ virCPUDefCopy(const virCPUDefPtr cpu) return NULL; if (VIR_ALLOC(copy) < 0) - goto no_memory; + goto error; copy->type = cpu->type; copy->mode = cpu->mode; @@ -155,7 +154,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,18 +164,16 @@ virCPUDefCopy(const virCPUDefPtr cpu) copy->cells[i].cpumask = virBitmapNewCopy(cpu->cells[i].cpumask); if (!copy->cells[i].cpumask) - goto no_memory; + goto error; if (!(copy->cells[i].cpustr = VIR_STRDUP(cpu->cells[i].cpustr))) - goto no_memory; + goto error; } copy->cells_cpus = cpu->cells_cpus; } return copy; -no_memory: - virReportOOMError(); error: virCPUDefFree(copy); return NULL; @@ -202,10 +199,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 +378,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 +438,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 +485,6 @@ cleanup: VIR_FREE(nodes); return def; -no_memory: - virReportOOMError(); - error: virCPUDefFree(def); def = NULL; @@ -689,21 +681,20 @@ virCPUDefAddFeature(virCPUDefPtr def, if (VIR_RESIZE_N(def->features, def->nfeatures_max, def->nfeatures, 1) < 0) - goto no_memory; + goto error; if (def->type == VIR_CPU_TYPE_HOST) policy = -1; if (!(def->features[def->nfeatures].name = VIR_STRDUP(name))) - goto no_memory; + goto error; def->features[def->nfeatures].policy = policy; def->nfeatures++; return 0; -no_memory: - virReportOOMError(); +error: return -1; } diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index b21bf88..6a74e51 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1286,59 +1286,43 @@ virDomainChrSourceDefCopy(virDomainChrSourceDefPtr dest, case VIR_DOMAIN_CHR_TYPE_FILE: case VIR_DOMAIN_CHR_TYPE_PIPE: if (src->data.file.path && - !(dest->data.file.path = VIR_STRDUP(src->data.file.path))) { - virReportOOMError(); + !(dest->data.file.path = VIR_STRDUP(src->data.file.path))) return -1; - } break; case VIR_DOMAIN_CHR_TYPE_UDP: if (src->data.udp.bindHost && - !(dest->data.udp.bindHost = VIR_STRDUP(src->data.udp.bindHost))) { - virReportOOMError(); + !(dest->data.udp.bindHost = VIR_STRDUP(src->data.udp.bindHost))) return -1; - } if (src->data.udp.bindService && - !(dest->data.udp.bindService = VIR_STRDUP(src->data.udp.bindService))) { - virReportOOMError(); + !(dest->data.udp.bindService = VIR_STRDUP(src->data.udp.bindService))) return -1; - } if (src->data.udp.connectHost && - !(dest->data.udp.connectHost = VIR_STRDUP(src->data.udp.connectHost))) { - virReportOOMError(); + !(dest->data.udp.connectHost = VIR_STRDUP(src->data.udp.connectHost))) return -1; - } if (src->data.udp.connectService && - !(dest->data.udp.connectService = VIR_STRDUP(src->data.udp.connectService))) { - virReportOOMError(); + !(dest->data.udp.connectService = VIR_STRDUP(src->data.udp.connectService))) return -1; - } break; case VIR_DOMAIN_CHR_TYPE_TCP: if (src->data.tcp.host && - !(dest->data.tcp.host = VIR_STRDUP(src->data.tcp.host))) { - virReportOOMError(); + !(dest->data.tcp.host = VIR_STRDUP(src->data.tcp.host))) return -1; - } if (src->data.tcp.service && - !(dest->data.tcp.service = VIR_STRDUP(src->data.tcp.service))) { - virReportOOMError(); + !(dest->data.tcp.service = VIR_STRDUP(src->data.tcp.service))) return -1; - } break; case VIR_DOMAIN_CHR_TYPE_UNIX: if (src->data.nix.path && - !(dest->data.nix.path = VIR_STRDUP(src->data.nix.path))) { - virReportOOMError(); + !(dest->data.nix.path = VIR_STRDUP(src->data.nix.path))) return -1; - } break; } @@ -1531,12 +1515,9 @@ virDomainHostdevDefPtr virDomainHostdevDefAlloc(void) { virDomainHostdevDefPtr def = NULL; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } if (VIR_ALLOC(def->info) < 0) { - virReportOOMError(); VIR_FREE(def); return NULL; } @@ -1695,20 +1676,20 @@ virDomainVcpuPinDefCopy(virDomainVcpuPinDefPtr *src, int nvcpupin) virDomainVcpuPinDefPtr *ret = NULL; if (VIR_ALLOC_N(ret, nvcpupin) < 0) { - goto no_memory; + 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]) { @@ -1718,8 +1699,6 @@ no_memory: } VIR_FREE(ret); } - virReportOOMError(); - return NULL; } @@ -2260,14 +2239,10 @@ virDomainDeviceInfoCopy(virDomainDeviceInfoPtr dst, dst->alias = NULL; dst->romfile = NULL; - if (src->alias && !(dst->alias = VIR_STRDUP(src->alias))) { - virReportOOMError(); + if (src->alias && !(dst->alias = VIR_STRDUP(src->alias))) return -1; - } - if (src->romfile && !(dst->romfile = VIR_STRDUP(src->romfile))) { - virReportOOMError(); + if (src->romfile && !(dst->romfile = VIR_STRDUP(src->romfile))) return -1; - } return 0; } @@ -3569,10 +3544,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); @@ -3693,10 +3666,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++) { @@ -3727,10 +3698,8 @@ virSecurityLabelDefsParseXML(virDomainDefPtr def, VIR_DEBUG("Found seclabel without a model, using '%s'", host->secModels[0].model); def->seclabels[0]->model = VIR_STRDUP(host->secModels[0].model); - if (!def->seclabels[0]->model) { - virReportOOMError(); + if (!def->seclabels[0]->model) goto error; - } } else { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing security model in domain seclabel")); @@ -3782,16 +3751,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++) { @@ -3876,10 +3841,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) { @@ -3996,10 +3959,8 @@ virDomainDiskDefParseXML(virCapsPtr caps, 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; @@ -4074,10 +4035,8 @@ virDomainDiskDefParseXML(virCapsPtr caps, 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; @@ -4728,7 +4687,7 @@ virDomainDiskDefParseXML(virCapsPtr caps, if (!def->driverName && caps->defaultDiskDriverName && !(def->driverName = VIR_STRDUP(caps->defaultDiskDriverName))) - goto no_memory; + goto error; if (mirrorFormat) { def->mirrorFormat = virStorageFileFormatTypeFromString(mirrorFormat); @@ -4792,9 +4751,6 @@ cleanup: ctxt->node = save_ctxt; return def; -no_memory: - virReportOOMError(); - error: virDomainDiskDefFree(def); def = NULL; @@ -4826,10 +4782,8 @@ virDomainControllerDefParseXML(xmlNodePtr node, char *idx = NULL; char *model = NULL; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } type = virXMLPropString(node, "type"); if (type) { @@ -4965,10 +4919,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) @@ -4985,10 +4937,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) @@ -5023,10 +4973,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) { @@ -5185,10 +5133,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; @@ -5262,10 +5208,8 @@ virDomainActualNetDefParseXML(xmlNodePtr node, addrtype = virXPathString("string(./source/address/@type)", ctxt); /* if not explicitly stated, source/vendor implies usb device */ if (!addrtype && virXPathNode("./source/vendor", ctxt) && - (addrtype = VIR_STRDUP("usb")) == NULL) { - virReportOOMError(); + (addrtype = VIR_STRDUP("usb")) == NULL) goto error; - } hostdev->mode = VIR_DOMAIN_HOSTDEV_MODE_SUBSYS; if (virDomainHostdevDefParseXMLSubsys(node, ctxt, addrtype, hostdev, flags) < 0) { @@ -5350,10 +5294,8 @@ virDomainNetDefParseXML(virCapsPtr caps, xmlNodePtr oldnode = ctxt->node; int ret; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } ctxt->node = node; @@ -5654,10 +5596,8 @@ virDomainNetDefParseXML(virCapsPtr caps, addrtype = virXPathString("string(./source/address/@type)", ctxt); /* if not explicitly stated, source/vendor implies usb device */ if (!addrtype && virXPathNode("./source/vendor", ctxt) && - ((addrtype = VIR_STRDUP("usb")) == NULL)) { - virReportOOMError(); + ((addrtype = VIR_STRDUP("usb")) == NULL)) goto error; - } hostdev->mode = VIR_DOMAIN_HOSTDEV_MODE_SUBSYS; if (virDomainHostdevDefParseXMLSubsys(node, ctxt, addrtype, hostdev, flags) < 0) { @@ -5916,10 +5856,8 @@ virDomainChrDefParseTargetXML(virCapsPtr caps, 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", @@ -6213,10 +6151,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; @@ -6364,10 +6300,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) { @@ -6493,10 +6427,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"); @@ -6589,10 +6521,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"); @@ -6639,10 +6569,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; @@ -6898,10 +6826,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; @@ -6931,10 +6857,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], @@ -7393,10 +7317,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) { @@ -7426,10 +7348,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; @@ -7453,7 +7373,6 @@ virDomainSoundDefParseXML(const xmlNodePtr node, int ii; if (VIR_ALLOC_N(def->codecs, ncodecs) < 0) { - virReportOOMError(); VIR_FREE(codecNodes); goto error; } @@ -7495,10 +7414,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) { @@ -7554,10 +7471,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")); @@ -7625,10 +7540,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) { @@ -7673,10 +7586,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) { @@ -7717,10 +7628,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) { @@ -7853,10 +7762,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")) @@ -7890,10 +7797,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) { @@ -8071,10 +7976,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) { @@ -8158,10 +8061,8 @@ virDomainRedirFilterUsbVersionHelper(const char *version, unsigned int minor; unsigned int hex; - if (!(version_copy = VIR_STRDUP(version))) { - virReportOOMError(); + if (!(version_copy = VIR_STRDUP(version))) return -1; - } len = strlen(version_copy); /* @@ -8210,10 +8111,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) { @@ -8306,7 +8205,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) { @@ -8314,7 +8213,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 = @@ -8329,9 +8228,6 @@ virDomainRedirFilterDefParseXML(const xmlNodePtr node, ctxt->node = save; return def; -no_memory: - virReportOOMError(); - error: VIR_FREE(nodes); virDomainRedirFilterDefFree(def); @@ -8400,10 +8296,8 @@ virDomainDeviceDefParse(virCapsPtr caps, 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; @@ -9005,11 +8899,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, @@ -9068,7 +8958,6 @@ static char *virDomainDefDefaultEmulator(virDomainDefPtr def, virCapsPtr caps) { const char *type; const char *emulator; - char *retemu; type = virDomainVirtTypeToString(def->virtType); if (!type) { @@ -9089,11 +8978,7 @@ static char *virDomainDefDefaultEmulator(virDomainDefPtr def, return NULL; } - retemu = VIR_STRDUP(emulator); - if (!retemu) - virReportOOMError(); - - return retemu; + return VIR_STRDUP(emulator); } static int @@ -9230,10 +9115,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; @@ -9321,10 +9204,8 @@ static int virDomainDefMaybeAddController(virDomainDefPtr def, if (found) return 0; - if (VIR_ALLOC(cont) < 0) { - virReportOOMError(); + if (VIR_ALLOC(cont) < 0) return -1; - } cont->type = type; cont->idx = idx; @@ -9338,7 +9219,6 @@ static int virDomainDefMaybeAddController(virDomainDefPtr def, if (VIR_REALLOC_N(def->controllers, def->ncontrollers+1) < 0) { VIR_FREE(cont); - virReportOOMError(); return -1; } def->controllers[def->ncontrollers] = cont; @@ -9401,10 +9281,8 @@ virDomainDefParseXML(virCapsPtr caps, bool usb_other = 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) @@ -9558,7 +9436,7 @@ virDomainDefParseXML(virCapsPtr caps, 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; @@ -9737,7 +9615,7 @@ virDomainDefParseXML(virCapsPtr caps, 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, @@ -9777,10 +9655,8 @@ virDomainDefParseXML(virCapsPtr caps, * 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, @@ -9790,10 +9666,8 @@ virDomainDefParseXML(virCapsPtr caps, 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); @@ -10133,7 +10007,7 @@ virDomainDefParseXML(virCapsPtr caps, 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], @@ -10152,9 +10026,8 @@ virDomainDefParseXML(virCapsPtr caps, if (!def->os.type) { if (def->os.bootloader) { def->os.type = VIR_STRDUP("xen"); - if (!def->os.type) { - goto no_memory; - } + if (!def->os.type) + goto error; } else { virReportError(VIR_ERR_OS_TYPE, "%s", _("no OS type")); @@ -10169,9 +10042,8 @@ virDomainDefParseXML(virCapsPtr caps, if (STREQ(def->os.type, "linux") && def->virtType == VIR_DOMAIN_VIRT_XEN) { VIR_FREE(def->os.type); - if (!(def->os.type = VIR_STRDUP("xen"))) { - goto no_memory; - } + if (!(def->os.type = VIR_STRDUP("xen"))) + goto error; } if (!virCapabilitiesSupportsGuestOSType(caps, def->os.type)) { @@ -10227,7 +10099,7 @@ virDomainDefParseXML(virCapsPtr caps, virDomainVirtTypeToString(def->virtType)); if (defaultMachine != NULL) { if (!(def->os.machine = VIR_STRDUP(defaultMachine))) { - goto no_memory; + goto error; } } } @@ -10247,7 +10119,7 @@ virDomainDefParseXML(virCapsPtr caps, if (caps->defaultInitPath) { def->os.init = VIR_STRDUP(caps->defaultInitPath); if (!def->os.init) { - goto no_memory; + goto error; } } else { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -10262,7 +10134,7 @@ virDomainDefParseXML(virCapsPtr caps, } 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) { @@ -10271,7 +10143,7 @@ virDomainDefParseXML(virCapsPtr caps, goto error; } if (!(def->os.initargv[i] = VIR_STRDUP((const char*)nodes[i]->children->content))) - goto no_memory; + goto error; } def->os.initargv[n] = NULL; VIR_FREE(nodes); @@ -10292,7 +10164,7 @@ virDomainDefParseXML(virCapsPtr caps, if (virDomainDefParseBootXML(ctxt, def, &bootMapSize) < 0) goto error; if (bootMapSize && !(bootMap = virBitmapNew(bootMapSize))) - goto no_memory; + goto error; } def->emulator = virXPathString("string(./devices/emulator[1])", ctxt); @@ -10307,7 +10179,7 @@ virDomainDefParseXML(virCapsPtr caps, 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(caps, @@ -10329,7 +10201,7 @@ virDomainDefParseXML(virCapsPtr caps, 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], @@ -10377,7 +10249,7 @@ virDomainDefParseXML(virCapsPtr caps, 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) @@ -10392,7 +10264,7 @@ virDomainDefParseXML(virCapsPtr caps, 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); @@ -10408,7 +10280,7 @@ virDomainDefParseXML(virCapsPtr caps, 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(caps, nodes[i], @@ -10423,7 +10295,7 @@ virDomainDefParseXML(virCapsPtr caps, /* <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); @@ -10434,7 +10306,7 @@ virDomainDefParseXML(virCapsPtr caps, 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], @@ -10452,7 +10324,7 @@ virDomainDefParseXML(virCapsPtr caps, 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(caps, @@ -10482,7 +10354,7 @@ virDomainDefParseXML(virCapsPtr caps, 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(caps, @@ -10514,7 +10386,7 @@ virDomainDefParseXML(virCapsPtr caps, goto error; } if (n && VIR_ALLOC_N(def->consoles, n) < 0) - goto no_memory; + goto error; for (i = 0 ; i < n ; i++) { bool create_stub = true; @@ -10567,7 +10439,7 @@ virDomainDefParseXML(virCapsPtr caps, } else { if (VIR_ALLOC_N(def->serials, 1) < 0) { virDomainChrDefFree(chr); - goto no_memory; + goto error; } chr->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL; def->nserials = 1; @@ -10578,7 +10450,7 @@ virDomainDefParseXML(virCapsPtr caps, if (create_stub) { /* And create a stub placeholder */ if (VIR_ALLOC(chr) < 0) - goto no_memory; + goto error; chr->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE; chr->targetType = VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL; } @@ -10594,7 +10466,7 @@ virDomainDefParseXML(virCapsPtr caps, 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(caps, @@ -10637,7 +10509,7 @@ virDomainDefParseXML(virCapsPtr caps, 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, @@ -10677,7 +10549,7 @@ virDomainDefParseXML(virCapsPtr caps, 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, @@ -10693,9 +10565,8 @@ virDomainDefParseXML(virCapsPtr caps, if (def->ngraphics > 0) { virDomainInputDefPtr input; - if (VIR_ALLOC(input) < 0) { - goto no_memory; - } + if (VIR_ALLOC(input) < 0) + goto error; if (STREQ(def->os.type, "hvm")) { input->type = VIR_DOMAIN_INPUT_TYPE_MOUSE; input->bus = VIR_DOMAIN_INPUT_BUS_PS2; @@ -10706,7 +10577,7 @@ virDomainDefParseXML(virCapsPtr caps, if (VIR_REALLOC_N(def->inputs, def->ninputs + 1) < 0) { virDomainInputDefFree(input); - goto no_memory; + goto error; } def->inputs[def->ninputs] = input; def->ninputs++; @@ -10718,7 +10589,7 @@ virDomainDefParseXML(virCapsPtr caps, 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, @@ -10735,7 +10606,7 @@ virDomainDefParseXML(virCapsPtr caps, 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], @@ -10770,7 +10641,7 @@ virDomainDefParseXML(virCapsPtr caps, 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", @@ -10782,7 +10653,7 @@ virDomainDefParseXML(virCapsPtr caps, video->heads = 1; if (VIR_ALLOC_N(def->videos, 1) < 0) { virDomainVideoDefFree(video); - goto no_memory; + goto error; } def->videos[def->nvideos++] = video; } @@ -10792,7 +10663,7 @@ virDomainDefParseXML(virCapsPtr caps, 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; @@ -10857,7 +10728,7 @@ virDomainDefParseXML(virCapsPtr caps, 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; @@ -10886,7 +10757,7 @@ virDomainDefParseXML(virCapsPtr caps, 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) @@ -10909,7 +10780,7 @@ virDomainDefParseXML(virCapsPtr caps, 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], bootMap, @@ -11033,8 +10904,6 @@ virDomainDefParseXML(virCapsPtr caps, return def; -no_memory: - virReportOOMError(); error: VIR_FREE(tmp); VIR_FREE(nodes); @@ -12471,10 +12340,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; } @@ -12482,22 +12349,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; } @@ -12532,10 +12398,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; @@ -12550,10 +12414,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); @@ -15619,9 +15481,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; } @@ -15791,7 +15651,6 @@ virDomainObjListGetInactiveNames(virDomainObjListPtr doms, if (data.oom) { for (i = 0 ; i < data.numnames ; i++) VIR_FREE(data.names[i]); - virReportOOMError(); return -1; } @@ -16226,12 +16085,9 @@ virDomainGraphicsGetListen(virDomainGraphicsDefPtr def, size_t ii, bool force0) def->type == VIR_DOMAIN_GRAPHICS_TYPE_RDP || def->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE) { - if (!def->listens && (ii == 0) && force0) { - if (VIR_ALLOC(def->listens) < 0) - virReportOOMError(); - else + if (!def->listens && (ii == 0) && force0 && + VIR_ALLOC(def->listens) == 0) def->nListens = 1; - } if (!def->listens || (def->nListens <= ii)) return NULL; @@ -16613,10 +16469,8 @@ virDomainObjListExport(virDomainObjListPtr doms, virObjectLock(doms); if (domains) { - if (VIR_ALLOC_N(data.domains, virHashSize(doms->objs) + 1) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(data.domains, virHashSize(doms->objs) + 1) < 0) goto cleanup; - } } virHashForEach(doms->objs, virDomainListPopulate, &data); @@ -16701,7 +16555,6 @@ virDomainDefGenSecurityLabelDef(const char *model) if (VIR_ALLOC(seclabel) < 0 || (model && !(seclabel->model = VIR_STRDUP(model)))) { - virReportOOMError(); virSecurityLabelDefFree(seclabel); seclabel = NULL; } @@ -16716,7 +16569,6 @@ virDomainDiskDefGenSecurityLabelDef(const char *model) if (VIR_ALLOC(seclabel) < 0 || (model && !(seclabel->model = VIR_STRDUP(model)))) { - virReportOOMError(); virSecurityDeviceLabelDefFree(seclabel); seclabel = NULL; } diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c index 1a44df6..419d849 100644 --- a/src/conf/domain_event.c +++ b/src/conf/domain_event.c @@ -416,8 +416,6 @@ virDomainEventCallbackListAddID(virConnectPtr conn, return ret; no_memory: - virReportOOMError(); - if (event) { if (event->dom) VIR_FREE(event->dom->name); @@ -566,10 +564,8 @@ virDomainEventQueueNew(void) { virDomainEventQueuePtr ret; - if (VIR_ALLOC(ret) < 0) { - virReportOOMError(); + if (VIR_ALLOC(ret) < 0) return NULL; - } return ret; } @@ -627,10 +623,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 +633,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,14 +655,11 @@ static virDomainEventPtr virDomainEventNewInternal(int eventID, { virDomainEventPtr event; - if (VIR_ALLOC(event) < 0) { - virReportOOMError(); + if (VIR_ALLOC(event) < 0) return NULL; - } event->eventID = eventID; if (!(event->dom.name = VIR_STRDUP(name))) { - virReportOOMError(); VIR_FREE(event); return NULL; } @@ -930,7 +919,6 @@ virDomainEventBlockJobNew(int id, const char *name, unsigned char *uuid, if (ev) { if (!(ev->data.blockJob.path = VIR_STRDUP(path))) { - virReportOOMError(); virDomainEventFree(ev); return NULL; } @@ -1005,7 +993,6 @@ virDomainEventDiskChangeNew(int id, const char *name, return ev; error: - virReportOOMError(); virDomainEventFree(ev); return NULL; } @@ -1052,7 +1039,6 @@ virDomainEventTrayChangeNew(int id, const char *name, return ev; error: - virReportOOMError(); virDomainEventFree(ev); return NULL; } @@ -1194,10 +1180,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 fd3c292..47a06fe 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 f30ac70..56baa6e 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 13ba8c6..b038dc0 100644 --- a/src/conf/netdev_vlan_conf.c +++ b/src/conf/netdev_vlan_conf.c @@ -49,10 +49,8 @@ virNetDevVlanParse(xmlNodePtr node, xmlXPathContextPtr ctxt, virNetDevVlanPtr de goto error; } - if (VIR_ALLOC_N(def->tag, nTags) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(def->tag, nTags) < 0) goto error; - } for (ii = 0; ii < nTags; ii++) { unsigned long id; diff --git a/src/conf/netdev_vport_profile_conf.c b/src/conf/netdev_vport_profile_conf.c index 32bcef9..cca6bc3 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 2d2c523..ee686d2 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -327,15 +327,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")); @@ -345,10 +341,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)); @@ -803,10 +797,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; @@ -816,10 +808,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) { @@ -890,10 +880,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, @@ -1069,10 +1057,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], @@ -1091,10 +1077,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, @@ -1113,10 +1097,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], @@ -1542,10 +1524,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; @@ -1589,10 +1569,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"))) { @@ -1636,10 +1614,8 @@ virNetworkForwardDefParseXML(const char *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) { @@ -1686,10 +1662,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); @@ -1793,10 +1767,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], @@ -1816,10 +1788,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], @@ -2687,11 +2657,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; } @@ -2725,10 +2691,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; } @@ -3867,12 +3831,8 @@ virNetworkList(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 e41bdc3..4e83cd0 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -175,10 +175,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, @@ -193,7 +191,6 @@ virNodeDeviceObjPtr virNodeDeviceAssignDef(virNodeDeviceObjListPtr devs, device->def = NULL; virNodeDeviceObjUnlock(device); virNodeDeviceObjFree(device); - virReportOOMError(); return NULL; } devs->objs[devs->count++] = device; @@ -1073,10 +1070,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) { @@ -1152,10 +1147,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) { @@ -1168,10 +1161,8 @@ virNodeDeviceDefParseXML(xmlXPathContextPtr ctxt, } else { def->name = VIR_STRDUP("new device"); - if (!def->name) { - virReportOOMError(); + if (!def->name) goto error; - } } /* Extract device parent, if any */ @@ -1309,7 +1300,6 @@ virNodeDeviceGetWWNs(virNodeDeviceDefPtr def, VIR_FREE(*wwnn); VIR_FREE(*wwpn); ret = -1; - virReportOOMError(); } return ret; @@ -1513,12 +1503,8 @@ virNodeDeviceList(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 291b5a4..c859ad6 100644 --- a/src/conf/nwfilter_conf.c +++ b/src/conf/nwfilter_conf.c @@ -379,7 +379,6 @@ virNWFilterRuleDefAddVar(virNWFilterRuleDefPtr nwf, } if (VIR_EXPAND_N(nwf->varAccess, nwf->nVarAccess, 1) < 0) { - virReportOOMError(); virNWFilterVarAccessFree(varAccess); return -1; } @@ -396,10 +395,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; - } nwf->strings[nwf->nstrings] = strndup(string, maxstrlen); @@ -2042,10 +2039,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) { @@ -2306,10 +2301,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"); @@ -2502,10 +2495,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) { @@ -2557,10 +2548,8 @@ virNWFilterDefParseXML(xmlXPathContextPtr ctxt) { } else { ret->chainsuffix = VIR_STRDUP(virNWFilterChainSuffixTypeToString( VIR_NWFILTER_CHAINSUFFIX_ROOT)); - if (ret->chainsuffix == NULL) { - virReportOOMError(); + if (ret->chainsuffix == NULL) goto cleanup; - } } uuid = virXPathString("string(./uuid)", ctxt); @@ -2583,10 +2572,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")) @@ -2597,7 +2584,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; @@ -3038,10 +3024,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, @@ -3057,7 +3041,6 @@ virNWFilterObjAssignDef(virConnectPtr conn, nwfilter->def = NULL; virNWFilterObjUnlock(nwfilter); virNWFilterObjFree(nwfilter); - virReportOOMError(); return NULL; } nwfilters->objs[nwfilters->count++] = nwfilter; @@ -3095,7 +3078,6 @@ virNWFilterObjLoad(virConnectPtr conn, VIR_FREE(nwfilter->configFile); /* for driver reload */ nwfilter->configFile = VIR_STRDUP(path); if (nwfilter->configFile == NULL) { - virReportOOMError(); virNWFilterDefFree(def); return NULL; } @@ -3491,11 +3473,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 fc2cd45..9d40f7a 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) { @@ -103,7 +101,6 @@ virNWFilterVarValueCopy(const virNWFilterVarValuePtr val) return res; err_exit: - virReportOOMError(); virNWFilterVarValueFree(res); return NULL; } @@ -119,10 +116,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; @@ -135,10 +130,8 @@ virNWFilterVarValueCreateSimpleCopyValue(const char *value) { char *val = VIR_STRDUP(value); - if (!val) { - virReportOOMError(); + if (!val) return NULL; - } return virNWFilterVarValueCreateSimple(val); } @@ -233,7 +226,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; @@ -245,10 +237,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; @@ -389,10 +379,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; @@ -483,10 +471,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; @@ -655,10 +641,8 @@ virNWFilterHashTablePut(virNWFilterHashTablePtr table, if (!virHashLookup(table->hashTable, name)) { if (copyName) { name = VIR_STRDUP(name); - if (!name) { - virReportOOMError(); + if (!name) return -1; - } if (VIR_REALLOC_N(table->names, table->nNames + 1) < 0) { VIR_FREE(name); @@ -711,10 +695,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); @@ -762,7 +744,6 @@ addToTable(void *payload, const void *name, void *data) val = virNWFilterVarValueCopy((virNWFilterVarValuePtr)payload); if (!val) { - virReportOOMError(); atts->errOccurred = 1; return; } @@ -844,10 +825,8 @@ virNWFilterParseParamAttributes(xmlNodePtr cur) virNWFilterVarValuePtr value; virNWFilterHashTablePtr table = virNWFilterHashTableCreate(0); - if (!table) { - virReportOOMError(); + if (!table) return NULL; - } cur = cur->children; @@ -997,10 +976,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 f7658e7..7eb84d4 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 ba878f9..a9d7674 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++) { @@ -463,20 +455,16 @@ virDomainSnapshotAlignDisks(virDomainSnapshotDefPtr def, } if (STRNEQ(disk->name, def->dom->disks[idx]->dst)) { VIR_FREE(disk->name); - if (!(disk->name = VIR_STRDUP(def->dom->disks[idx]->dst))) { - virReportOOMError(); + if (!(disk->name = VIR_STRDUP(def->dom->disks[idx]->dst))) goto cleanup; - } } } /* 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; @@ -485,10 +473,8 @@ virDomainSnapshotAlignDisks(virDomainSnapshotDefPtr def, if (inuse) continue; disk = &def->disks[ndisks++]; - if (!(disk->name = VIR_STRDUP(def->dom->disks[i]->dst))) { - virReportOOMError(); + if (!(disk->name = VIR_STRDUP(def->dom->disks[i]->dst))) goto cleanup; - } disk->index = i; disk->snapshot = def->dom->disks[i]->snapshot; if (!disk->snapshot) @@ -538,10 +524,8 @@ virDomainSnapshotAlignDisks(virDomainSnapshotDefPtr def, (int) (tmp - original), original, def->name)); } - if (!disk->file) { - virReportOOMError(); + if (!disk->file) goto cleanup; - } } } @@ -643,10 +627,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); @@ -702,10 +684,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); @@ -770,7 +750,6 @@ static void virDomainSnapshotObjListCopyNames(void *payload, if (data->names && data->count < data->maxnames && !(data->names[data->count] = VIR_STRDUP(obj->def->name))) { data->error = true; - virReportOOMError(); return; } data->count++; @@ -1031,10 +1010,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 36eb2aa..adecc85 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -526,10 +526,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"); @@ -562,7 +560,6 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt, if (nsource > 0) { if (VIR_ALLOC_N(source->devices, nsource) < 0) { VIR_FREE(nodeset); - virReportOOMError(); goto cleanup; } @@ -635,10 +632,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", @@ -739,10 +734,8 @@ virStoragePoolDefParseXML(xmlXPathContextPtr ctxt) { char *uuid = NULL; char *tmppath; - if (VIR_ALLOC(ret) < 0) { - virReportOOMError(); + if (VIR_ALLOC(ret) < 0) return NULL; - } type = virXPathString("string(./@type)", ctxt); if ((ret->type = virStoragePoolTypeFromString((const char *)type)) < 0) { @@ -811,10 +804,8 @@ virStoragePoolDefParseXML(xmlXPathContextPtr ctxt) { if (ret->source.name == NULL) { /* source name defaults to pool name */ ret->source.name = VIR_STRDUP(ret->name); - if (ret->source.name == NULL) { - virReportOOMError(); + if (ret->source.name == NULL) goto cleanup; - } } } @@ -1119,10 +1110,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) { @@ -1522,10 +1511,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, @@ -1541,7 +1528,6 @@ virStoragePoolObjAssignDef(virStoragePoolObjListPtr pools, pool->def = NULL; virStoragePoolObjUnlock(pool); virStoragePoolObjFree(pool); - virReportOOMError(); return NULL; } pools->objs[pools->count++] = pool; @@ -1577,14 +1563,12 @@ virStoragePoolObjLoad(virStoragePoolObjListPtr pools, VIR_FREE(pool->configFile); /* for driver reload */ pool->configFile = VIR_STRDUP(path); if (pool->configFile == NULL) { - virReportOOMError(); virStoragePoolDefFree(def); return NULL; } VIR_FREE(pool->autostartLink); /* for driver reload */ pool->autostartLink = VIR_STRDUP(autostartLink); if (pool->autostartLink == NULL) { - virReportOOMError(); virStoragePoolDefFree(def); return NULL; } @@ -1712,10 +1696,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)); @@ -1980,12 +1962,8 @@ virStoragePoolList(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 20fcdb4..737aef3 100644 --- a/src/conf/virchrdev.c +++ b/src/conf/virchrdev.c @@ -73,10 +73,8 @@ static char *virChrdevLockFilePath(const char *dev) char *filename; char *p; - if (!(devCopy = VIR_STRDUP(dev))) { - virReportOOMError(); + if (!(devCopy = VIR_STRDUP(dev))) goto cleanup; - } /* skip the leading "/dev/" */ filename = STRSKIP(devCopy, "/dev"); @@ -392,19 +390,15 @@ 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; cbdata->devs = devs; - if (!(cbdata->path = VIR_STRDUP(path))) { - virReportOOMError(); + if (!(cbdata->path = VIR_STRDUP(path))) goto error; - } /* open the character device */ switch (source->type) { diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c index 6beab55..b8651da 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..446a7da 100644 --- a/src/cpu/cpu_arm.c +++ b/src/cpu/cpu_arm.c @@ -35,10 +35,8 @@ ArmNodeData(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_generic.c b/src/cpu/cpu_generic.c index a3d3b08..10e0d30 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++) { @@ -142,7 +140,7 @@ genericBaseline(virCPUDefPtr *cpus, if (VIR_ALLOC(cpu) < 0 || !(cpu->model = VIR_STRDUP(cpus[0]->model)) || VIR_ALLOC_N(features, cpus[0]->nfeatures) < 0) - goto no_memory; + goto error; cpu->arch = cpus[0]->arch; cpu->type = VIR_CPU_TYPE_HOST; @@ -170,7 +168,7 @@ genericBaseline(virCPUDefPtr *cpus, } if (!(hash = genericHashFeatures(cpus[i]))) - goto no_memory; + goto error; for (j = 0; j < nfeatures; j++) { if (features[j].name && @@ -184,7 +182,7 @@ genericBaseline(virCPUDefPtr *cpus, } if (VIR_ALLOC_N(cpu->features, count) < 0) - goto no_memory; + goto error; cpu->nfeatures = count; j = 0; @@ -193,7 +191,7 @@ genericBaseline(virCPUDefPtr *cpus, continue; if (!(cpu->features[j++].name = VIR_STRDUP(features[i].name))) - goto no_memory; + goto error; } cleanup: @@ -201,8 +199,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 0e01d93..aa052b9 100644 --- a/src/cpu/cpu_powerpc.c +++ b/src/cpu/cpu_powerpc.c @@ -206,7 +206,7 @@ ppcVendorLoad(xmlXPathContextPtr ctxt, int ret = -1; if (VIR_ALLOC(vendor) < 0) - goto no_memory; + return ret; vendor->name = virXPathString("string(@name)", ctxt); if (!vendor->name) { @@ -240,9 +240,6 @@ out: VIR_FREE(string); return ret; -no_memory: - virReportOOMError(); - ignore: ppcVendorFree(vendor); goto out; @@ -258,7 +255,7 @@ ppcModelLoad(xmlXPathContextPtr ctxt, int ret = -1; if (!(model = ppcModelNew())) - goto no_memory; + return ret; model->name = virXPathString("string(@name)", ctxt); if (model->name == NULL) { @@ -303,9 +300,6 @@ out: VIR_FREE(nodes); return ret; -no_memory: - virReportOOMError(); - ignore: ppcModelFree(model); goto out; @@ -356,10 +350,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; @@ -406,7 +398,6 @@ ppcModelFromCPU(const virCPUDefPtr cpu, return model; no_memory: - virReportOOMError(); ppcModelFree(model); return NULL; @@ -474,10 +465,8 @@ PowerPCDecode(virCPUDefPtr cpu, goto next; } - if (VIR_ALLOC(cpuCandidate) < 0) { - virReportOOMError(); + if (VIR_ALLOC(cpuCandidate) < 0) goto out; - } cpuCandidate->model = VIR_STRDUP(candidate->name); cpuCandidate->vendor = VIR_STRDUP(candidate->vendor->name); @@ -550,10 +539,8 @@ PowerPCNodeData(void) { union cpuData *data; - if (VIR_ALLOC(data) < 0) { - virReportOOMError(); + if (VIR_ALLOC(data) < 0) return NULL; - } #if defined(__powerpc__) || \ defined(__powerpc64__) @@ -590,7 +577,7 @@ PowerPCBaseline(virCPUDefPtr *cpus, } if (VIR_ALLOC(cpu) < 0) - goto no_memory; + goto error; cpu->arch = cpus[0]->arch; cpu->type = VIR_CPU_TYPE_GUEST; @@ -617,8 +604,6 @@ cleanup: ppcMapFree(map); return cpu; -no_memory: - virReportOOMError(); error: ppcModelFree(model); virCPUDefFree(cpu); 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 84affcf..fe1cae1 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -270,7 +270,6 @@ x86DataExpand(union cpuData *data, return 0; no_memory: - virReportOOMError(); return -1; } @@ -452,11 +451,11 @@ x86DataToCPU(const union cpuData *data, !(cpu->model = VIR_STRDUP(model->name)) || !(copy = x86DataCopy(data)) || !(modelData = x86DataCopy(model->data))) - goto no_memory; + goto error; if ((vendor = x86DataToVendor(copy, map)) && !(cpu->vendor = VIR_STRDUP(vendor->name))) - goto no_memory; + goto error; x86DataSubtract(copy, modelData); x86DataSubtract(modelData, data); @@ -473,8 +472,6 @@ cleanup: x86DataFree(copy); return cpu; -no_memory: - virReportOOMError(); error: virCPUDefFree(cpu); cpu = NULL; @@ -565,7 +562,6 @@ out: return ret; no_memory: - virReportOOMError(); ret = -1; ignore: x86VendorFree(vendor); @@ -723,7 +719,6 @@ out: return ret; no_memory: - virReportOOMError(); ret = -1; ignore: @@ -813,9 +808,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 +829,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; @@ -1034,7 +1026,6 @@ out: return ret; no_memory: - virReportOOMError(); ret = -1; ignore: @@ -1098,10 +1089,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; @@ -1126,11 +1115,11 @@ error: do { \ char *flagsStr = NULL; \ if (!(flagsStr = x86FeatureNames(map, ", ", (CPU_DEF)))) \ - goto no_memory; \ + 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 +1162,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 +1176,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 +1209,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 +1230,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 +1258,6 @@ out: return ret; -no_memory: - virReportOOMError(); - error: ret = VIR_CPU_COMPARE_ERROR; goto out; @@ -1489,10 +1475,8 @@ x86Encode(const virCPUDefPtr cpu, if (v && (VIR_ALLOC(data_vendor) < 0 || - x86DataAddCpuid(data_vendor, &v->cpuid) < 0)) { - virReportOOMError(); + x86DataAddCpuid(data_vendor, &v->cpuid) < 0)) goto error; - } } if (forced) @@ -1571,10 +1555,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; @@ -1592,10 +1574,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; @@ -1636,7 +1616,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; @@ -1698,7 +1678,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; @@ -1714,8 +1694,6 @@ cleanup: return cpu; -no_memory: - virReportOOMError(); error: x86ModelFree(model); virCPUDefFree(cpu); diff --git a/src/datatypes.c b/src/datatypes.c index 04bf366..0967c35 100644 --- a/src/datatypes.c +++ b/src/datatypes.c @@ -199,7 +199,6 @@ virGetDomain(virConnectPtr conn, const char *name, const unsigned char *uuid) return ret; no_memory: - virReportOOMError(); virObjectUnref(ret); return NULL; } @@ -270,7 +269,6 @@ virGetNetwork(virConnectPtr conn, const char *name, const unsigned char *uuid) return ret; no_memory: - virReportOOMError(); virObjectUnref(ret); return NULL; } @@ -346,7 +344,6 @@ virGetInterface(virConnectPtr conn, const char *name, const char *mac) return ret; no_memory: - virReportOOMError(); virObjectUnref(ret); return NULL; } @@ -423,7 +420,6 @@ virGetStoragePool(virConnectPtr conn, const char *name, return ret; no_memory: - virReportOOMError(); virObjectUnref(ret); return NULL; } @@ -510,7 +506,6 @@ virGetStorageVol(virConnectPtr conn, const char *pool, const char *name, return ret; no_memory: - virReportOOMError(); virObjectUnref(ret); return NULL; } @@ -580,7 +575,6 @@ virGetNodeDevice(virConnectPtr conn, const char *name) ret->conn = virObjectRef(conn); return ret; no_memory: - virReportOOMError(); virObjectUnref(ret); return NULL; } @@ -651,7 +645,6 @@ virGetSecret(virConnectPtr conn, const unsigned char *uuid, return ret; no_memory: - virReportOOMError(); virObjectUnref(ret); return NULL; } @@ -748,7 +741,6 @@ virGetNWFilter(virConnectPtr conn, const char *name, return ret; no_memory: - virReportOOMError(); virObjectUnref(ret); return NULL; } @@ -802,7 +794,6 @@ virGetDomainSnapshot(virDomainPtr domain, const char *name) return ret; no_memory: - virReportOOMError(); virObjectUnref(ret); return NULL; } diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index cfb3c6b..d0c9c6e 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -144,10 +144,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 || @@ -197,10 +195,8 @@ esxParseVMXFileName(const char *fileName, void *opaque) } if (virAsprintf(&result, "[%s] %s", datastoreName, - strippedFileName) < 0) { - virReportOOMError(); + strippedFileName) < 0) goto cleanup; - } break; } @@ -237,10 +233,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 */ @@ -592,10 +586,8 @@ esxCapsInit(esxPrivate *priv) caps = virCapabilitiesNew(VIR_ARCH_I686, 1, 1); } - if (caps == NULL) { - virReportOOMError(); + if (caps == NULL) return NULL; - } virCapabilitiesSetMacPrefix(caps, (unsigned char[]){ 0x00, 0x0c, 0x29 }); virCapabilitiesAddHostMigrateTransport(caps, "vpxmigr"); @@ -680,10 +672,8 @@ esxConnectToHost(esxPrivate *priv, if (conn->uri->user != NULL) { username = VIR_STRDUP(conn->uri->user); - if (username == NULL) { - virReportOOMError(); + if (username == NULL) goto cleanup; - } } else { username = virAuthGetUsername(conn, auth, "esx", "root", conn->uri->server); @@ -707,10 +697,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, @@ -763,10 +751,8 @@ esxConnectToHost(esxPrivate *priv, if (*vCenterIpAddress != NULL) { *vCenterIpAddress = VIR_STRDUP(*vCenterIpAddress); - if (*vCenterIpAddress == NULL) { - virReportOOMError(); + if (*vCenterIpAddress == NULL) goto cleanup; - } } result = 0; @@ -812,10 +798,8 @@ esxConnectToVCenter(esxPrivate *priv, if (conn->uri->user != NULL) { username = VIR_STRDUP(conn->uri->user); - if (username == NULL) { - virReportOOMError(); + if (username == NULL) goto cleanup; - } } else { username = virAuthGetUsername(conn, auth, "esx", "administrator", hostname); @@ -839,10 +823,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, @@ -994,10 +976,8 @@ esxOpen(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; @@ -1289,15 +1269,11 @@ esxGetHostname(virConnectPtr conn) if (domainName == NULL || strlen(domainName) < 1) { complete = VIR_STRDUP(hostName); - if (complete == NULL) { - virReportOOMError(); + if (complete == NULL) goto cleanup; - } } else { - if (virAsprintf(&complete, "%s.%s", hostName, domainName) < 0) { - virReportOOMError(); + if (virAsprintf(&complete, "%s.%s", hostName, domainName) < 0) goto cleanup; - } } cleanup: @@ -2025,14 +2001,7 @@ esxDomainDestroy(virDomainPtr dom) static char * esxDomainGetOSType(virDomainPtr domain ATTRIBUTE_UNUSED) { - char *osType = VIR_STRDUP("hvm"); - - if (osType == NULL) { - virReportOOMError(); - return NULL; - } - - return osType; + return VIR_STRDUP("hvm"); } @@ -2768,16 +2737,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; @@ -3242,16 +3207,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, @@ -3588,10 +3549,8 @@ esxDomainGetSchedulerType(virDomainPtr domain ATTRIBUTE_UNUSED, int *nparams) { char *type = VIR_STRDUP("allocation"); - if (type == NULL) { - virReportOOMError(); + if (type == NULL) return NULL; - } if (nparams != NULL) { *nparams = 3; /* reservation, limit, shares */ @@ -3891,10 +3850,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; @@ -5051,7 +5008,7 @@ esxListAllDomains(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; @@ -5105,7 +5062,7 @@ esxListAllDomains(virConnectPtr conn, if (domains) { if (VIR_ALLOC_N(doms, 1) < 0) - goto no_memory; + goto cleanup; ndoms = 1; } @@ -5198,7 +5155,7 @@ esxListAllDomains(virConnectPtr conn, } if (VIR_RESIZE_N(doms, ndoms, count, 2) < 0) - goto no_memory; + goto cleanup; if (!(dom = virGetDomain(conn, name, uuid))) goto cleanup; @@ -5234,10 +5191,6 @@ cleanup: esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotTreeList); return ret; - -no_memory: - virReportOOMError(); - goto cleanup; } #undef MATCH diff --git a/src/esx/esx_interface_driver.c b/src/esx/esx_interface_driver.c index b8b318c..8c74045 100644 --- a/src/esx/esx_interface_driver.c +++ b/src/esx/esx_interface_driver.c @@ -114,10 +114,8 @@ esxListInterfaces(virConnectPtr conn, char **const names, int maxnames) physicalNic = physicalNic->_next) { names[count] = VIR_STRDUP(physicalNic->device); - if (names[count] == NULL) { - virReportOOMError(); + if (names[count] == NULL) goto cleanup; - } ++count; } diff --git a/src/esx/esx_network_driver.c b/src/esx/esx_network_driver.c index 45d1798..0f16a6c 100644 --- a/src/esx/esx_network_driver.c +++ b/src/esx/esx_network_driver.c @@ -124,10 +124,8 @@ esxListNetworks(virConnectPtr conn, char **const names, int maxnames) hostVirtualSwitch = hostVirtualSwitch->_next) { names[count] = VIR_STRDUP(hostVirtualSwitch->name); - if (names[count] == NULL) { - virReportOOMError(); + if (names[count] == NULL) goto cleanup; - } ++count; } @@ -647,10 +645,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 */ @@ -699,10 +695,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, @@ -715,10 +709,8 @@ esxNetworkGetXMLDesc(virNetworkPtr network_, unsigned int flags) def->name = VIR_STRDUP(hostVirtualSwitch->name); - if (def->name == NULL) { - virReportOOMError(); + if (def->name == NULL) goto cleanup; - } def->forward.type = VIR_NETWORK_FORWARD_NONE; @@ -733,10 +725,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) { @@ -755,10 +745,8 @@ esxNetworkGetXMLDesc(virNetworkPtr network_, unsigned int flags) def->forward.ifs[def->forward.nifs].device.dev = VIR_STRDUP(physicalNic->device); - if (def->forward.ifs[def->forward.nifs].device.dev == NULL) { - virReportOOMError(); + if (def->forward.ifs[def->forward.nifs].device.dev == NULL) goto cleanup; - } ++def->forward.nifs; @@ -785,10 +773,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 || @@ -825,10 +811,8 @@ esxNetworkGetXMLDesc(virNetworkPtr network_, unsigned int flags) if (STREQ(networkName->value, hostPortGroup->spec->name)) { def->portGroups[def->nPortGroups].name = VIR_STRDUP(networkName->value); - if (def->portGroups[def->nPortGroups].name == NULL) { - virReportOOMError(); + if (def->portGroups[def->nPortGroups].name == NULL) goto cleanup; - } if (hostPortGroup->spec->policy != NULL) { if (esxShapingPolicyToBandwidth diff --git a/src/esx/esx_storage_backend_iscsi.c b/src/esx/esx_storage_backend_iscsi.c index fca7ccd..5b80746 100644 --- a/src/esx/esx_storage_backend_iscsi.c +++ b/src/esx/esx_storage_backend_iscsi.c @@ -132,10 +132,8 @@ esxStorageBackendISCSIListPools(virConnectPtr conn, char **const names, target != NULL && count < maxnames; target = target->_next) { names[count] = VIR_STRDUP(target->iScsiName); - if (names[count] == NULL) { - virReportOOMError(); + if (names[count] == NULL) goto cleanup; - } ++count; } @@ -337,10 +335,8 @@ esxStorageBackendISCSIPoolGetXMLDesc(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; @@ -421,10 +417,8 @@ esxStorageBackendISCSIPoolListVolumes(virStoragePoolPtr pool, char **const names if (STREQ(hostScsiTopologyLun->scsiLun, scsiLun->key)) { names[count] = VIR_STRDUP(scsiLun->deviceName); - if (names[count] == NULL) { - virReportOOMError(); + if (names[count] == NULL) goto cleanup; - } ++count; } @@ -739,14 +733,7 @@ esxStorageBackendISCSIVolumeWipe(virStorageVolPtr volume ATTRIBUTE_UNUSED, static char * esxStorageBackendISCSIVolumeGetPath(virStorageVolPtr volume) { - char *path = VIR_STRDUP(volume->name); - - if (path == NULL) { - virReportOOMError(); - return NULL; - } - - return path; + return VIR_STRDUP(volume->name); } diff --git a/src/esx/esx_storage_backend_vmfs.c b/src/esx/esx_storage_backend_vmfs.c index 969a74d..e21e368 100644 --- a/src/esx/esx_storage_backend_vmfs.c +++ b/src/esx/esx_storage_backend_vmfs.c @@ -169,10 +169,8 @@ esxStorageBackendVMFSListPools(virConnectPtr conn, char **const names, names[count] = VIR_STRDUP(dynamicProperty->val->string); - if (names[count] == NULL) { - virReportOOMError(); + if (names[count] == NULL) goto cleanup; - } ++count; break; @@ -486,10 +484,8 @@ esxStorageBackendVMFSPoolGetXMLDesc(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; @@ -615,15 +611,11 @@ esxStorageBackendVMFSPoolListVolumes(virStoragePoolPtr pool, char **const names, if (length < 1) { names[count] = VIR_STRDUP(fileInfo->path); - if (names[count] == NULL) { - virReportOOMError(); + if (names[count] == NULL) goto cleanup; - } } else if (virAsprintf(&names[count], "%s/%s", directoryAndFileName, - fileInfo->path) < 0) { - virReportOOMError(); + fileInfo->path) < 0) goto cleanup; - } ++count; } @@ -657,10 +649,8 @@ esxStorageBackendVMFSVolumeLookupByName(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) { @@ -791,22 +781,16 @@ esxStorageBackendVMFSVolumeLookupByKey(virConnectPtr conn, const char *key) if (length < 1) { if (virAsprintf(&volumeName, "%s", - fileInfo->path) < 0) { - virReportOOMError(); + fileInfo->path) < 0) 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 */ @@ -916,10 +900,8 @@ esxStorageBackendVMFSVolumeCreateXML(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 */ @@ -943,16 +925,12 @@ esxStorageBackendVMFSVolumeCreateXML(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 @@ -1024,10 +1002,8 @@ esxStorageBackendVMFSVolumeCreateXML(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, @@ -1116,10 +1092,8 @@ esxStorageBackendVMFSVolumeCreateXMLFrom(virStoragePoolPtr pool, } if (virAsprintf(&sourceDatastorePath, "[%s] %s", sourceVolume->pool, - sourceVolume->name) < 0) { - virReportOOMError(); + sourceVolume->name) < 0) goto cleanup; - } /* Parse config */ def = virStorageVolDefParseString(&poolDef, xmldesc); @@ -1152,10 +1126,8 @@ esxStorageBackendVMFSVolumeCreateXMLFrom(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 */ @@ -1179,16 +1151,12 @@ esxStorageBackendVMFSVolumeCreateXMLFrom(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 @@ -1226,10 +1194,8 @@ esxStorageBackendVMFSVolumeCreateXMLFrom(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, @@ -1289,10 +1255,8 @@ esxStorageBackendVMFSVolumeDelete(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, @@ -1334,10 +1298,8 @@ esxStorageBackendVMFSVolumeWipe(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, @@ -1379,10 +1341,8 @@ esxStorageBackendVMFSVolumeGetInfo(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, @@ -1439,10 +1399,8 @@ esxStorageBackendVMFSVolumeGetXMLDesc(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, @@ -1501,13 +1459,9 @@ esxStorageBackendVMFSVolumeGetXMLDesc(virStorageVolPtr volume, static char * esxStorageBackendVMFSVolumeGetPath(virStorageVolPtr volume) { - char *path; - - if (virAsprintf(&path, "[%s] %s", volume->pool, volume->name) < 0) { - virReportOOMError(); - return NULL; - } + char *path = 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 2f00d94..25a63be 100644 --- a/src/esx/esx_util.c +++ b/src/esx/esx_util.c @@ -53,10 +53,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]; @@ -66,10 +64,8 @@ esxUtil_ParseUri(esxUtil_ParsedUri **parsedUri, virURIPtr uri) (*parsedUri)->transport = VIR_STRDUP(queryParam->value); - if ((*parsedUri)->transport == NULL) { - virReportOOMError(); + if ((*parsedUri)->transport == NULL) goto cleanup; - } if (STRNEQ((*parsedUri)->transport, "http") && STRNEQ((*parsedUri)->transport, "https")) { @@ -84,10 +80,8 @@ esxUtil_ParseUri(esxUtil_ParsedUri **parsedUri, virURIPtr uri) (*parsedUri)->vCenter = VIR_STRDUP(queryParam->value); - if ((*parsedUri)->vCenter == NULL) { - virReportOOMError(); + if ((*parsedUri)->vCenter == NULL) goto cleanup; - } } else if (STRCASEEQ(queryParam->name, "no_verify")) { if (virStrToLong_i(queryParam->value, NULL, 10, &noVerify) < 0 || (noVerify != 0 && noVerify != 1)) { @@ -138,10 +132,8 @@ esxUtil_ParseUri(esxUtil_ParsedUri **parsedUri, virURIPtr uri) (*parsedUri)->proxy_hostname = VIR_STRDUP(tmp); - if ((*parsedUri)->proxy_hostname == NULL) { - virReportOOMError(); + if ((*parsedUri)->proxy_hostname == NULL) goto cleanup; - } if ((tmp = strchr((*parsedUri)->proxy_hostname, ':')) != NULL) { if (tmp == (*parsedUri)->proxy_hostname) { @@ -173,19 +165,15 @@ esxUtil_ParseUri(esxUtil_ParsedUri **parsedUri, virURIPtr uri) if (uri->path != NULL) { (*parsedUri)->path = VIR_STRDUP(uri->path); - if ((*parsedUri)->path == NULL) { - virReportOOMError(); + if ((*parsedUri)->path == NULL) goto cleanup; - } } if ((*parsedUri)->transport == NULL) { (*parsedUri)->transport = VIR_STRDUP("https"); - if ((*parsedUri)->transport == NULL) { - virReportOOMError(); + if ((*parsedUri)->transport == NULL) goto cleanup; - } } result = 0; @@ -497,10 +485,8 @@ esxUtil_EscapeDatastoreItem(const char *string) char *escaped1; char *escaped2 = NULL; - if (replaced == NULL) { - virReportOOMError(); + if (replaced == NULL) return NULL; - } esxUtil_ReplaceSpecialWindowsPathChars(replaced); diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c index 042bbbc..98701b2 100644 --- a/src/esx/esx_vi.c +++ b/src/esx/esx_vi.c @@ -391,15 +391,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); @@ -807,10 +803,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", @@ -948,10 +942,8 @@ esxVI_Context_LookupManagedObjects(esxVI_Context *ctx) ctx->datacenterPath = VIR_STRDUP(ctx->datacenter->name); - if (ctx->datacenterPath == NULL) { - virReportOOMError(); + if (ctx->datacenterPath == NULL) return -1; - } /* Lookup (Cluster)ComputeResource */ if (esxVI_LookupComputeResource(ctx, NULL, ctx->datacenter->hostFolder, @@ -968,10 +960,8 @@ esxVI_Context_LookupManagedObjects(esxVI_Context *ctx) ctx->computeResourcePath = VIR_STRDUP(ctx->computeResource->name); - if (ctx->computeResourcePath == NULL) { - virReportOOMError(); + if (ctx->computeResourcePath == NULL) return -1; - } /* Lookup HostSystem */ if (esxVI_LookupHostSystem(ctx, NULL, ctx->computeResource->_reference, @@ -982,10 +972,8 @@ esxVI_Context_LookupManagedObjects(esxVI_Context *ctx) ctx->hostSystemName = VIR_STRDUP(ctx->hostSystem->name); - if (ctx->hostSystemName == NULL) { - virReportOOMError(); + if (ctx->hostSystemName == NULL) return -1; - } return 0; } @@ -1004,10 +992,8 @@ esxVI_Context_LookupManagedObjectsByPath(esxVI_Context *ctx, const char *path) tmp = VIR_STRDUP(path); - if (tmp == NULL) { - virReportOOMError(); + if (tmp == NULL) goto cleanup; - } /* Lookup Datacenter */ item = strtok_r(tmp, "/", &saveptr); @@ -1161,10 +1147,8 @@ esxVI_Context_LookupManagedObjectsByPath(esxVI_Context *ctx, const char *path) ctx->hostSystemName = VIR_STRDUP(previousItem); - if (ctx->hostSystemName == NULL) { - virReportOOMError(); + if (ctx->hostSystemName == NULL) goto cleanup; - } if (esxVI_LookupHostSystem(ctx, ctx->hostSystemName, ctx->computeResource->_reference, NULL, @@ -1334,10 +1318,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); @@ -2498,10 +2480,8 @@ esxVI_GetVirtualMachineIdentity(esxVI_ObjectContent *virtualMachine, *name = VIR_STRDUP(dynamicProperty->val->string); - if (*name == NULL) { - virReportOOMError(); + if (*name == NULL) goto failure; - } if (virVMXUnescapeHexPercent(*name) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -2611,10 +2591,8 @@ esxVI_GetSnapshotTreeNames(esxVI_VirtualMachineSnapshotTree *snapshotTreeList, if (!(leaves && snapshotTree->childSnapshotList)) { names[count] = VIR_STRDUP(snapshotTree->name); - if (names[count] == NULL) { - virReportOOMError(); + if (names[count] == NULL) goto failure; - } count++; } @@ -3507,20 +3485,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 (esxVI_String_DeepCopyValue(&fileName, directoryAndFileName) < 0) { goto cleanup; } } else { if (virAsprintf(&datastorePathWithoutFileName, "[%s] %s", - datastoreName, directoryName) < 0) { - virReportOOMError(); + datastoreName, directoryName) < 0) goto cleanup; - } length = strlen(directoryName); @@ -3743,10 +3717,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, @@ -3816,10 +3788,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; @@ -4388,10 +4358,8 @@ esxVI_WaitForTaskCompletion(esxVI_Context *ctx, version = VIR_STRDUP(""); - if (version == NULL) { - virReportOOMError(); + if (version == NULL) return -1; - } if (esxVI_ObjectSpec_Alloc(&objectSpec) < 0) { goto cleanup; @@ -4469,10 +4437,8 @@ esxVI_WaitForTaskCompletion(esxVI_Context *ctx, VIR_FREE(version); version = VIR_STRDUP(updateSet->version); - if (version == NULL) { - virReportOOMError(); + if (version == NULL) goto cleanup; - } if (updateSet->filterSet == NULL) { continue; @@ -4523,24 +4489,18 @@ esxVI_WaitForTaskCompletion(esxVI_Context *ctx, if (taskInfo->error == NULL) { *errorMessage = VIR_STRDUP(_("Unknown error")); - if (*errorMessage == NULL) { - virReportOOMError(); + if (*errorMessage == NULL) goto cleanup; - } } else if (taskInfo->error->localizedMessage == NULL) { *errorMessage = VIR_STRDUP(taskInfo->error->fault->_actualType); - if (*errorMessage == NULL) { - virReportOOMError(); + if (*errorMessage == NULL) goto cleanup; - } } else { if (virAsprintf(errorMessage, "%s - %s", taskInfo->error->fault->_actualType, - taskInfo->error->localizedMessage) < 0) { - virReportOOMError(); + taskInfo->error->localizedMessage) < 0) goto cleanup; - } } } @@ -4984,10 +4944,8 @@ esxVI_LookupStoragePoolNameByScsiLunKey(esxVI_Context *ctx, if (STREQ(hostScsiTopologyLun->scsiLun, key)) { *poolName = VIR_STRDUP(candidate->iScsiName); - if (*poolName == NULL) { - virReportOOMError(); + if (*poolName == NULL) goto cleanup; - } } } diff --git a/src/esx/esx_vi_types.c b/src/esx/esx_vi_types.c index 80357a1..ea6c5e8 100644 --- a/src/esx/esx_vi_types.c +++ b/src/esx/esx_vi_types.c @@ -1052,10 +1052,8 @@ esxVI_AnyType_Deserialize(xmlNodePtr node, esxVI_AnyType **anyType) if ((*anyType)->value == NULL) { (*anyType)->value = VIR_STRDUP(""); - if ((*anyType)->value == NULL) { - virReportOOMError(); + if ((*anyType)->value == NULL) goto failure; - } } #define _DESERIALIZE_NUMBER(_type, _xsdType, _name, _min, _max) \ @@ -1178,10 +1176,8 @@ esxVI_String_AppendValueToList(esxVI_String **stringList, const char *value) string->value = VIR_STRDUP(value); - if (string->value == NULL) { - virReportOOMError(); + if (string->value == NULL) goto failure; - } if (esxVI_String_AppendToList(stringList, string) < 0) { goto failure; @@ -1245,10 +1241,8 @@ esxVI_String_DeepCopyValue(char **dest, const char *src) *dest = VIR_STRDUP(src); - if (*dest == NULL) { - virReportOOMError(); + if (*dest == NULL) return -1; - } return 0; } @@ -1329,10 +1323,8 @@ esxVI_String_DeserializeValue(xmlNodePtr node, char **value) if (*value == NULL) { *value = VIR_STRDUP(""); - if (*value == NULL) { - virReportOOMError(); + if (*value == NULL) return -1; - } } return 0; diff --git a/src/fdstream.c b/src/fdstream.c index 51903fe..7be10e8 100644 --- a/src/fdstream.c +++ b/src/fdstream.c @@ -476,10 +476,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/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c index f794edf..3d5cb47 100644 --- a/src/hyperv/hyperv_driver.c +++ b/src/hyperv/hyperv_driver.c @@ -114,10 +114,8 @@ hypervOpen(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; @@ -139,10 +137,8 @@ hypervOpen(virConnectPtr conn, virConnectAuthPtr auth, unsigned int flags) if (conn->uri->user != NULL) { username = VIR_STRDUP(conn->uri->user); - if (username == NULL) { - virReportOOMError(); + if (username == NULL) goto cleanup; - } } else { username = virAuthGetUsername(conn, auth, "hyperv", "administrator", conn->uri->server); @@ -256,10 +252,8 @@ hypervGetHostname(virConnectPtr conn) hostname = VIR_STRDUP(computerSystem->data->DNSHostName); - if (hostname == NULL) { - virReportOOMError(); + if (hostname == NULL) goto cleanup; - } cleanup: hypervFreeObject(priv, (hypervObject *)computerSystem); @@ -649,14 +643,7 @@ hypervDomainDestroy(virDomainPtr domain) static char * hypervDomainGetOSType(virDomainPtr domain ATTRIBUTE_UNUSED) { - char *osType = VIR_STRDUP("hvm"); - - if (osType == NULL) { - virReportOOMError(); - return NULL; - } - - return osType; + return VIR_STRDUP("hvm"); } @@ -812,10 +799,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); @@ -907,18 +892,14 @@ hypervDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) def->name = VIR_STRDUP(computerSystem->data->ElementName); - if (def->name == NULL) { - virReportOOMError(); + if (def->name == NULL) goto cleanup; - } if (virtualSystemSettingData->data->Notes != NULL) { def->description = VIR_STRDUP(virtualSystemSettingData->data->Notes); - if (def->description == NULL) { - virReportOOMError(); + if (def->description == NULL) goto cleanup; - } } def->mem.max_balloon = memorySettingData->data->Limit * 1024; /* megabyte to kilobyte */ @@ -929,10 +910,8 @@ hypervDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) def->os.type = VIR_STRDUP("hvm"); - if (def->os.type == NULL) { - virReportOOMError(); + if (def->os.type == NULL) goto cleanup; - } /* FIXME: devices section is totally missing */ @@ -980,10 +959,8 @@ hypervListDefinedDomains(virConnectPtr conn, char **const names, int maxnames) computerSystem = computerSystem->next) { names[count] = VIR_STRDUP(computerSystem->data->ElementName); - if (names[count] == NULL) { - virReportOOMError(); + if (names[count] == NULL) goto cleanup; - } ++count; @@ -1285,7 +1262,7 @@ hypervListAllDomains(virConnectPtr conn, !MATCH(VIR_CONNECT_LIST_DOMAINS_NO_SNAPSHOT))) { if (domains && VIR_ALLOC_N(*domains, 1) < 0) - goto no_memory; + goto cleanup; ret = 0; goto cleanup; @@ -1315,7 +1292,7 @@ hypervListAllDomains(virConnectPtr conn, if (domains) { if (VIR_ALLOC_N(doms, 1) < 0) - goto no_memory; + goto cleanup; ndoms = 1; } @@ -1354,7 +1331,7 @@ hypervListAllDomains(virConnectPtr conn, } if (VIR_RESIZE_N(doms, ndoms, count, 2) < 0) - goto no_memory; + goto cleanup; domain = NULL; @@ -1382,10 +1359,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 46e4e32..42c2bae 100644 --- a/src/hyperv/hyperv_util.c +++ b/src/hyperv/hyperv_util.c @@ -43,10 +43,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]; @@ -56,10 +54,8 @@ hypervParseUri(hypervParsedUri **parsedUri, virURIPtr uri) (*parsedUri)->transport = VIR_STRDUP(queryParam->value); - if ((*parsedUri)->transport == NULL) { - virReportOOMError(); + if ((*parsedUri)->transport == NULL) goto cleanup; - } if (STRNEQ((*parsedUri)->transport, "http") && STRNEQ((*parsedUri)->transport, "https")) { @@ -78,10 +74,8 @@ hypervParseUri(hypervParsedUri **parsedUri, virURIPtr uri) if ((*parsedUri)->transport == NULL) { (*parsedUri)->transport = VIR_STRDUP("https"); - if ((*parsedUri)->transport == NULL) { - virReportOOMError(); + if ((*parsedUri)->transport == NULL) goto cleanup; - } } result = 0; diff --git a/src/hyperv/hyperv_wmi.c b/src/hyperv/hyperv_wmi.c index 37394b9..76f48f2 100644 --- a/src/hyperv/hyperv_wmi.c +++ b/src/hyperv/hyperv_wmi.c @@ -209,10 +209,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; @@ -413,10 +411,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(); diff --git a/src/interface/interface_backend_netcf.c b/src/interface/interface_backend_netcf.c index 8671717..64dc79c 100644 --- a/src/interface/interface_backend_netcf.c +++ b/src/interface/interface_backend_netcf.c @@ -125,10 +125,7 @@ static virDrvOpenStatus interfaceOpenInterface(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) @@ -303,7 +300,6 @@ interfaceListAllInterfaces(virConnectPtr conn, } if (VIR_ALLOC_N(names, count) < 0) { - virReportOOMError(); ret = -1; goto cleanup; } @@ -320,12 +316,8 @@ interfaceListAllInterfaces(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++) { iface = ncf_lookup_by_name(driver->netcf, names[i]); diff --git a/src/interface/interface_backend_udev.c b/src/interface/interface_backend_udev.c index 34b673a..49ac9c3 100644 --- a/src/interface/interface_backend_udev.c +++ b/src/interface/interface_backend_udev.c @@ -110,10 +110,8 @@ udevIfaceOpenInterface(virConnectPtr conn, virCheckFlags(0, VIR_DRV_OPEN_ERROR); - if (VIR_ALLOC(driverState) < 0) { - virReportOOMError(); + if (VIR_ALLOC(driverState) < 0) goto err; - } driverState->udev = udev_new(); if (!driverState->udev) { @@ -231,10 +229,8 @@ udevIfaceListInterfacesByStatus(virConnectPtr conn, udev_device_unref(dev); /* If VIR_STRDUP() failed, we are out of memory */ - if (!names[count]) { - virReportOOMError(); + if (!names[count]) goto err; - } count++; } @@ -337,12 +333,9 @@ udevIfaceListAllInterfaces(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 */ @@ -752,10 +745,8 @@ udevIfaceGetIfaceDefBond(struct udev *udev, goto cleanup; } ifacedef->data.bond.target = VIR_STRDUP(tmp_str); - if (!ifacedef->data.bond.target) { - virReportOOMError(); + if (!ifacedef->data.bond.target) goto cleanup; - } /* Slaves of the bond */ /* Get each slave in the bond */ @@ -769,10 +760,8 @@ udevIfaceGetIfaceDefBond(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 cleanup; - } ifacedef->data.bond.nbItf = slave_count; for (i = 0; i < slave_count; i++) { @@ -840,10 +829,8 @@ udevIfaceGetIfaceDefBridge(struct udev *udev, } ifacedef->data.bridge.delay = VIR_STRDUP(tmp_str); - if (!ifacedef->data.bridge.delay) { - virReportOOMError(); + if (!ifacedef->data.bridge.delay) goto error; - } /* Retrieve Spanning Tree State. Valid values = -1, 0, 1 */ tmp_str = udev_device_get_sysattr_value(dev, "bridge/stp_state"); @@ -875,10 +862,8 @@ udevIfaceGetIfaceDefBridge(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, @@ -895,10 +880,8 @@ udevIfaceGetIfaceDefBridge(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 */ @@ -939,10 +922,8 @@ udevIfaceGetIfaceDefVlan(struct udev *udev ATTRIBUTE_UNUSED, char *vlan_parent_dev = NULL; vlan_parent_dev = VIR_STRDUP(name); - if (!vlan_parent_dev) { - virReportOOMError(); + if (!vlan_parent_dev) goto cleanup; - } /* Find the DEVICE.VID again */ vid = strrchr(vlan_parent_dev, '.'); @@ -980,19 +961,15 @@ udevIfaceGetIfaceDef(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; ifacedef->name = VIR_STRDUP(name); - if (!ifacedef->name) { - virReportOOMError(); + if (!ifacedef->name) goto cleanup; - } /* Lookup the device we've been asked about */ dev = udev_device_new_from_subsystem_sysname(udev, "net", name); @@ -1004,10 +981,8 @@ udevIfaceGetIfaceDef(struct udev *udev, const char *name) /* MAC address */ ifacedef->mac = VIR_STRDUP(udev_device_get_sysattr_value(dev, "address")); - if (!ifacedef->mac) { - virReportOOMError(); + if (!ifacedef->mac) goto cleanup; - } /* MTU */ mtu_str = udev_device_get_sysattr_value(dev, "mtu"); diff --git a/src/libvirt.c b/src/libvirt.c index 276c95e..ed5b28e 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -940,7 +940,7 @@ virConnectGetConfigFilePath(void) if (geteuid() == 0) { if (virAsprintf(&path, "%s/libvirt/libvirt.conf", SYSCONFDIR) < 0) - goto no_memory; + goto error; } else { char *userdir = virGetUserConfigDirectory(); if (!userdir) @@ -949,15 +949,13 @@ virConnectGetConfigFilePath(void) if (virAsprintf(&path, "%s/libvirt.conf", userdir) < 0) { VIR_FREE(userdir); - goto no_memory; + goto error; } VIR_FREE(userdir); } return path; -no_memory: - virReportOOMError(); error: return NULL; } @@ -1034,10 +1032,8 @@ virConnectOpenFindURIAliasMatch(virConfValuePtr value, const char *alias, char * STREQLEN(entry->str, alias, alias_len)) { VIR_DEBUG("Resolved alias '%s' to '%s'", alias, offset+1); - if (!(*uri = VIR_STRDUP(offset+1))) { - virReportOOMError(); + if (!(*uri = VIR_STRDUP(offset+1))) return -1; - } return 0; } @@ -16055,10 +16051,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; @@ -16155,10 +16149,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/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index b96c368..3778962 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -296,7 +296,6 @@ libxlMakeCapabilitiesInternal(virArch hostarch, return caps; no_memory: - virReportOOMError(); virObjectUnref(caps); return NULL; } @@ -315,10 +314,8 @@ libxlMakeDomCreateInfo(libxlDriverPrivatePtr driver, else c_info->type = LIBXL_DOMAIN_TYPE_PV; - if ((c_info->name = VIR_STRDUP(def->name)) == NULL) { - virReportOOMError(); + if ((c_info->name = VIR_STRDUP(def->name)) == NULL) goto error; - } if (def->nseclabels && def->seclabels[0]->type == VIR_DOMAIN_SECLABEL_STATIC) { @@ -416,10 +413,8 @@ libxlMakeDomBuildInfo(virDomainDefPtr def, libxl_domain_config *d_config) else { bootorder[def->os.nBootDevs] = '\0'; } - if ((b_info->u.hvm.boot = VIR_STRDUP(bootorder)) == NULL) { - virReportOOMError(); + if ((b_info->u.hvm.boot = VIR_STRDUP(bootorder)) == NULL) goto error; - } /* * The following comment and calculation were taken directly from @@ -432,10 +427,8 @@ libxlMakeDomBuildInfo(virDomainDefPtr def, libxl_domain_config *d_config) 2 * (b_info->max_memkb / 1024)); } else { if (def->os.bootloader) { - if ((b_info->u.pv.bootloader = VIR_STRDUP(def->os.bootloader)) == NULL) { - virReportOOMError(); + if ((b_info->u.pv.bootloader = VIR_STRDUP(def->os.bootloader)) == NULL) goto error; - } } if (def->os.bootloaderArgs) { if (!(b_info->u.pv.bootloader_args = @@ -443,24 +436,18 @@ libxlMakeDomBuildInfo(virDomainDefPtr def, libxl_domain_config *d_config) goto error; } if (def->os.cmdline) { - if ((b_info->u.pv.cmdline = VIR_STRDUP(def->os.cmdline)) == NULL) { - virReportOOMError(); + if ((b_info->u.pv.cmdline = VIR_STRDUP(def->os.cmdline)) == NULL) goto error; - } } if (def->os.kernel) { /* libxl_init_build_info() sets kernel.path = VIR_STRDUP("hvmloader") */ VIR_FREE(b_info->u.pv.kernel); - if ((b_info->u.pv.kernel = VIR_STRDUP(def->os.kernel)) == NULL) { - virReportOOMError(); + if ((b_info->u.pv.kernel = VIR_STRDUP(def->os.kernel)) == NULL) goto error; - } } if (def->os.initrd) { - if ((b_info->u.pv.ramdisk = VIR_STRDUP(def->os.initrd)) == NULL) { - virReportOOMError(); + if ((b_info->u.pv.ramdisk = VIR_STRDUP(def->os.initrd)) == NULL) goto error; - } } } @@ -474,15 +461,11 @@ error: int libxlMakeDisk(virDomainDiskDefPtr l_disk, libxl_device_disk *x_disk) { - if (l_disk->src && (x_disk->pdev_path = VIR_STRDUP(l_disk->src)) == NULL) { - virReportOOMError(); + if (l_disk->src && (x_disk->pdev_path = VIR_STRDUP(l_disk->src)) == NULL) return -1; - } - if (l_disk->dst && (x_disk->vdev = VIR_STRDUP(l_disk->dst)) == NULL) { - virReportOOMError(); + if (l_disk->dst && (x_disk->vdev = VIR_STRDUP(l_disk->dst)) == NULL) return -1; - } if (l_disk->driverName) { if (STREQ(l_disk->driverName, "tap") || @@ -555,10 +538,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) @@ -588,31 +569,23 @@ libxlMakeNic(virDomainNetDefPtr l_nic, libxl_device_nic *x_nic) virMacAddrGetRaw(&l_nic->mac, x_nic->mac); if (l_nic->model && !STREQ(l_nic->model, "netfront")) { - if ((x_nic->model = VIR_STRDUP(l_nic->model)) == NULL) { - virReportOOMError(); + if ((x_nic->model = VIR_STRDUP(l_nic->model)) == NULL) return -1; - } x_nic->nictype = LIBXL_NIC_TYPE_VIF_IOEMU; } else { x_nic->nictype = LIBXL_NIC_TYPE_VIF; } - if (l_nic->ifname && (x_nic->ifname = VIR_STRDUP(l_nic->ifname)) == NULL) { - virReportOOMError(); + if (l_nic->ifname && (x_nic->ifname = VIR_STRDUP(l_nic->ifname)) == NULL) return -1; - } if (l_nic->type == VIR_DOMAIN_NET_TYPE_BRIDGE) { if (l_nic->data.bridge.brname && - (x_nic->bridge = VIR_STRDUP(l_nic->data.bridge.brname)) == NULL) { - virReportOOMError(); + (x_nic->bridge = VIR_STRDUP(l_nic->data.bridge.brname)) == NULL) return -1; - } if (l_nic->script && - (x_nic->script = VIR_STRDUP(l_nic->script)) == NULL) { - virReportOOMError(); + (x_nic->script = VIR_STRDUP(l_nic->script)) == NULL) return -1; - } } else { if (l_nic->script) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, @@ -633,10 +606,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++) { x_nics[i].devid = i; @@ -669,16 +640,12 @@ libxlMakeVfb(libxlDriverPrivatePtr driver, case VIR_DOMAIN_GRAPHICS_TYPE_SDL: libxl_defbool_set(&x_vfb->sdl.enable, 1); if (l_vfb->data.sdl.display && - (x_vfb->sdl.display = VIR_STRDUP(l_vfb->data.sdl.display)) == NULL) { - virReportOOMError(); + (x_vfb->sdl.display = VIR_STRDUP(l_vfb->data.sdl.display)) == NULL) return -1; - } if (l_vfb->data.sdl.xauth && (x_vfb->sdl.xauthority = - VIR_STRDUP(l_vfb->data.sdl.xauth)) == NULL) { - virReportOOMError(); + VIR_STRDUP(l_vfb->data.sdl.xauth)) == NULL) return -1; - } break; case VIR_DOMAIN_GRAPHICS_TYPE_VNC: libxl_defbool_set(&x_vfb->vnc.enable, 1); @@ -701,17 +668,13 @@ libxlMakeVfb(libxlDriverPrivatePtr driver, if (listenAddr) { /* libxl_device_vfb_init() does VIR_STRDUP("127.0.0.1") */ VIR_FREE(x_vfb->vnc.listen); - if ((x_vfb->vnc.listen = VIR_STRDUP(listenAddr)) == NULL) { - virReportOOMError(); + if ((x_vfb->vnc.listen = VIR_STRDUP(listenAddr)) == NULL) return -1; - } } if (l_vfb->data.vnc.keymap && (x_vfb->keymap = - VIR_STRDUP(l_vfb->data.vnc.keymap)) == NULL) { - virReportOOMError(); + VIR_STRDUP(l_vfb->data.vnc.keymap)) == NULL) return -1; - } break; } @@ -732,12 +695,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 6086b5d..f43bafc 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -178,10 +178,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; - } if (events & POLLIN) vir_events |= VIR_EVENT_HANDLE_READABLE; @@ -280,10 +278,8 @@ libxlTimeoutRegisterEventHook(void *priv, static struct timeval zero; int timeout; - if (VIR_ALLOC(info) < 0) { - virReportOOMError(); + if (VIR_ALLOC(info) < 0) return -1; - } gettimeofday(&now, NULL); timersub(&abs_t, &now, &res); @@ -503,13 +499,9 @@ libxlDoNodeGetInfo(libxlDriverPrivatePtr driver, virNodeInfoPtr info) static char * libxlDomainManagedSavePath(libxlDriverPrivatePtr driver, virDomainObjPtr vm) { - char *ret; - - if (virAsprintf(&ret, "%s/%s.save", driver->saveDir, vm->def->name) < 0) { - virReportOOMError(); - return NULL; - } + char *ret = NULL; + ignore_value(virAsprintf(&ret, "%s/%s.save", driver->saveDir, vm->def->name)); return ret; } @@ -554,10 +546,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")); @@ -788,10 +778,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; @@ -1154,27 +1142,27 @@ libxlStartup(bool privileged, if (virAsprintf(&libxl_driver->configDir, "%s", LIBXL_CONFIG_DIR) == -1) - goto out_of_memory; + goto error; if (virAsprintf(&libxl_driver->autostartDir, "%s", LIBXL_AUTOSTART_DIR) == -1) - goto out_of_memory; + goto error; if (virAsprintf(&libxl_driver->logDir, "%s", LIBXL_LOG_DIR) == -1) - goto out_of_memory; + goto error; if (virAsprintf(&libxl_driver->stateDir, "%s", LIBXL_STATE_DIR) == -1) - goto out_of_memory; + goto error; if (virAsprintf(&libxl_driver->libDir, "%s", LIBXL_LIB_DIR) == -1) - goto out_of_memory; + goto error; if (virAsprintf(&libxl_driver->saveDir, "%s", LIBXL_SAVE_DIR) == -1) - goto out_of_memory; + goto error; if (virFileMakePath(libxl_driver->logDir) < 0) { VIR_ERROR(_("Failed to create log dir '%s': %s"), @@ -1197,9 +1185,8 @@ libxlStartup(bool privileged, goto error; } - if (virAsprintf(&log_file, "%s/libxl.log", libxl_driver->logDir) < 0) { - goto out_of_memory; - } + if (virAsprintf(&log_file, "%s/libxl.log", libxl_driver->logDir) < 0) + goto error; if ((libxl_driver->logger_file = fopen(log_file, "a")) == NULL) { virReportSystemError(errno, @@ -1276,8 +1263,6 @@ libxlStartup(bool privileged, return 0; -out_of_memory: - virReportOOMError(); error: ret = -1; fail: @@ -1853,8 +1838,7 @@ libxlDomainGetOSType(virDomainPtr dom) goto cleanup; } - if (!(type = VIR_STRDUP(vm->def->os.type))) - virReportOOMError(); + type = VIR_STRDUP(vm->def->os.type); cleanup: if (vm) @@ -2585,10 +2569,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; @@ -2743,10 +2725,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, @@ -2939,10 +2919,8 @@ libxlDomainXMLToNative(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); @@ -3238,10 +3216,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; @@ -3363,10 +3339,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; @@ -3870,9 +3844,6 @@ libxlDomainGetSchedulerType(virDomainPtr dom, int *nparams) goto cleanup; } - if (!ret) - virReportOOMError(); - cleanup: if (vm) virObjectUnlock(vm); diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c index f62642c..9da06c6 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", @@ -371,7 +367,7 @@ virLockDaemonPidFilePath(bool privileged, { if (privileged) { if (!(*pidfile = VIR_STRDUP(LOCALSTATEDIR "/run/virtlockd.pid"))) - goto no_memory; + goto error; } else { char *rundir = NULL; mode_t old_umask; @@ -388,7 +384,7 @@ virLockDaemonPidFilePath(bool privileged, if (virAsprintf(pidfile, "%s/virtlockd.pid", rundir) < 0) { VIR_FREE(rundir); - goto no_memory; + goto error; } VIR_FREE(rundir); @@ -396,8 +392,6 @@ virLockDaemonPidFilePath(bool privileged, return 0; -no_memory: - virReportOOMError(); error: return -1; } @@ -409,7 +403,7 @@ virLockDaemonUnixSocketPaths(bool privileged, { if (privileged) { if (!(*sockfile = VIR_STRDUP(LOCALSTATEDIR "/run/libvirt/virtlockd-sock"))) - goto no_memory; + goto error; } else { char *rundir = NULL; mode_t old_umask; @@ -426,15 +420,13 @@ virLockDaemonUnixSocketPaths(bool privileged, if (virAsprintf(sockfile, "%s/virtlockd-sock", rundir) < 0) { VIR_FREE(rundir); - goto no_memory; + goto error; } VIR_FREE(rundir); } return 0; -no_memory: - virReportOOMError(); error: return -1; } @@ -501,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); } @@ -519,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; @@ -537,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); @@ -557,8 +549,6 @@ virLockDaemonSetupLogging(virLockDaemonConfigPtr config, return 0; -no_memory: - virReportOOMError(); error: return -1; } @@ -785,14 +775,11 @@ virLockDaemonClientNew(virNetServerClientPtr client, gid_t clientgid; 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(); return NULL; } @@ -867,10 +854,8 @@ virLockDaemonClientNewPostExecRestart(virNetServerClientPtr client, _("Missing ownerName data in JSON document")); goto error; } - if (!(priv->ownerName = VIR_STRDUP(ownerName))) { - virReportOOMError(); + if (!(priv->ownerName = VIR_STRDUP(ownerName))) goto error; - } if (!(ownerUUID = virJSONValueObjectGetString(object, "ownerUUID"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing ownerUUID data in JSON document")); @@ -940,14 +925,9 @@ error: static char * virLockDaemonGetExecRestartMagic(void) { - char *ret; - - if (virAsprintf(&ret, "%lld", - (long long int)getpid()) < 0) { - virReportOOMError(); - return NULL; - } + char *ret = NULL; + ignore_value(virAsprintf(&ret, "%lld", (long long int)getpid())); return ret; } @@ -1312,10 +1292,8 @@ int main(int argc, char **argv) { /* Ensure the rundir exists (on tmpfs on some systems) */ if (privileged) { - if (!(run_dir = VIR_STRDUP(LOCALSTATEDIR "/run/libvirt"))) { - virReportOOMError(); + if (!(run_dir = VIR_STRDUP(LOCALSTATEDIR "/run/libvirt"))) goto cleanup; - } } else { if (!(run_dir = virGetUserRuntimeDirectory())) { VIR_ERROR(_("Can't determine user directory")); diff --git a/src/locking/lock_daemon_config.c b/src/locking/lock_daemon_config.c index 82046c6..749920a 100644 --- a/src/locking/lock_daemon_config.c +++ b/src/locking/lock_daemon_config.c @@ -63,10 +63,8 @@ checkType(virConfValuePtr p, const char *filename, if (checkType(p, filename, #var_name, VIR_CONF_STRING) < 0) \ goto error; \ VIR_FREE(data->var_name); \ - if (!(data->var_name = VIR_STRDUP(p->str))) { \ - virReportOOMError(); \ + if (!(data->var_name = VIR_STRDUP(p->str))) \ goto error; \ - } \ } \ } while (0) @@ -86,7 +84,7 @@ virLockDaemonConfigFilePath(bool privileged, char **configfile) { if (privileged) { if (!(*configfile = VIR_STRDUP(SYSCONFDIR "/libvirt/virtlockd.conf"))) - goto no_memory; + goto error; } else { char *configdir = NULL; @@ -95,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; } @@ -114,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_daemon_dispatch.c b/src/locking/lock_daemon_dispatch.c index ebe6197..44b501d 100644 --- a/src/locking/lock_daemon_dispatch.c +++ b/src/locking/lock_daemon_dispatch.c @@ -276,10 +276,8 @@ virLockSpaceProtocolDispatchRegister(virNetServerPtr server ATTRIBUTE_UNUSED, goto cleanup; } - if (!(priv->ownerName = VIR_STRDUP(args->owner.name))) { - virReportOOMError(); + if (!(priv->ownerName = VIR_STRDUP(args->owner.name))) goto cleanup; - } memcpy(priv->ownerUUID, args->owner.uuid, VIR_UUID_BUFLEN); priv->ownerId = args->owner.id; priv->ownerPid = args->owner.pid; diff --git a/src/locking/lock_driver_lockd.c b/src/locking/lock_driver_lockd.c index b3b8d25..086112c 100644 --- a/src/locking/lock_driver_lockd.c +++ b/src/locking/lock_driver_lockd.c @@ -130,7 +130,6 @@ static int virLockManagerLockDaemonLoadConfig(const char *configFile) if (p && p->str) { VIR_FREE(driver->fileLockSpaceDir); if (!(driver->fileLockSpaceDir = VIR_STRDUP(p->str))) { - virReportOOMError(); virConfFree(conf); return -1; } @@ -141,7 +140,6 @@ static int virLockManagerLockDaemonLoadConfig(const char *configFile) if (p && p->str) { VIR_FREE(driver->lvmLockSpaceDir); if (!(driver->lvmLockSpaceDir = VIR_STRDUP(p->str))) { - virReportOOMError(); virConfFree(conf); return -1; } @@ -152,7 +150,6 @@ static int virLockManagerLockDaemonLoadConfig(const char *configFile) if (p && p->str) { VIR_FREE(driver->scsiLockSpaceDir); if (!(driver->scsiLockSpaceDir = VIR_STRDUP(p->str))) { - virReportOOMError(); virConfFree(conf); return -1; } @@ -174,10 +171,8 @@ static char *virLockManagerLockDaemonPath(bool privileged) { char *path; if (privileged) { - if (!(path = VIR_STRDUP(LOCALSTATEDIR "/run/libvirt/virtlockd-sock"))) { - virReportOOMError(); + if (!(path = VIR_STRDUP(LOCALSTATEDIR "/run/libvirt/virtlockd-sock"))) return NULL; - } } else { char *rundir = NULL; @@ -186,7 +181,6 @@ static char *virLockManagerLockDaemonPath(bool privileged) if (virAsprintf(&path, "%s/virtlockd-sock", rundir) < 0) { VIR_FREE(rundir); - virReportOOMError(); return NULL; } @@ -380,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; @@ -456,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) { @@ -468,10 +458,8 @@ static int virLockManagerLockDaemonNew(virLockManagerPtr lock, if (STREQ(params[i].key, "uuid")) { memcpy(priv->uuid, params[i].value.uuid, VIR_UUID_BUFLEN); } else if (STREQ(params[i].key, "name")) { - if (!(priv->name = VIR_STRDUP(params[i].value.str))) { - virReportOOMError(); + if (!(priv->name = VIR_STRDUP(params[i].value.str))) return -1; - } } else if (STREQ(params[i].key, "id")) { priv->id = params[i].value.i; } else if (STREQ(params[i].key, "pid")) { @@ -530,10 +518,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]; @@ -589,7 +575,7 @@ static int virLockManagerLockDaemonAddResource(virLockManagerPtr lock, if (newName) { VIR_DEBUG("Got an LVM UUID %s for %s", newName, name); if (!(newLockspace = VIR_STRDUP(driver->lvmLockSpaceDir))) - goto no_memory; + goto error; autoCreate = true; break; } @@ -606,7 +592,7 @@ static int virLockManagerLockDaemonAddResource(virLockManagerPtr lock, if (newName) { VIR_DEBUG("Got an SCSI ID %s for %s", newName, name); if (!(newLockspace = VIR_STRDUP(driver->scsiLockSpaceDir))) - goto no_memory; + goto error; autoCreate = true; break; } @@ -616,16 +602,16 @@ static int virLockManagerLockDaemonAddResource(virLockManagerPtr lock, if (driver->fileLockSpaceDir) { if (!(newLockspace = VIR_STRDUP(driver->fileLockSpaceDir))) - goto no_memory; + goto error; if (!(newName = virLockManagerLockDaemonDiskLeaseName(name))) - goto no_memory; + goto error; autoCreate = true; VIR_DEBUG("Using indirect lease %s for %s", newName, name); } else { if (!(newLockspace = VIR_STRDUP(""))) - goto no_memory; + goto error; if (!(newName = VIR_STRDUP(name))) - goto no_memory; + goto error; VIR_DEBUG("Using direct lease for %s", name); } @@ -658,12 +644,10 @@ static int virLockManagerLockDaemonAddResource(virLockManagerPtr lock, return -1; } if (virAsprintf(&newLockspace, "%s/%s", - path, lockspace) < 0) { - virReportOOMError(); + path, lockspace) < 0) return -1; - } if (!(newName = VIR_STRDUP(name))) - goto no_memory; + goto error; } break; default: @@ -674,7 +658,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; @@ -689,8 +673,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 42cda67..53b46b5 100644 --- a/src/locking/lock_driver_sanlock.c +++ b/src/locking/lock_driver_sanlock.c @@ -129,7 +129,6 @@ static int virLockManagerSanlockLoadConfig(const char *configFile) if (p && p->str) { VIR_FREE(driver->autoDiskLeasePath); if (!(driver->autoDiskLeasePath = VIR_STRDUP(p->str))) { - virReportOOMError(); virConfFree(conf); return -1; } @@ -150,7 +149,6 @@ static int virLockManagerSanlockLoadConfig(const char *configFile) CHECK_TYPE("user", VIR_CONF_STRING); if (p) { if (!(tmp = VIR_STRDUP(p->str))) { - virReportOOMError(); virConfFree(conf); return -1; } @@ -167,7 +165,6 @@ static int virLockManagerSanlockLoadConfig(const char *configFile) CHECK_TYPE("group", VIR_CONF_STRING); if (p) { if (!(tmp = VIR_STRDUP(p->str))) { - virReportOOMError(); virConfFree(conf); return -1; } @@ -200,10 +197,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)) { @@ -397,10 +392,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; @@ -409,7 +402,6 @@ static int virLockManagerSanlockInit(unsigned int version, driver->group = (gid_t) -1; if (!(driver->autoDiskLeasePath = VIR_STRDUP(LOCALSTATEDIR "/lib/libvirt/sanlock"))) { VIR_FREE(driver); - virReportOOMError(); goto error; } @@ -470,10 +462,8 @@ static int virLockManagerSanlockNew(virLockManagerPtr lock, return -1; } - if (VIR_ALLOC(priv) < 0) { - virReportOOMError(); + if (VIR_ALLOC(priv) < 0) return -1; - } priv->flags = flags; @@ -562,10 +552,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; @@ -627,10 +615,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; @@ -638,10 +624,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"), @@ -921,10 +905,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 4baca1e..1844126 100644 --- a/src/locking/lock_manager.c +++ b/src/locking/lock_manager.c @@ -142,10 +142,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; @@ -155,10 +153,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, @@ -185,18 +181,14 @@ 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; plugin->refs = 1; - if (!(plugin->name = VIR_STRDUP(name))) { - virReportOOMError(); + if (!(plugin->name = VIR_STRDUP(name))) goto cleanup; - } VIR_FREE(configFile); VIR_FREE(modfile); @@ -322,10 +314,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; diff --git a/src/lxc/lxc_conf.c b/src/lxc/lxc_conf.c index 794bfe1..8599b79 100644 --- a/src/lxc/lxc_conf.c +++ b/src/lxc/lxc_conf.c @@ -131,12 +131,12 @@ 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 (!(caps->host.secModels[0].model = VIR_STRDUP(model))) - goto no_memory; + goto error; if (!(caps->host.secModels[0].doi = VIR_STRDUP(doi))) - goto no_memory; + goto error; } VIR_DEBUG("Initialized caps for security driver \"%s\" with " @@ -147,9 +147,6 @@ virCapsPtr lxcCapsInit(virLXCDriverPtr driver) return caps; -no_memory: - virReportOOMError(); - error: virObjectUnref(caps); return NULL; @@ -208,7 +205,6 @@ int lxcLoadDriverConfig(virLXCDriverPtr driver) CHECK_TYPE("security_driver", VIR_CONF_STRING); if (p && p->str) { if (!(driver->securityDriverName = VIR_STRDUP(p->str))) { - virReportOOMError(); virConfFree(conf); return -1; } @@ -232,6 +228,5 @@ done: return 0; no_memory: - virReportOOMError(); return -1; } diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c index 8616731..460563f 100644 --- a/src/lxc/lxc_container.c +++ b/src/lxc/lxc_container.c @@ -155,10 +155,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); @@ -352,7 +350,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; } @@ -432,10 +429,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; @@ -470,10 +465,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, @@ -492,10 +485,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, @@ -621,10 +612,8 @@ static int lxcContainerMountBasicFS(bool pivotRoot, ignore_value(virAsprintf(&opts, "mode=755,size=65536%s", sec_mount_options)); - if (!opts) { - virReportOOMError(); + if (!opts) goto cleanup; - } VIR_DEBUG("Mount devfs on /dev type=tmpfs flags=%x, opts=%s", MS_NOSUID, opts); @@ -778,10 +767,8 @@ static int lxcContainerPopulateDevices(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, @@ -809,10 +796,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) { @@ -935,10 +920,8 @@ lxcContainerMountDetectFilesystem(const char *src, char **type) goto cleanup; } - if (!(*type = VIR_STRDUP(data))) { - virReportOOMError(); + if (!(*type = VIR_STRDUP(data))) goto cleanup; - } done: ret = 0; @@ -985,10 +968,8 @@ static int lxcContainerMountFSBlockAuto(virDomainFSDefPtr fs, /* First time around we use /etc/filesystems */ retry: if (virAsprintf(&fslist, "%s%s", - srcprefix, tryProc ? "/proc/filesystems" : "/etc/filesystems") < 0) { - virReportOOMError(); + srcprefix, tryProc ? "/proc/filesystems" : "/etc/filesystems") < 0) goto cleanup; - } VIR_DEBUG("Open fslist %s", fslist); if (!(fp = fopen(fslist, "r"))) { @@ -1143,10 +1124,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, srcprefix); @@ -1165,10 +1144,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, @@ -1286,15 +1263,11 @@ static int lxcContainerSetupDisk(virDomainDefPtr vmDef, goto cleanup; } - if (virAsprintf(&src, "%s/%s", dstprefix, def->src) < 0) { - virReportOOMError(); + if (virAsprintf(&src, "%s/%s", dstprefix, 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, @@ -1376,22 +1349,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, "%s/%s", dstprefix, dstfile) < 0) { - virReportOOMError(); + if (virAsprintf(&src, "%s/%s", dstprefix, dstfile) < 0) goto cleanup; - } if (stat(src, &sb) < 0) { virReportSystemError(errno, @@ -1452,10 +1419,8 @@ static int lxcContainerSetupHostdevCapsStorage(virDomainDefPtr vmDef ATTRIBUTE_U goto cleanup; } - if (virAsprintf(&src, "%s/%s", dstprefix, def->source.caps.u.storage.block) < 0) { - virReportOOMError(); + if (virAsprintf(&src, "%s/%s", dstprefix, def->source.caps.u.storage.block) < 0) goto cleanup; - } if (stat(src, &sb) < 0) { virReportSystemError(errno, @@ -1510,10 +1475,8 @@ static int lxcContainerSetupHostdevCapsMisc(virDomainDefPtr vmDef ATTRIBUTE_UNUS goto cleanup; } - if (virAsprintf(&src, "%s/%s", dstprefix, def->source.caps.u.misc.chardev) < 0) { - virReportOOMError(); + if (virAsprintf(&src, "%s/%s", dstprefix, def->source.caps.u.misc.chardev) < 0) goto cleanup; - } if (stat(src, &sb) < 0) { virReportSystemError(errno, @@ -1649,14 +1612,10 @@ 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 (!(mounts[nmounts] = VIR_STRDUP(mntent.mnt_dir))) { - virReportOOMError(); + if (!(mounts[nmounts] = VIR_STRDUP(mntent.mnt_dir))) goto cleanup; - } nmounts++; VIR_DEBUG("Grabbed %s", mntent.mnt_dir); } @@ -1784,10 +1743,8 @@ static int lxcContainerIdentifyCGroups(struct lxcContainerCGroup **mountsret, if (!*root) { char *tmp; - if (!(*root = VIR_STRDUP(mntent.mnt_dir))) { - virReportOOMError(); + if (!(*root = VIR_STRDUP(mntent.mnt_dir))) goto cleanup; - } tmp = strrchr(*root, '/'); *tmp = '\0'; } else if (!STRPREFIX(mntent.mnt_dir, *root)) { @@ -1802,14 +1759,10 @@ static int lxcContainerIdentifyCGroups(struct lxcContainerCGroup **mountsret, if (strstr(mntent.mnt_opts, "name=")) continue; - if (VIR_EXPAND_N(mounts, nmounts, 1) < 0) { - virReportOOMError(); + if (VIR_EXPAND_N(mounts, nmounts, 1) < 0) goto cleanup; - } - if (!(mounts[nmounts-1].dir = VIR_STRDUP(mntent.mnt_dir))) { - virReportOOMError(); + if (!(mounts[nmounts-1].dir = VIR_STRDUP(mntent.mnt_dir))) goto cleanup; - } VIR_DEBUG("Grabbed '%s'", mntent.mnt_dir); } @@ -1837,10 +1790,8 @@ static int lxcContainerIdentifyCGroups(struct lxcContainerCGroup **mountsret, continue; VIR_DEBUG("Checking entry %s", dent->d_name); - if (virAsprintf(&path, "%s/%s", *root, dent->d_name) < 0) { - virReportOOMError(); + if (virAsprintf(&path, "%s/%s", *root, dent->d_name) < 0) goto cleanup; - } if ((rv = readlink(path, linkbuf, sizeof(linkbuf)-1)) < 0) { if (errno != EINVAL) { @@ -1855,14 +1806,10 @@ static int lxcContainerIdentifyCGroups(struct lxcContainerCGroup **mountsret, } else { linkbuf[rv] = '\0'; VIR_DEBUG("Got a link %s to %s", path, linkbuf); - if (VIR_EXPAND_N(mounts, nmounts, 1) < 0) { - virReportOOMError(); + if (VIR_EXPAND_N(mounts, nmounts, 1) < 0) goto cleanup; - } - if (!(mounts[nmounts-1].linkDest = VIR_STRDUP(linkbuf))) { - virReportOOMError(); + if (!(mounts[nmounts-1].linkDest = VIR_STRDUP(linkbuf))) goto cleanup; - } mounts[nmounts-1].dir = path; path = NULL; } @@ -1903,10 +1850,8 @@ static int lxcContainerMountCGroups(struct lxcContainerCGroup *mounts, } if (virAsprintf(&opts, - "mode=755,size=65536%s", sec_mount_options) < 0) { - virReportOOMError(); + "mode=755,size=65536%s", sec_mount_options) < 0) return -1; - } if (mount("tmpfs", root, "tmpfs", MS_NOSUID|MS_NODEV|MS_NOEXEC, opts) < 0) { VIR_FREE(opts); @@ -2263,21 +2208,15 @@ 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 (!(ttyPath = VIR_STRDUP(argv->ttyPaths[0]))) { - virReportOOMError(); + if (!(ttyPath = VIR_STRDUP(argv->ttyPaths[0]))) goto cleanup; - } } } else { - if (!(ttyPath = VIR_STRDUP("/dev/null"))) { - virReportOOMError(); + if (!(ttyPath = VIR_STRDUP("/dev/null"))) goto cleanup; - } } VIR_DEBUG("Container TTY path: %s", ttyPath); @@ -2417,10 +2356,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 a4de784..9cadb10 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c @@ -151,13 +151,13 @@ static virLXCControllerPtr virLXCControllerNew(const char *name) char *configFile = NULL; if (VIR_ALLOC(ctrl) < 0) - goto no_memory; + goto error; ctrl->timerShutdown = -1; ctrl->firstClient = true; if (!(ctrl->name = VIR_STRDUP(name))) - goto no_memory; + goto error; if ((caps = lxcCapsInit(NULL)) == NULL) goto error; @@ -186,8 +186,6 @@ cleanup: virObjectUnref(xmlconf); return ctrl; -no_memory: - virReportOOMError(); error: virLXCControllerFree(ctrl); ctrl = NULL; @@ -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; @@ -408,7 +404,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; @@ -451,7 +446,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; @@ -621,10 +615,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, @@ -1135,7 +1127,6 @@ lxcCreateTty(char *ptmx, int *ttymaster, char **ttyName) * kernels, we can skip those steps. ptyno shouldn't currently be * anything other than 0, but let's play it safe. */ if (virAsprintf(ttyName, "/dev/pts/%d", ptyno) < 0) { - virReportOOMError(); errno = ENOMEM; goto cleanup; } @@ -1222,10 +1213,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, @@ -1237,10 +1226,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); @@ -1408,10 +1395,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", @@ -1560,28 +1545,20 @@ int main(int argc, char *argv[]) break; case 'n': - if ((name = VIR_STRDUP(optarg)) == NULL) { - virReportOOMError(); + if ((name = VIR_STRDUP(optarg)) == NULL) goto cleanup; - } break; case 'v': - if (VIR_REALLOC_N(veths, nveths+1) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(veths, nveths+1) < 0) goto cleanup; - } - if ((veths[nveths++] = VIR_STRDUP(optarg)) == NULL) { - virReportOOMError(); + if ((veths[nveths++] = VIR_STRDUP(optarg)) == NULL) 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 c01c259..8baaf05 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -636,9 +636,6 @@ static char *lxcGetOSType(virDomainPtr dom) ret = VIR_STRDUP(vm->def->os.type); - if (ret == NULL) - virReportOOMError(); - cleanup: if (vm) virObjectUnlock(vm); @@ -1681,8 +1678,6 @@ static char *lxcGetSchedulerType(virDomainPtr domain, } ret = VIR_STRDUP("posix"); - if (!ret) - virReportOOMError(); cleanup: lxcDriverUnlock(driver); @@ -2819,10 +2814,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 (root && root->src) { if (flags == 0) @@ -2912,10 +2905,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)) { @@ -2972,10 +2963,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; @@ -2983,10 +2972,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; @@ -2998,10 +2985,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; @@ -3177,15 +3162,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)) @@ -3273,10 +3254,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 @@ -3411,31 +3390,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 (!lxcCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_DEVICES)) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", @@ -3552,22 +3523,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; @@ -3665,22 +3630,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; @@ -3871,10 +3830,8 @@ lxcDomainDetachDeviceDiskLive(virLXCDriverPtr driver, 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 (!lxcCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_DEVICES)) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", @@ -4002,18 +3959,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 (!lxcCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_DEVICES)) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", @@ -4089,10 +4042,8 @@ lxcDomainDetachDeviceHostdevStorageLive(virLXCDriverPtr driver, 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 (!lxcCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_DEVICES)) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", @@ -4160,10 +4111,8 @@ lxcDomainDetachDeviceHostdevMiscLive(virLXCDriverPtr driver, 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 (!lxcCgroupControllerActive(driver, 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 9f6f3da..1da716d 100644 --- a/src/lxc/lxc_fuse.c +++ b/src/lxc/lxc_fuse.c @@ -50,10 +50,8 @@ static int lxcProcGetattr(const char *path, struct stat *stbuf) struct stat sb; 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; @@ -234,10 +232,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; @@ -293,10 +289,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 465748d..6a93205 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 c7374bb..99e316e 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -443,10 +443,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: { @@ -649,10 +647,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, @@ -1049,10 +1045,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 @@ -1089,10 +1083,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; @@ -1132,10 +1124,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) @@ -1186,10 +1176,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", diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 0cf6c42..2e9b658 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -194,13 +194,13 @@ 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; /* dnsmasq */ dnsmasqDelete(dctx); @@ -223,10 +223,6 @@ cleanup: VIR_FREE(radvdpidbase); dnsmasqContextFree(dctx); return ret; - -no_memory: - virReportOOMError(); - goto cleanup; } static char * @@ -294,10 +290,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(NETWORK_PID_DIR, radvdpidbase, &obj->radvdPid, RADVD)); VIR_FREE(radvdpidbase); @@ -372,10 +366,10 @@ networkStartup(bool privileged, if (privileged) { if (virAsprintf(&driverState->logDir, "%s/log/libvirt/qemu", LOCALSTATEDIR) == -1) - goto out_of_memory; + goto error; if ((base = VIR_STRDUP(SYSCONFDIR "/libvirt")) == NULL) - goto out_of_memory; + goto error; } else { char *userdir = virGetUserCacheDirectory(); @@ -385,14 +379,14 @@ networkStartup(bool privileged, if (virAsprintf(&driverState->logDir, "%s/qemu/log", userdir) == -1) { VIR_FREE(userdir); - goto out_of_memory; + goto error; } VIR_FREE(userdir); userdir = virGetUserConfigDirectory(); if (virAsprintf(&base, "%s", userdir) == -1) { VIR_FREE(userdir); - goto out_of_memory; + goto error; } VIR_FREE(userdir); } @@ -401,17 +395,16 @@ networkStartup(bool privileged, * /etc/libvirt/qemu/... (system). */ if (virAsprintf(&driverState->networkConfigDir, "%s/qemu/networks", base) == -1) - goto out_of_memory; + goto error; if (virAsprintf(&driverState->networkAutostartDir, "%s/qemu/networks/autostart", base) == -1) - goto out_of_memory; + goto error; VIR_FREE(base); - if (!(driverState->iptables = iptablesContextNew())) { - goto out_of_memory; - } + if (!(driverState->iptables = iptablesContextNew())) + goto error; /* if this fails now, it will be retried later with dnsmasqCapsRefresh() */ driverState->dnsmasqCaps = dnsmasqCapsNewFromBinary(DNSMASQ); @@ -456,9 +449,6 @@ networkStartup(bool privileged, return 0; -out_of_memory: - virReportOOMError(); - error: if (driverState) networkDriverUnlock(driverState); @@ -772,22 +762,16 @@ 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(); + if (virAsprintf(&recordPort, "%d", dns->srvs[ii].port) < 0) goto cleanup; - } } if (dns->srvs[ii].priority) { - if (virAsprintf(&recordPriority, "%d", dns->srvs[ii].priority) < 0) { - virReportOOMError(); + if (virAsprintf(&recordPriority, "%d", dns->srvs[ii].priority) < 0) goto cleanup; - } } if (dns->srvs[ii].weight) { - if (virAsprintf(&recordWeight, "%d", dns->srvs[ii].weight) < 0) { - virReportOOMError(); + if (virAsprintf(&recordWeight, "%d", dns->srvs[ii].weight) < 0) goto cleanup; - } } if (virAsprintf(&record, "%s.%s.%s,%s,%s,%s,%s", @@ -797,10 +781,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); @@ -916,10 +898,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); @@ -933,10 +913,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); @@ -1014,10 +992,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) { @@ -1063,10 +1039,8 @@ networkStartDhcpDaemon(struct network_driver *driver, goto cleanup; } - if (!(pidfile = virPidFileBuildPath(NETWORK_PID_DIR, network->def->name))) { - virReportOOMError(); + if (!(pidfile = virPidFileBuildPath(NETWORK_PID_DIR, network->def->name))) goto cleanup; - } if (virFileMakePath(DNSMASQ_STATE_DIR) < 0) { virReportSystemError(errno, @@ -1314,10 +1288,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, @@ -1379,14 +1351,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(NETWORK_PID_DIR, radvdpidbase))) { - virReportOOMError(); + if (!(pidfile = virPidFileBuildPath(NETWORK_PID_DIR, radvdpidbase))) goto cleanup; - } if (networkRadvdConfWrite(network, &configfile) < 0) goto cleanup; @@ -2202,10 +2170,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", @@ -2231,10 +2197,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, @@ -2247,10 +2211,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, @@ -2407,10 +2369,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, @@ -2558,9 +2518,7 @@ static int networkShutdownNetworkVirtual(struct network_driver *driver, 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(NETWORK_PID_DIR, radvdpidbase); VIR_FREE(radvdpidbase); } @@ -2571,9 +2529,7 @@ static int networkShutdownNetworkVirtual(struct network_driver *driver, if (network->def->mac_specified) { char *macTapIfName = networkBridgeDummyNicName(network->def->bridge); - if (!macTapIfName) { - virReportOOMError(); - } else { + if (macTapIfName) { ignore_value(virNetDevTapDelete(macTapIfName)); VIR_FREE(macTapIfName); } @@ -2812,7 +2768,6 @@ static int networkListNetworks(virConnectPtr conn, char **const names, int nname if (virNetworkObjIsActive(driver->networks.objs[i])) { if (!(names[got] = VIR_STRDUP(driver->networks.objs[i]->def->name))) { virNetworkObjUnlock(driver->networks.objs[i]); - virReportOOMError(); goto cleanup; } got++; @@ -2856,7 +2811,6 @@ static int networkListDefinedNetworks(virConnectPtr conn, char **const names, in if (!virNetworkObjIsActive(driver->networks.objs[i])) { if (!(names[got] = VIR_STRDUP(driver->networks.objs[i]->def->name))) { virNetworkObjUnlock(driver->networks.objs[i]); - virReportOOMError(); goto cleanup; } got++; @@ -3479,8 +3433,6 @@ static char *networkGetBridgeName(virNetworkPtr net) { } bridge = VIR_STRDUP(network->def->bridge); - if (!bridge) - virReportOOMError(); cleanup: if (network) @@ -3654,10 +3606,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; @@ -3669,10 +3619,8 @@ networkCreateInterfacePool(virNetworkDefPtr netdef) { netdef->forward.ifs[ii].type = VIR_NETWORK_FORWARD_HOSTDEV_DEVICE_NETDEV; if (vfname[ii]) { netdef->forward.ifs[ii].device.dev = VIR_STRDUP(vfname[ii]); - if (!netdef->forward.ifs[ii].device.dev) { - virReportOOMError(); + if (!netdef->forward.ifs[ii].device.dev) goto finish; - } } else { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -3762,10 +3710,8 @@ networkAllocateActualDevice(virDomainNetDefPtr iface) if (bandwidth) { if (!iface->data.network.actual - && (VIR_ALLOC(iface->data.network.actual) < 0)) { - virReportOOMError(); + && (VIR_ALLOC(iface->data.network.actual) < 0)) goto error; - } if (virNetDevBandwidthCopy(&iface->data.network.actual->bandwidth, bandwidth) < 0) @@ -3782,10 +3728,8 @@ networkAllocateActualDevice(virDomainNetDefPtr iface) if (vlan) { if (!iface->data.network.actual - && (VIR_ALLOC(iface->data.network.actual) < 0)) { - virReportOOMError(); + && (VIR_ALLOC(iface->data.network.actual) < 0)) goto error; - } if (virNetDevVlanCopy(&iface->data.network.actual->vlan, vlan) < 0) goto error; } @@ -3811,17 +3755,13 @@ networkAllocateActualDevice(virDomainNetDefPtr iface) */ if (!iface->data.network.actual - && (VIR_ALLOC(iface->data.network.actual) < 0)) { - virReportOOMError(); + && (VIR_ALLOC(iface->data.network.actual) < 0)) goto error; - } iface->data.network.actual->type = actualType = VIR_DOMAIN_NET_TYPE_BRIDGE; iface->data.network.actual->data.bridge.brname = VIR_STRDUP(netdef->bridge); - if (!iface->data.network.actual->data.bridge.brname) { - virReportOOMError(); + if (!iface->data.network.actual->data.bridge.brname) goto error; - } /* merge virtualports from interface, network, and portgroup to * arrive at actual virtualport to use @@ -3849,10 +3789,8 @@ networkAllocateActualDevice(virDomainNetDefPtr iface) } else if (netdef->forward.type == VIR_NETWORK_FORWARD_HOSTDEV) { if (!iface->data.network.actual - && (VIR_ALLOC(iface->data.network.actual) < 0)) { - virReportOOMError(); + && (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 && @@ -3917,10 +3855,8 @@ networkAllocateActualDevice(virDomainNetDefPtr iface) */ if (!iface->data.network.actual - && (VIR_ALLOC(iface->data.network.actual) < 0)) { - virReportOOMError(); + && (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; @@ -4016,10 +3952,8 @@ networkAllocateActualDevice(virDomainNetDefPtr iface) goto error; } iface->data.network.actual->data.direct.linkdev = VIR_STRDUP(dev->device.dev); - if (!iface->data.network.actual->data.direct.linkdev) { - virReportOOMError(); + if (!iface->data.network.actual->data.direct.linkdev) goto error; - } } } diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c index a5d9300..e5e4aff 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -69,10 +69,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 */ @@ -90,10 +88,8 @@ static int update_driver_name(virNodeDeviceObjPtr dev) p = strrchr(devpath, '/'); if (p) { dev->def->driver = VIR_STRDUP(p+1); - if (!dev->def->driver) { - virReportOOMError(); + if (!dev->def->driver) goto cleanup; - } } ret = 0; @@ -163,7 +159,6 @@ nodeListDevices(virConnectPtr conn, virNodeDeviceHasCap(driver->devs.objs[i], cap)) { if ((names[ndevs++] = VIR_STRDUP(driver->devs.objs[i]->def->name)) == NULL) { virNodeDeviceObjUnlock(driver->devs.objs[i]); - virReportOOMError(); goto failure; } } @@ -322,8 +317,6 @@ nodeDeviceGetParent(virNodeDevicePtr dev) if (obj->def->parent) { ret = VIR_STRDUP(obj->def->parent); - if (!ret) - virReportOOMError(); } else { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("no parent for this device")); @@ -389,10 +382,8 @@ nodeDeviceListCaps(virNodeDevicePtr dev, char **const names, int maxnames) for (caps = obj->def->caps; caps && ncaps < maxnames; caps = caps->next) { names[ncaps] = VIR_STRDUP(virNodeDevCapTypeToString(caps->type)); - if (names[ncaps++] == NULL) { - virReportOOMError(); + if (names[ncaps++] == NULL) goto cleanup; - } } ret = ncaps; @@ -563,10 +554,8 @@ nodeDeviceDestroy(virNodeDevicePtr dev) virNodeDeviceObjUnlock(obj); obj = NULL; - if (parent_name == NULL) { - virReportOOMError(); + if (parent_name == NULL) goto out; - } if (virNodeDeviceGetParentHost(&driver->devs, dev->name, diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c index 02c1205..47c3312 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -129,7 +129,6 @@ static int udevGetDeviceProperty(struct udev_device *udev_device, VIR_ERROR(_("Failed to allocate memory for property value for " "property key '%s' on device with sysname '%s'"), property_key, udev_device_get_sysname(udev_device)); - virReportOOMError(); ret = PROPERTY_ERROR; goto out; } @@ -218,7 +217,6 @@ static int udevGetDeviceSysfsAttr(struct udev_device *udev_device, VIR_ERROR(_("Failed to allocate memory for sysfs attribute value for " "sysfs attribute '%s' on device with sysname '%s'"), attr_name, udev_device_get_sysname(udev_device)); - virReportOOMError(); ret = PROPERTY_ERROR; goto out; } @@ -388,18 +386,14 @@ static int udevTranslatePCIIds(unsigned int vendor, if (vendor_name != NULL) { *vendor_string = VIR_STRDUP(vendor_name); - if (*vendor_string == NULL) { - virReportOOMError(); + if (*vendor_string == NULL) goto out; - } } if (device_name != NULL) { *product_string = VIR_STRDUP(device_name); - if (*product_string == NULL) { - virReportOOMError(); + if (*product_string == NULL) goto out; - } } ret = 0; @@ -691,10 +685,8 @@ static int udevProcessSCSITarget(struct udev_device *device ATTRIBUTE_UNUSED, sysname = udev_device_get_sysname(device); data->scsi_target.name = VIR_STRDUP(sysname); - if (data->scsi_target.name == NULL) { - virReportOOMError(); + if (data->scsi_target.name == NULL) goto out; - } if (udevGenerateDeviceName(device, def, NULL) != 0) { goto out; @@ -755,7 +747,6 @@ static int udevGetSCSIType(virNodeDeviceDefPtr def ATTRIBUTE_UNUSED, if (*typestring == NULL) { if (foundtype == 1) { ret = -1; - virReportOOMError(); } else { VIR_DEBUG("Failed to find SCSI device type %d for %s", type, def->sysfs_path); @@ -917,10 +908,8 @@ static int udevProcessCDROM(struct udev_device *device, * versions of libvirt. */ VIR_FREE(def->caps->data.storage.drive_type); def->caps->data.storage.drive_type = VIR_STRDUP("cdrom"); - if (def->caps->data.storage.drive_type == NULL) { - virReportOOMError(); + if (def->caps->data.storage.drive_type == NULL) goto out; - } if ((udevGetIntProperty(device, "ID_CDROM_MEDIA", &tmp_int, 0) == PROPERTY_FOUND)) @@ -1257,17 +1246,12 @@ static int udevSetParent(struct udev_device *device, def->parent = VIR_STRDUP(dev->def->name); virNodeDeviceObjUnlock(dev); - if (def->parent == NULL) { - virReportOOMError(); + if (def->parent == NULL) goto out; - } def->parent_sysfs_path = VIR_STRDUP(parent_sysfs_path); - if (def->parent_sysfs_path == NULL) { - virReportOOMError(); + if (def->parent_sysfs_path == NULL) goto out; - } - } } while (def->parent == NULL && parent_device != NULL); @@ -1276,10 +1260,8 @@ static int udevSetParent(struct udev_device *device, def->parent = VIR_STRDUP("computer"); } - if (def->parent == NULL) { - virReportOOMError(); + if (def->parent == NULL) goto out; - } ret = 0; @@ -1294,10 +1276,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; - } def->sysfs_path = VIR_STRDUP(udev_device_get_syspath(device)); if (udevGetStringProperty(device, @@ -1306,10 +1286,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; @@ -1570,21 +1548,15 @@ static int udevSetupSystemDev(void) virNodeDeviceObjPtr dev = NULL; int ret = -1; - if (VIR_ALLOC(def) != 0) { - virReportOOMError(); + if (VIR_ALLOC(def) != 0) goto out; - } def->name = VIR_STRDUP("computer"); - if (def->name == NULL) { - virReportOOMError(); + if (def->name == NULL) 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); @@ -1637,7 +1609,6 @@ static int udevDeviceMonitorStartup(bool privileged ATTRIBUTE_UNUSED, #endif if (VIR_ALLOC(priv) < 0) { - virReportOOMError(); ret = -1; goto out; } @@ -1645,7 +1616,6 @@ static int udevDeviceMonitorStartup(bool privileged ATTRIBUTE_UNUSED, priv->watch = -1; if (VIR_ALLOC(driverState) < 0) { - virReportOOMError(); VIR_FREE(priv); ret = -1; goto out; diff --git a/src/nodeinfo.c b/src/nodeinfo.c index 3c073f2..4b1b5d9 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) { @@ -291,10 +287,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]); @@ -475,10 +469,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 */ @@ -493,10 +485,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) @@ -529,10 +519,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) @@ -842,10 +830,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; @@ -979,10 +965,8 @@ int nodeGetMemoryStats(virConnectPtr conn ATTRIBUTE_UNUSED, if (cellNum == VIR_NODE_MEMORY_STATS_ALL_CELLS) { meminfo_path = VIR_STRDUP(MEMINFO_PATH); - if (!meminfo_path) { - virReportOOMError(); + if (!meminfo_path) return -1; - } } else { # if WITH_NUMACTL if (numa_available() < 0) { @@ -1004,10 +988,8 @@ int nodeGetMemoryStats(virConnectPtr conn 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"); @@ -1049,10 +1031,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 */ @@ -1089,10 +1069,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) { @@ -1127,13 +1105,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; } @@ -1164,10 +1140,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 +1212,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; @@ -1481,10 +1453,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; diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c b/src/nwfilter/nwfilter_dhcpsnoop.c index 617c859..a5f385b 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 */ @@ -1093,10 +1087,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 @@ -1106,10 +1098,8 @@ virNWFilterSnoopDHCPOpen(const char *ifname, virMacAddr *mac, * generate much more traffic than if we filtered by VM and * braodcast MAC as well */ - if (virAsprintf(&ext_filter, "%s", filter) < 0) { - virReportOOMError(); + if (virAsprintf(&ext_filter, "%s", filter) < 0) return NULL; - } } handle = pcap_create(ifname, pcap_errbuf); @@ -1199,10 +1189,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; @@ -1635,10 +1623,8 @@ virNWFilterDHCPSnoopReq(virNWFilterTechDriverPtr techdriver, req->vars = virNWFilterHashTableCreate(0); if (!req->ifname || !req->filtername || !req->vars || tmp < 0 || - (linkdev != NULL && req->linkdev == NULL)) { - virReportOOMError(); + (linkdev != NULL && req->linkdev == NULL)) goto exit_snoopreqput; - } /* check that all tools are available for applying the filters (late) */ if (!techdriver->canApplyBasicRules()) { @@ -1783,7 +1769,6 @@ virNWFilterSnoopLeaseFileWrite(int lfd, const char *ifkey, ifkey, ipstr, dhcpstr); if (len < 0) { - virReportOOMError(); ret = -1; goto cleanup; } @@ -2091,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 8567583..eb53b4a 100644 --- a/src/nwfilter/nwfilter_driver.c +++ b/src/nwfilter/nwfilter_driver.c @@ -177,10 +177,8 @@ nwfilterDriverStartup(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; @@ -222,11 +220,11 @@ nwfilterDriverStartup(bool privileged, } if ((base = VIR_STRDUP(SYSCONFDIR "/libvirt")) == NULL) - goto out_of_memory; + goto error; if (virAsprintf(&driverState->configDir, "%s/nwfilter", base) == -1) - goto out_of_memory; + goto error; VIR_FREE(base); @@ -239,9 +237,6 @@ nwfilterDriverStartup(bool privileged, return 0; -out_of_memory: - virReportOOMError(); - error: VIR_FREE(base); nwfilterDriverUnlock(driverState); @@ -456,7 +451,6 @@ nwfilterListNWFilters(virConnectPtr conn, virNWFilterObjLock(driver->nwfilters.objs[i]); if (!(names[got] = VIR_STRDUP(driver->nwfilters.objs[i]->def->name))) { virNWFilterObjUnlock(driver->nwfilters.objs[i]); - virReportOOMError(); goto cleanup; } got++; @@ -495,10 +489,8 @@ nwfilterListAllNWFilters(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 d047174..0f26479 100644 --- a/src/nwfilter/nwfilter_ebiptables_driver.c +++ b/src/nwfilter/nwfilter_ebiptables_driver.c @@ -482,10 +482,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; @@ -2993,10 +2991,8 @@ ebtablesCreateTmpSubChain(ebiptablesRuleInstPtr *inst, break; } - if (!protostr) { - virReportOOMError(); + if (!protostr) return -1; - } virBufferAsprintf(&buf, CMD_DEF("$EBT -t nat -F %s") CMD_SEPARATOR @@ -3370,10 +3366,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; - } } /* @@ -3697,10 +3691,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]), @@ -3713,16 +3705,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; - } } } } @@ -4199,7 +4187,6 @@ ebiptablesDriverInitWithFirewallD(void) if (!ebtables_cmd_path || !iptables_cmd_path || !ip6tables_cmd_path) { - virReportOOMError(); 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 9388e59..522cbba 100644 --- a/src/nwfilter/nwfilter_gentech_driver.c +++ b/src/nwfilter/nwfilter_gentech_driver.c @@ -109,10 +109,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; } @@ -200,10 +198,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); @@ -302,10 +298,8 @@ virNWFilterRuleInstantiate(virNWFilterTechDriverPtr techdriver, int i; virNWFilterRuleInstPtr ret; - if (VIR_ALLOC(ret) < 0) { - virReportOOMError(); + if (VIR_ALLOC(ret) < 0) return NULL; - } ret->techdriver = techdriver; @@ -339,10 +333,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; @@ -414,7 +406,6 @@ _virNWFilterInstantiateRec(virNWFilterTechDriverPtr techdriver, } if (VIR_REALLOC_N(*insts, (*nEntries)+1) < 0) { - virReportOOMError(); rc = -1; break; } @@ -440,7 +431,6 @@ _virNWFilterInstantiateRec(virNWFilterTechDriverPtr techdriver, virNWFilterCreateVarsFrom(inc->params, vars); if (!tmpvars) { - virReportOOMError(); rc = -1; virNWFilterObjUnlock(obj); break; @@ -552,7 +542,6 @@ virNWFilterDetermineMissingVarsRec(virNWFilterDefPtr filter, virNWFilterCreateVarsFrom(inc->params, vars); if (!tmpvars) { - virReportOOMError(); rc = -1; virNWFilterObjUnlock(obj); break; @@ -610,10 +599,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; @@ -673,7 +660,6 @@ virNWFilterInstantiate(const unsigned char *vmuuid ATTRIBUTE_UNUSED, virNWFilterHashTablePtr missing_vars = virNWFilterHashTableCreate(0); if (!missing_vars) { - virReportOOMError(); rc = -1; goto err_exit; } @@ -868,7 +854,6 @@ __virNWFilterInstantiateFilter(const unsigned char *vmuuid, virMacAddrFormat(macaddr, vmmacaddr); str_macaddr = VIR_STRDUP(vmmacaddr); if (!str_macaddr) { - virReportOOMError(); rc = -1; goto err_exit; } diff --git a/src/nwfilter/nwfilter_learnipaddr.c b/src/nwfilter/nwfilter_learnipaddr.c index 9bc9cc8..cf3d1b6 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", @@ -681,25 +679,19 @@ 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; req->filtername = VIR_STRDUP(filtername); - if (req->filtername == NULL) { - virReportOOMError(); + if (req->filtername == NULL) goto err_free_ht; - } if (virStrcpyStatic(req->ifname, ifname) == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c index 95e9167..aa45ed3 100644 --- a/src/openvz/openvz_conf.c +++ b/src/openvz/openvz_conf.c @@ -138,10 +138,8 @@ openvzParseBarrierLimit(const char* value, char *saveptr = NULL; char *str = VIR_STRDUP(value); - if (str == NULL) { - virReportOOMError(); + if (str == NULL) goto error; - } token = strtok_r(str, ":", &saveptr); if (token == NULL) { @@ -217,7 +215,8 @@ no_memory: int openvzReadNetworkConf(virDomainDefPtr def, - int veid) { + int veid) +{ int ret; virDomainNetDefPtr net = NULL; char *temp = NULL; @@ -238,16 +237,16 @@ 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; net->data.ethernet.ipaddr = VIR_STRDUP(token); if (net->data.ethernet.ipaddr == NULL) - goto no_memory; + goto error; if (VIR_REALLOC_N(def->nets, def->nnets + 1) < 0) - goto no_memory; + goto error; def->nets[def->nnets++] = net; net = NULL; @@ -271,7 +270,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; @@ -294,7 +293,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, @@ -311,7 +310,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, @@ -341,7 +340,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; @@ -352,8 +351,6 @@ openvzReadNetworkConf(virDomainDefPtr def, VIR_FREE(temp); return 0; -no_memory: - virReportOOMError(); error: VIR_FREE(temp); virDomainNetDefFree(net); @@ -397,7 +394,8 @@ openvz_replace(const char* str, static int openvzReadFSConf(virDomainDefPtr def, - int veid) { + int veid) +{ int ret; virDomainFSDefPtr fs = NULL; char *veid_str = NULL; @@ -413,7 +411,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; fs->src = VIR_STRDUP(temp); @@ -428,10 +426,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; fs->src = openvz_replace(temp, "$VEID", veid_str); @@ -462,19 +460,19 @@ openvzReadFSConf(virDomainDefPtr def, } } - if (fs->src == NULL || fs->dst == NULL) - goto no_memory; + if (fs->src == NULL || fs->dst == NULL) { + virReportOOMError(); + goto error; + } if (VIR_REALLOC_N(def->fss, def->nfss + 1) < 0) - goto no_memory; + goto error; def->fss[def->nfss++] = fs; fs = NULL; VIR_FREE(temp); return 0; -no_memory: - virReportOOMError(); error: VIR_FREE(temp); virDomainFSDefFree(fs); @@ -566,7 +564,8 @@ openvzFreeDriver(struct openvz_driver *driver) -int openvzLoadDomains(struct openvz_driver *driver) { +int openvzLoadDomains(struct openvz_driver *driver) +{ int veid, ret; char *status; char uuidstr[VIR_UUID_STRING_BUFLEN]; @@ -598,7 +597,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; @@ -607,7 +606,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); @@ -619,9 +618,9 @@ int openvzLoadDomains(struct openvz_driver *driver) { } if (!(def->os.type = VIR_STRDUP("exe"))) - goto no_memory; + goto cleanup; if (!(def->os.init = VIR_STRDUP("/sbin/init"))) - goto no_memory; + goto cleanup; ret = openvzReadVPSConfigParam(veid, "CPUS", &temp); if (ret < 0) { @@ -678,10 +677,7 @@ int openvzLoadDomains(struct openvz_driver *driver) { return 0; - no_memory: - virReportOOMError(); - - cleanup: +cleanup: virCommandFree(cmd); VIR_FREE(temp); VIR_FREE(outbuf); @@ -710,10 +706,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) @@ -915,10 +909,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; @@ -949,10 +941,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 848cf00..cae277d 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -320,8 +320,7 @@ static char *openvzGetOSType(virDomainPtr dom) goto cleanup; } - if (!(ret = VIR_STRDUP(vm->def->os.type))) - virReportOOMError(); + ret = VIR_STRDUP(vm->def->os.type); cleanup: if (vm) @@ -758,10 +757,6 @@ openvzGenerateContainerVethName(int veid) VIR_FREE(temp); - if (name == NULL) { - virReportOOMError(); - } - return name; } @@ -1442,10 +1437,8 @@ static virDrvOpenStatus openvzOpen(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; @@ -1591,10 +1584,8 @@ static int openvzListDefinedDomains(virConnectPtr conn ATTRIBUTE_UNUSED, continue; } snprintf(vpsname, sizeof(vpsname), "%d", veid); - if (!(names[got] = VIR_STRDUP(vpsname))) { - virReportOOMError(); + if (!(names[got] = VIR_STRDUP(vpsname))) goto out; - } got ++; } diff --git a/src/parallels/parallels_driver.c b/src/parallels/parallels_driver.c index d683200..694d064 100644 --- a/src/parallels/parallels_driver.c +++ b/src/parallels/parallels_driver.c @@ -156,7 +156,6 @@ parallelsBuildCapabilities(void) return caps; no_memory: - virReportOOMError(); virObjectUnref(caps); return NULL; } @@ -230,7 +229,6 @@ parallelsGetSerialInfo(virDomainChrDefPtr chr, return 0; no_memory: - virReportOOMError(); return -1; } @@ -241,20 +239,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; @@ -303,7 +299,6 @@ parallelsAddVideoInfo(virDomainDefPtr def, virJSONValuePtr value) return 0; no_memory: - virReportOOMError(); VIR_FREE(accel); virDomainVideoDefFree(video); error: @@ -329,10 +324,8 @@ parallelsGetHddInfo(virDomainDefPtr def, return -1; } - if (!(disk->src = VIR_STRDUP(tmp))) { - virReportOOMError(); + if (!(disk->src = VIR_STRDUP(tmp))) return -1; - } } else { disk->type = VIR_DOMAIN_DISK_TYPE_FILE; @@ -341,10 +334,8 @@ parallelsGetHddInfo(virDomainDefPtr def, return -1; } - if (!(disk->src = VIR_STRDUP(tmp))) { - virReportOOMError(); + if (!(disk->src = VIR_STRDUP(tmp))) return -1; - } } tmp = virJSONValueObjectGetString(value, "port"); @@ -404,20 +395,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; @@ -465,10 +454,8 @@ parallelsGetNetInfo(virDomainNetDefPtr net, /* use device name, shown by prlctl as target device * for identifying network adapter in virDomainDefineXML */ - if (!(net->ifname = VIR_STRDUP(key))) { - virReportOOMError(); + if (!(net->ifname = VIR_STRDUP(key))) goto error; - } net->type = VIR_DOMAIN_NET_TYPE_NETWORK; @@ -489,10 +476,8 @@ parallelsGetNetInfo(virDomainNetDefPtr net, goto error; } - if (!(net->data.network.name = VIR_STRDUP(tmp))) { - virReportOOMError(); + if (!(net->data.network.name = VIR_STRDUP(tmp))) goto error; - } } else if (virJSONValueObjectHasKey(value, "type")) { if (!(tmp = virJSONValueObjectGetString(value, "type"))) { parallelsParseError(); @@ -504,10 +489,8 @@ parallelsGetNetInfo(virDomainNetDefPtr net, goto error; } - if (!(net->data.network.name = VIR_STRDUP(PARALLELS_ROUTED_NETWORK_NAME))) { - virReportOOMError(); + if (!(net->data.network.name = VIR_STRDUP(PARALLELS_ROUTED_NETWORK_NAME))) goto error; - } } else { parallelsParseError(); goto error; @@ -531,20 +514,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; @@ -620,7 +601,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) @@ -648,24 +629,22 @@ parallelsAddVNCInfo(virDomainDefPtr def, virJSONValuePtr jobj_root) } if (VIR_ALLOC(gr->listens) < 0) - goto no_memory; + goto cleanup; gr->nListens = 1; if (!(gr->listens[0].address = VIR_STRDUP(tmp))) - goto no_memory; + goto cleanup; 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: +cleanup: virDomainGraphicsDefFree(gr); return ret; } @@ -688,7 +667,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; @@ -698,7 +677,7 @@ parallelsLoadDomain(parallelsConnPtr privconn, virJSONValuePtr jobj) goto cleanup; } if (!(def->name = VIR_STRDUP(tmp))) - goto no_memory; + goto cleanup; if (!(tmp = virJSONValueObjectGetString(jobj, "ID"))) { parallelsParseError(); @@ -716,7 +695,7 @@ parallelsLoadDomain(parallelsConnPtr privconn, virJSONValuePtr jobj) goto cleanup; } if (!(def->description = VIR_STRDUP(tmp))) - goto no_memory; + goto cleanup; if (!(jobj2 = virJSONValueObjectGet(jobj, "Hardware"))) { parallelsParseError(); @@ -783,18 +762,18 @@ parallelsLoadDomain(parallelsConnPtr privconn, virJSONValuePtr jobj) if (STREQ(tmp, "CT")) { if (!(def->os.type = VIR_STRDUP("exe"))) - goto no_memory; + goto cleanup; if (!(def->os.init = VIR_STRDUP("/sbin/init"))) - goto no_memory; + goto cleanup; } else if (STREQ(tmp, "VM")) { if (!(def->os.type = VIR_STRDUP("hvm"))) - goto no_memory; + goto cleanup; } 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; @@ -804,7 +783,7 @@ parallelsLoadDomain(parallelsConnPtr privconn, virJSONValuePtr jobj) goto cleanup; } if (!(pdom->uuid = VIR_STRDUP(tmp))) - goto no_memory; + goto cleanup; if (!(tmp = virJSONValueObjectGetString(jobj, "Home"))) { parallelsParseError(); @@ -812,7 +791,7 @@ parallelsLoadDomain(parallelsConnPtr privconn, virJSONValuePtr jobj) } if (!(pdom->home = VIR_STRDUP(tmp))) - goto no_memory; + goto cleanup; if (!(state = virJSONValueObjectGetString(jobj, "State"))) { parallelsParseError(); @@ -856,9 +835,7 @@ parallelsLoadDomain(parallelsConnPtr privconn, virJSONValuePtr jobj) return dom; - no_memory: - virReportOOMError(); - cleanup: +cleanup: virDomainDefFree(def); parallelsDomObjFreePrivate(pdom); return NULL; @@ -916,10 +893,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")); @@ -1243,10 +1218,9 @@ parallelsGetOSType(virDomainPtr domain) goto cleanup; } - if (!(ret = VIR_STRDUP(privdom->def->os.type))) - virReportOOMError(); + ret = VIR_STRDUP(privdom->def->os.type); - cleanup: +cleanup: if (privdom) virObjectUnlock(privdom); parallelsDriverUnlock(privconn); @@ -1806,10 +1780,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 2a88108..3096c5a 100644 --- a/src/parallels/parallels_network.c +++ b/src/parallels/parallels_network.c @@ -55,26 +55,20 @@ 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); goto cleanup; } - if (!(def->bridge = VIR_STRDUP(basename(bridgePath)))) { - virReportOOMError(); + if (!(def->bridge = VIR_STRDUP(basename(bridgePath)))) 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 +106,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); @@ -129,10 +121,8 @@ static int parallelsGetHostOnlyNetInfo(virNetworkDefPtr def, const char *name) goto cleanup; } - if (!(def->ips[0].family = VIR_STRDUP("ipv4"))) { - virReportOOMError(); + if (!(def->ips[0].family = VIR_STRDUP("ipv4"))) goto cleanup; - }; if (!(tmp = virJSONValueObjectGetString(jobj2, "IP address"))) { parallelsParseError(); goto cleanup; @@ -158,10 +148,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(); @@ -199,7 +187,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(); @@ -207,7 +195,7 @@ parallelsLoadNetwork(parallelsConnPtr privconn, virJSONValuePtr jobj) } if (!(def->name = VIR_STRDUP(tmp))) - goto no_memory; + goto cleanup; /* Network names are unique in Parallels Cloud Server, so we can make * an UUID from it */ @@ -245,8 +233,6 @@ parallelsLoadNetwork(parallelsConnPtr privconn, virJSONValuePtr jobj) virNetworkObjUnlock(net); return net; -no_memory: - virReportOOMError(); cleanup: virNetworkDefFree(def); return NULL; @@ -259,12 +245,12 @@ parallelsAddRoutedNetwork(parallelsConnPtr privconn) virNetworkDefPtr def; if (VIR_ALLOC(def) < 0) - goto no_memory; + goto cleanup; def->forward.type = VIR_NETWORK_FORWARD_ROUTE; if (!(def->name = VIR_STRDUP(PARALLELS_ROUTED_NETWORK_NAME))) - goto no_memory; + goto cleanup; if (virUUIDParse(PARALLELS_ROUTED_NETWORK_UUID, def->uuid) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -284,8 +270,6 @@ parallelsAddRoutedNetwork(parallelsConnPtr privconn) return net; -no_memory: - virReportOOMError(); cleanup: virNetworkDefFree(def); return NULL; @@ -391,7 +375,6 @@ static int parallelsListNetworks(virConnectPtr conn, if (virNetworkObjIsActive(privconn->networks.objs[i])) { if (!(names[got] = VIR_STRDUP(privconn->networks.objs[i]->def->name))) { virNetworkObjUnlock(privconn->networks.objs[i]); - virReportOOMError(); goto cleanup; } got++; @@ -439,7 +422,6 @@ static int parallelsListDefinedNetworks(virConnectPtr conn, if (!virNetworkObjIsActive(privconn->networks.objs[i])) { if (!(names[got] = VIR_STRDUP(privconn->networks.objs[i]->def->name))) { virNetworkObjUnlock(privconn->networks.objs[i]); - virReportOOMError(); goto cleanup; } got++; diff --git a/src/parallels/parallels_storage.c b/src/parallels/parallels_storage.c index dbe312b..17d54f4 100644 --- a/src/parallels/parallels_storage.c +++ b/src/parallels/parallels_storage.c @@ -105,10 +105,8 @@ parallelsFindVolumes(virStoragePoolObjPtr pool) continue; if (!(path = virFileBuildPath(pool->def->target.path, - ent->d_name, NULL))) { - virReportOOMError(); + ent->d_name, NULL))) goto cleanup; - } if (!parallelsStorageVolumeDefine(pool, NULL, path, false)) goto cleanup; @@ -136,20 +134,16 @@ static char *parallelsMakePoolName(virConnectPtr conn, const char *path) bool found = false; int j; - if (!(name = VIR_STRDUP(path))) { - virReportOOMError(); + if (!(name = VIR_STRDUP(path))) return NULL; - } if (i == 0) name = VIR_STRDUP(path); else ignore_value(virAsprintf(&name, "%s-%u", path, i)); - if (!name) { - virReportOOMError(); + if (!name) return 0; - } for (j = 0; j < strlen(name); j++) if (name[j] == '/') @@ -180,13 +174,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", @@ -208,8 +202,6 @@ parallelsPoolCreateByPath(virConnectPtr conn, const char *path) virStoragePoolObjUnlock(pool); return pool; -no_memory: - virReportOOMError(); error: virStoragePoolDefFree(def); if (pool) @@ -231,10 +223,8 @@ parallelsPoolAddByDomain(virConnectPtr conn, virDomainObjPtr dom) virStoragePoolObjPtr pool = NULL; int j; - if (!(poolPath = VIR_STRDUP(pdom->home))) { - virReportOOMError(); + if (!(poolPath = VIR_STRDUP(pdom->home))) return NULL; - } poolPath = dirname(poolPath); @@ -312,10 +302,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; @@ -323,19 +313,17 @@ static int parallelsAddDiskVolume(virStoragePoolObjPtr pool, goto error; if (!(def->target.path = realpath(diskPath, NULL))) - goto no_memory; + goto error; if (!(def->key = VIR_STRDUP(def->target.path))) - goto no_memory; + 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; return 0; -no_memory: - virReportOOMError(); error: virStorageVolDefFree(def); return -1; @@ -362,10 +350,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, @@ -378,10 +364,8 @@ static int parallelsFindVmVolumes(virStoragePoolObjPtr pool, continue; if (!(diskDescPath = virFileBuildPath(diskPath, - "DiskDescriptor", ".xml"))) { - virReportOOMError(); + "DiskDescriptor", ".xml"))) goto cleanup; - } if (access(diskDescPath, F_OK)) continue; @@ -427,16 +411,16 @@ static int parallelsLoadPools(virConnectPtr conn) size_t i; if ((base = VIR_STRDUP(SYSCONFDIR "/libvirt")) == NULL) - goto out_of_memory; + goto error; /* 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); @@ -469,8 +453,6 @@ static int parallelsLoadPools(virConnectPtr conn) return 0; -out_of_memory: - virReportOOMError(); error: VIR_FREE(base); return -1; @@ -487,10 +469,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); @@ -552,7 +532,6 @@ parallelsStorageListPools(virConnectPtr conn, char **const names, int nnames) return n; no_memory: - virReportOOMError(); for (n = 0; n < nnames; n++) VIR_FREE(names[n]); parallelsDriverUnlock(privconn); @@ -602,7 +581,6 @@ parallelsStorageListDefinedPools(virConnectPtr conn, return n; no_memory: - virReportOOMError(); for (n = 0; n < nnames; n++) VIR_FREE(names[n]); parallelsDriverUnlock(privconn); @@ -760,10 +738,8 @@ parallelsStoragePoolDefine(virConnectPtr conn, def = NULL; pool->configFile = VIR_STRDUP("\0"); - if (!pool->configFile) { - virReportOOMError(); + if (!pool->configFile) goto cleanup; - } ret = virGetStoragePool(conn, pool->def->name, pool->def->uuid, NULL, NULL); @@ -1086,10 +1062,8 @@ parallelsStoragePoolListVolumes(virStoragePoolPtr pool, } for (i = 0; i < privpool->volumes.count && n < maxnames; i++) { - if ((names[n++] = VIR_STRDUP(privpool->volumes.objs[i]->name)) == NULL) { - virReportOOMError(); + if ((names[n++] = VIR_STRDUP(privpool->volumes.objs[i]->name)) == NULL) goto error; - } } virStoragePoolObjUnlock(privpool); @@ -1261,22 +1235,16 @@ parallelsStorageVolumeDefine(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; - } privvol->key = VIR_STRDUP(privvol->target.path); - if (privvol->key == NULL) { - virReportOOMError(); + if (privvol->key == NULL) goto cleanup; - } if (is_new) { xml_path = parallelsAddFileExt(privvol->target.path, ".xml"); @@ -1402,22 +1370,16 @@ parallelsStorageVolumeCreateXMLFrom(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; - } privvol->key = VIR_STRDUP(privvol->target.path); - if (privvol->key == NULL) { - virReportOOMError(); + if (privvol->key == NULL) goto cleanup; - } privpool->def->allocation += privvol->allocation; privpool->def->available = (privpool->def->capacity - @@ -1661,8 +1623,6 @@ parallelsStorageVolumeGetPath(virStorageVolPtr vol) } ret = VIR_STRDUP(privvol->target.path); - if (ret == NULL) - virReportOOMError(); cleanup: if (privpool) diff --git a/src/parallels/parallels_utils.c b/src/parallels/parallels_utils.c index 08264ff..3b40dbf 100644 --- a/src/parallels/parallels_utils.c +++ b/src/parallels/parallels_utils.c @@ -131,10 +131,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); diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index b6908da..1800fb9 100644 --- a/src/phyp/phyp_driver.c +++ b/src/phyp/phyp_driver.c @@ -119,10 +119,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 && @@ -268,10 +266,8 @@ phypGetSystemType(virConnectPtr conn) char *ret = NULL; int exit_status = 0; - if (virAsprintf(&cmd, "lshmc -V") < 0) { - virReportOOMError(); + if (virAsprintf(&cmd, "lshmc -V") < 0) return -1; - } ret = phypExec(session, cmd, &exit_status, conn); VIR_FREE(cmd); @@ -504,10 +500,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."); @@ -608,15 +602,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); @@ -655,10 +645,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 @@ -672,8 +660,7 @@ phypUUIDTable_ReadFile(virConnectPtr conn) goto err; } } - } else - virReportOOMError(); + } VIR_FORCE_CLOSE(fd); return 0; @@ -702,10 +689,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 { @@ -799,10 +784,8 @@ phypUUIDTable_Init(virConnectPtr conn) if ((nids_numdomains = phypNumDomainsGeneric(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 = phypListDomainsGeneric(conn, ids, nids_numdomains, 1)) < 0) @@ -828,10 +811,8 @@ 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) @@ -839,7 +820,6 @@ phypUUIDTable_Init(virConnectPtr conn) ids[i]); } } else { - virReportOOMError(); goto cleanup; } @@ -918,10 +898,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]) { @@ -959,23 +937,17 @@ 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) { username = VIR_STRDUP(conn->uri->user); - if (username == NULL) { - virReportOOMError(); + if (username == NULL) goto err; - } } else { if (auth == NULL || auth->cb == NULL) { virReportError(VIR_ERR_AUTH_FAILED, @@ -1139,20 +1111,14 @@ phypOpen(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) { @@ -1162,10 +1128,8 @@ phypOpen(virConnectPtr conn, else managed_system = VIR_STRDUP(conn->uri->path); - if (!managed_system) { - virReportOOMError(); + if (!managed_system) goto failure; - } /* here we are handling only the first component of the path, * so skipping the second: @@ -1199,10 +1163,8 @@ phypOpen(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->xmlconf = virDomainXMLConfNew(NULL, NULL))) goto failure; @@ -1516,10 +1478,8 @@ phypGetBackingDevice(virConnectPtr conn, const char *managed_system, backing_device = VIR_STRDUP(char_ptr); - if (backing_device == NULL) { - virReportOOMError(); + if (backing_device == NULL) goto cleanup; - } } else { backing_device = ret; ret = NULL; @@ -1736,10 +1696,8 @@ phypAttachDevice(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); @@ -1749,10 +1707,8 @@ phypAttachDevice(virDomainPtr domain, const char *xml) def->os.type = VIR_STRDUP("aix"); - if (def->os.type == NULL) { - virReportOOMError(); + if (def->os.type == NULL) goto cleanup; - } dev = virDomainDeviceDefParse(phyp_driver->caps, def, xml, VIR_DOMAIN_XML_INACTIVE); @@ -2030,10 +1986,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 * */ @@ -2299,10 +2253,8 @@ phypVolumeGetXMLDesc(virStorageVolPtr vol, unsigned int flags) voldef.key = VIR_STRDUP(vol->key); - if (voldef.key == NULL) { - virReportOOMError(); + if (voldef.key == NULL) goto cleanup; - } voldef.type = VIR_STORAGE_POOL_LOGICAL; @@ -2360,10 +2312,8 @@ phypVolumeGetPath(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); @@ -2415,10 +2365,8 @@ phypStoragePoolListVolumes(virStoragePoolPtr pool, char **const volumes, if (char_ptr) { *char_ptr = '\0'; - if ((volumes[got++] = VIR_STRDUP(volumes_list)) == NULL) { - virReportOOMError(); + if ((volumes[got++] = VIR_STRDUP(volumes_list)) == NULL) goto cleanup; - } char_ptr++; volumes_list = char_ptr; } else @@ -2609,10 +2557,8 @@ phypListStoragePools(virConnectPtr conn, char **const pools, int npools) if (char_ptr) { *char_ptr = '\0'; - if ((pools[got++] = VIR_STRDUP(storage_pools)) == NULL) { - virReportOOMError(); + if ((pools[got++] = VIR_STRDUP(storage_pools)) == NULL) goto cleanup; - } char_ptr++; storage_pools = char_ptr; } else @@ -2644,20 +2590,16 @@ phypGetStoragePoolLookUpByUUID(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 = phypNumOfStoragePools(conn)) == -1) { virReportOOMError(); goto err; } - if (VIR_ALLOC_N(pools, npools) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(pools, npools) < 0) goto err; - } if ((gotpools = phypListStoragePools(conn, pools, npools)) == -1) { virReportOOMError(); @@ -3076,10 +3018,8 @@ phypListInterfaces(virConnectPtr conn, char **const names, int nnames) if (char_ptr) { *char_ptr = '\0'; - if ((names[got++] = VIR_STRDUP(networks)) == NULL) { - virReportOOMError(); + if ((names[got++] = VIR_STRDUP(networks)) == NULL) goto cleanup; - } char_ptr++; networks = char_ptr; } else { @@ -3243,10 +3183,8 @@ phypListDefinedDomains(virConnectPtr conn, char **const names, int nnames) if (char_ptr) { *char_ptr = '\0'; - if ((names[got++] = VIR_STRDUP(domains)) == NULL) { - virReportOOMError(); + if ((names[got++] = VIR_STRDUP(domains)) == NULL) goto cleanup; - } char_ptr++; domains = char_ptr; } else diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index bb5d51d..129e5aa 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 :-) */ @@ -1216,19 +1210,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); diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 4a43800..ec852ab 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -375,7 +375,7 @@ virQEMUCapsParseMachineTypesStr(const char *output, VIR_REALLOC_N(qemuCaps->machineAliases, qemuCaps->nmachineTypes + 1) < 0) { VIR_FREE(name); VIR_FREE(canonical); - goto no_memory; + goto error; } qemuCaps->nmachineTypes++; if (canonical) { @@ -395,6 +395,7 @@ virQEMUCapsParseMachineTypesStr(const char *output, no_memory: virReportOOMError(); +error: return -1; } @@ -475,10 +476,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; @@ -536,10 +535,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; @@ -602,10 +599,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); @@ -822,10 +817,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; @@ -1487,10 +1480,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 (!(typelist[ntypelist-1] = strndup(tmp, end-tmp))) { virReportOOMError(); goto cleanup; @@ -1544,10 +1535,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 (!(proplist[nproplist-1] = strndup(tmp, end-tmp))) { virReportOOMError(); goto cleanup; @@ -1692,7 +1681,6 @@ virQEMUCapsNew(void) return qemuCaps; no_memory: - virReportOOMError(); virObjectUnref(qemuCaps); return NULL; } @@ -1737,7 +1725,6 @@ virQEMUCapsPtr virQEMUCapsNewCopy(virQEMUCapsPtr qemuCaps) return ret; no_memory: - virReportOOMError(); virObjectUnref(ret); return NULL; } @@ -1840,13 +1827,10 @@ int virQEMUCapsAddCPUDefinition(virQEMUCapsPtr qemuCaps, const char *name) { char *tmp = VIR_STRDUP(name); - if (!tmp) { - virReportOOMError(); + if (!tmp) return -1; - } if (VIR_EXPAND_N(qemuCaps->cpuDefinitions, qemuCaps->ncpuDefinitions, 1) < 0) { VIR_FREE(tmp); - virReportOOMError(); return -1; } qemuCaps->cpuDefinitions[qemuCaps->ncpuDefinitions-1] = tmp; @@ -2072,26 +2056,18 @@ 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; - } for (i = 0 ; i < nmachines ; i++) { if (machines[i]->alias) { - if (!(qemuCaps->machineAliases[i] = VIR_STRDUP(machines[i]->alias))) { - virReportOOMError(); + if (!(qemuCaps->machineAliases[i] = VIR_STRDUP(machines[i]->alias))) goto cleanup; - } } - if (!(qemuCaps->machineTypes[i] = VIR_STRDUP(machines[i]->name))) { - virReportOOMError(); + if (!(qemuCaps->machineTypes[i] = VIR_STRDUP(machines[i]->name))) goto cleanup; - } if (machines[i]->isDefault) defIdx = i; } @@ -2342,14 +2318,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" @@ -2357,10 +2329,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; @@ -2518,7 +2488,7 @@ virQEMUCapsPtr virQEMUCapsNewForBinary(const char *binary, int rv; if (!(qemuCaps->binary = VIR_STRDUP(binary))) - goto no_memory; + goto error; /* We would also want to check faccessat if we cared about ACLs, * but we don't. */ @@ -2548,8 +2518,6 @@ virQEMUCapsPtr virQEMUCapsNewForBinary(const char *binary, return qemuCaps; -no_memory: - virReportOOMError(); error: virObjectUnref(qemuCaps); qemuCaps = NULL; @@ -2585,10 +2553,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", @@ -2599,10 +2565,8 @@ virQEMUCapsCacheNew(const char *libDir, if (!(cache->binaries = virHashCreate(10, virQEMUCapsHashDataFree))) goto error; - if (!(cache->libDir = VIR_STRDUP(libDir))) { - virReportOOMError(); + if (!(cache->libDir = VIR_STRDUP(libDir))) goto error; - } cache->runUid = runUid; cache->runGid = runGid; diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index baf6175..584bf35 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -241,10 +241,8 @@ qemuNetworkIfaceConnect(virDomainDefPtr def, return -1; } else if (actualType == VIR_DOMAIN_NET_TYPE_BRIDGE) { - if (!(brname = VIR_STRDUP(virDomainNetGetActualBridgeName(net)))) { - virReportOOMError(); + if (!(brname = VIR_STRDUP(virDomainNetGetActualBridgeName(net)))) return -1; - } } else { virReportError(VIR_ERR_INTERNAL_ERROR, _("Network type %d is not supported"), @@ -256,10 +254,8 @@ qemuNetworkIfaceConnect(virDomainDefPtr def, STRPREFIX(net->ifname, VIR_NET_GENERATED_PREFIX) || strchr(net->ifname, '%')) { VIR_FREE(net->ifname); - if (!(net->ifname = VIR_STRDUP(VIR_NET_GENERATED_PREFIX "%d"))) { - virReportOOMError(); + if (!(net->ifname = VIR_STRDUP(VIR_NET_GENERATED_PREFIX "%d"))) goto cleanup; - } /* avoid exposing vnet%d in getXMLDesc or error outputs */ template_ifname = true; } @@ -405,10 +401,8 @@ static int qemuAssignDeviceDiskAliasLegacy(virDomainDiskDefPtr disk) else dev_name = VIR_STRDUP(disk->dst); - if (!dev_name) { - virReportOOMError(); + if (!dev_name) return -1; - } disk->info.alias = dev_name; return 0; @@ -421,15 +415,11 @@ 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(); + if (virAsprintf(&ret, "%s%s", QEMU_DRIVE_HOST_PREFIX, disk->info.alias) < 0) return NULL; - } } else { - if (!(ret = VIR_STRDUP(disk->info.alias))) { - virReportOOMError(); + if (!(ret = VIR_STRDUP(disk->info.alias))) return NULL; - } } return ret; } @@ -478,10 +468,8 @@ static int qemuAssignDeviceDiskAliasFixed(virDomainDiskDefPtr disk) return -1; } - if (ret == -1) { - virReportOOMError(); + if (ret == -1) return -1; - } disk->info.alias = dev_name; @@ -587,7 +575,6 @@ qemuAssignDeviceDiskAliasCustom(virDomainDefPtr def, return 0; no_memory: - virReportOOMError(); return -1; } @@ -631,10 +618,8 @@ qemuAssignDeviceNetAlias(virDomainDefPtr def, virDomainNetDefPtr net, int idx) } } - if (virAsprintf(&net->info.alias, "net%d", idx) < 0) { - virReportOOMError(); + if (virAsprintf(&net->info.alias, "net%d", idx) < 0) return -1; - } return 0; } @@ -658,10 +643,8 @@ qemuAssignDeviceHostdevAlias(virDomainDefPtr def, virDomainHostdevDefPtr hostdev } } - if (virAsprintf(&hostdev->info->alias, "hostdev%d", idx) < 0) { - virReportOOMError(); + if (virAsprintf(&hostdev->info->alias, "hostdev%d", idx) < 0) return -1; - } return 0; } @@ -685,10 +668,8 @@ qemuAssignDeviceRedirdevAlias(virDomainDefPtr def, virDomainRedirdevDefPtr redir } } - if (virAsprintf(&redirdev->info.alias, "redir%d", idx) < 0) { - virReportOOMError(); + if (virAsprintf(&redirdev->info.alias, "redir%d", idx) < 0) return -1; - } return 0; } @@ -700,10 +681,8 @@ qemuAssignDeviceControllerAlias(virDomainControllerDefPtr controller) const char *prefix = virDomainControllerTypeToString(controller->type); if (virAsprintf(&controller->info.alias, "%s%d", prefix, - controller->idx) < 0) { - virReportOOMError(); + controller->idx) < 0) return -1; - } return 0; } @@ -802,7 +781,6 @@ qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps) return 0; no_memory: - virReportOOMError(); return -1; } @@ -818,14 +796,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; } @@ -1006,7 +980,7 @@ qemuDomainCCWAddressSetCreate(void) qemuDomainCCWAddressSetPtr addrs = NULL; if (VIR_ALLOC(addrs) < 0) - goto no_memory; + goto cleanup; if (!(addrs->defined = virHashCreate(10, qemuDomainCCWAddressSetFreeEntry))) goto cleanup; @@ -1018,8 +992,6 @@ qemuDomainCCWAddressSetCreate(void) addrs->next.assigned = 0; return addrs; -no_memory: - virReportOOMError(); cleanup: qemuDomainCCWAddressSetFree(addrs); return addrs; @@ -1194,7 +1166,7 @@ struct _qemuDomainPCIAddressSet { static char *qemuPCIAddressAsString(virDevicePCIAddressPtr addr) { - char *str; + char *str = NULL; if (addr->domain != 0 || addr->bus != 0) { @@ -1203,14 +1175,11 @@ static char *qemuPCIAddressAsString(virDevicePCIAddressPtr addr) return NULL; } - if (virAsprintf(&str, "%d:%d:%d.%d", - addr->domain, - addr->bus, - addr->slot, - addr->function) < 0) { - virReportOOMError(); - return NULL; - } + ignore_value(virAsprintf(&str, "%d:%d:%d.%d", + addr->domain, + addr->bus, + addr->slot, + addr->function)); return str; } @@ -1356,7 +1325,7 @@ qemuDomainPCIAddressSetPtr qemuDomainPCIAddressSetCreate(virDomainDefPtr def) qemuDomainPCIAddressSetPtr addrs; if (VIR_ALLOC(addrs) < 0) - goto no_memory; + goto error; if (!(addrs->used = virHashCreate(10, qemuDomainPCIAddressSetFreeEntry))) goto error; @@ -1366,8 +1335,6 @@ qemuDomainPCIAddressSetPtr qemuDomainPCIAddressSetCreate(virDomainDefPtr def) return addrs; -no_memory: - virReportOOMError(); error: qemuDomainPCIAddressSetFree(addrs); return NULL; @@ -2224,7 +2191,6 @@ static int qemuAddRBDHost(virDomainDiskDefPtr disk, char *hostport) return 0; no_memory: - virReportOOMError(); VIR_FREE(disk->hosts[disk->nhosts-1].port); VIR_FREE(disk->hosts[disk->nhosts-1].name); return -1; @@ -2298,7 +2264,6 @@ static int qemuParseRBDString(virDomainDiskDefPtr disk) no_memory: VIR_FREE(options); - virReportOOMError(); return -1; } @@ -2313,7 +2278,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) @@ -2340,10 +2305,10 @@ qemuParseDriveURIString(virDomainDiskDefPtr def, virURIPtr uri, if (def->hosts->transport != VIR_DOMAIN_DISK_PROTO_TRANS_UNIX) { def->hosts->name = VIR_STRDUP(uri->server); if (!def->hosts->name) - goto no_memory; + 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; @@ -2352,7 +2317,7 @@ qemuParseDriveURIString(virDomainDiskDefPtr def, virURIPtr uri, sock = strchr(uri->query, '=') + 1; def->hosts->socket = VIR_STRDUP(sock); if (!def->hosts->socket) - goto no_memory; + goto error; } else { virReportError(VIR_ERR_INTERNAL_ERROR, _("Invalid query parameter '%s'"), uri->query); @@ -2365,7 +2330,7 @@ qemuParseDriveURIString(virDomainDiskDefPtr def, virURIPtr uri, VIR_FREE(def->src); def->src = VIR_STRDUP(volimg); if (!def->src) - goto no_memory; + goto error; } else { VIR_FREE(def->src); def->src = NULL; @@ -2378,7 +2343,7 @@ qemuParseDriveURIString(virDomainDiskDefPtr def, virURIPtr uri, def->auth.username = VIR_STRDUP(uri->user); if (!def->auth.username) - goto no_memory; + goto error; } def->nhosts = 1; @@ -2386,11 +2351,8 @@ qemuParseDriveURIString(virDomainDiskDefPtr def, virURIPtr uri, cleanup: virURIFree(uri); - return ret; -no_memory: - virReportOOMError(); error: virDomainDiskHostDefFree(def->hosts); VIR_FREE(def->hosts); @@ -2449,7 +2411,7 @@ qemuParseNBDString(virDomainDiskDefPtr disk) } if (VIR_ALLOC(h) < 0) - goto no_memory; + goto error; host = disk->src + strlen("nbd:"); if (STRPREFIX(host, "unix:/")) { @@ -2470,7 +2432,7 @@ qemuParseNBDString(virDomainDiskDefPtr disk) *port++ = '\0'; h->name = VIR_STRDUP(host); if (!h->name) - goto no_memory; + goto error; src = strchr(port, ':'); if (src) @@ -2478,13 +2440,13 @@ qemuParseNBDString(virDomainDiskDefPtr disk) h->port = VIR_STRDUP(port); if (!h->port) - goto no_memory; + goto error; } if (src && STRPREFIX(src, "exportname=")) { src = VIR_STRDUP(strchr(src, '=') + 1); if (!src) - goto no_memory; + goto error; } else { src = NULL; } @@ -2495,8 +2457,6 @@ qemuParseNBDString(virDomainDiskDefPtr disk) disk->hosts = h; return 0; -no_memory: - virReportOOMError(); error: virDomainDiskHostDefFree(h); VIR_FREE(h); @@ -2536,14 +2496,14 @@ qemuBuildDriveURIString(virConnectPtr conn, if (disk->hosts->transport == VIR_DOMAIN_DISK_PROTO_TRANS_TCP) { tmpscheme = VIR_STRDUP(scheme); if (tmpscheme == NULL) - goto no_memory; + 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); @@ -2551,7 +2511,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 */ @@ -2577,7 +2537,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"), @@ -2608,10 +2568,6 @@ cleanup: VIR_FREE(user); return ret; - -no_memory: - virReportOOMError(); - goto cleanup; } static int @@ -3636,22 +3592,18 @@ qemuBuildNicStr(virDomainNetDefPtr net, const char *prefix, int vlan) { - char *str; - if (virAsprintf(&str, - "%smacaddr=%02x:%02x:%02x:%02x:%02x:%02x,vlan=%d%s%s%s%s", - prefix ? prefix : "", - net->mac.addr[0], net->mac.addr[1], - net->mac.addr[2], net->mac.addr[3], - net->mac.addr[4], net->mac.addr[5], - vlan, - (net->model ? ",model=" : ""), - (net->model ? net->model : ""), - (net->info.alias ? ",name=" : ""), - (net->info.alias ? net->info.alias : "")) < 0) { - virReportOOMError(); - return NULL; - } - + char *str = NULL; + ignore_value(virAsprintf(&str, + "%smacaddr=%02x:%02x:%02x:%02x:%02x:%02x,vlan=%d%s%s%s%s", + prefix ? prefix : "", + net->mac.addr[0], net->mac.addr[1], + net->mac.addr[2], net->mac.addr[3], + net->mac.addr[4], net->mac.addr[5], + vlan, + (net->model ? ",model=" : ""), + (net->model ? net->model : ""), + (net->info.alias ? ",name=" : ""), + (net->info.alias ? net->info.alias : ""))); return str; } @@ -4115,10 +4067,8 @@ qemuOpenPCIConfig(virDomainHostdevDefPtr dev) dev->source.subsys.u.pci.domain, dev->source.subsys.u.pci.bus, dev->source.subsys.u.pci.slot, - dev->source.subsys.u.pci.function) < 0) { - virReportOOMError(); + dev->source.subsys.u.pci.function) < 0) return -1; - } configfd = open(path, O_RDWR, 0); @@ -4169,12 +4119,10 @@ qemuBuildPCIHostdevPCIDevStr(virDomainHostdevDefPtr dev) { char *ret = NULL; - if (virAsprintf(&ret, "host=%.2x:%.2x.%.1x", - dev->source.subsys.u.pci.bus, - dev->source.subsys.u.pci.slot, - dev->source.subsys.u.pci.function) < 0) - virReportOOMError(); - + ignore_value(virAsprintf(&ret, "host=%.2x:%.2x.%.1x", + dev->source.subsys.u.pci.bus, + dev->source.subsys.u.pci.slot, + dev->source.subsys.u.pci.function)); return ret; } @@ -4364,11 +4312,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; } @@ -5074,7 +5020,7 @@ qemuBuildCpuArgStr(const virQEMUDriverPtr driver, } else { if (VIR_ALLOC(guest) < 0 || (cpu->vendor_id && !(guest->vendor_id = VIR_STRDUP(cpu->vendor_id)))) - goto no_memory; + goto cleanup; guest->arch = host->arch; if (cpu->match == VIR_CPU_MATCH_MINIMUM) @@ -5173,8 +5119,10 @@ qemuBuildCpuArgStr(const virQEMUDriverPtr driver, } } - if (virBufferError(&buf)) - goto no_memory; + if (virBufferError(&buf)) { + virReportOOMError(); + goto cleanup; + } *opt = virBufferContentAndReset(&buf); @@ -5188,10 +5136,6 @@ cleanup: virCPUDefFree(cpu); virObjectUnref(caps); return ret; - -no_memory: - virReportOOMError(); - goto cleanup; } static int @@ -5345,7 +5289,7 @@ qemuBuildGraphicsCommandLine(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", @@ -5649,8 +5593,6 @@ qemuBuildGraphicsCommandLine(virQEMUDriverConfigPtr cfg, return 0; -no_memory: - virReportOOMError(); error: return -1; } @@ -6548,14 +6490,14 @@ qemuBuildCommandLine(virConnectPtr conn, fmt = "fat:%s"; if (virAsprintf(&file, fmt, disk->src) < 0) { - goto no_memory; + goto error; } } else if (disk->type == VIR_DOMAIN_DISK_TYPE_NETWORK) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("network disks are only supported with -drive")); } else { if (!(file = VIR_STRDUP(disk->src))) { - goto no_memory; + goto error; } } @@ -6655,10 +6597,8 @@ qemuBuildCommandLine(virConnectPtr conn, } if (virDomainHostdevFind(def, hostdev, &found) < 0) { - if (virDomainHostdevInsert(def, hostdev) < 0) { - virReportOOMError(); + if (virDomainHostdevInsert(def, hostdev) < 0) goto error; - } if (qemuPrepareHostdevPCIDevices(driver, def->name, def->uuid, &hostdev, 1) < 0) { goto error; @@ -7333,7 +7273,7 @@ qemuBuildCommandLine(virConnectPtr conn, int size = 100; char *modstr; if (VIR_ALLOC_N(modstr, size+1) < 0) - goto no_memory; + goto error; for (i = 0 ; i < def->nsounds && size > 0 ; i++) { virDomainSoundDefPtr sound = def->sounds[i]; @@ -7384,7 +7324,7 @@ qemuBuildCommandLine(virConnectPtr conn, } if (!(optstr = VIR_STRDUP(model))) - goto no_memory; + goto error; } virCommandAddArg(cmd, optstr); VIR_FREE(optstr); @@ -7488,7 +7428,7 @@ qemuBuildCommandLine(virConnectPtr conn, if (configfd >= 0) { if (virAsprintf(&configfd_name, "%d", configfd) < 0) { VIR_FORCE_CLOSE(configfd); - goto no_memory; + goto error; } virCommandTransferFD(cmd, configfd); @@ -7766,8 +7706,11 @@ static int qemuStringToArgvEnv(const char *args, arg = VIR_STRDUP(curr); } - if (!arg) + if (!arg) { + if (next) + virReportOOMError(); goto no_memory; + } if (argalloc == argcount) { if (VIR_REALLOC_N(arglist, argalloc+10) < 0) { @@ -7824,7 +7767,6 @@ no_memory: for (i = 0 ; i < argcount ; i++) VIR_FREE(arglist[i]); VIR_FREE(arglist); - virReportOOMError(); return -1; } @@ -7924,7 +7866,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; } @@ -7981,10 +7923,8 @@ qemuParseCommandLineDisk(virCapsPtr qemuCaps, &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; @@ -8010,10 +7950,8 @@ qemuParseCommandLineDisk(virCapsPtr qemuCaps, def->type = VIR_DOMAIN_DISK_TYPE_NETWORK; def->protocol = VIR_DOMAIN_DISK_PROTOCOL_RBD; def->src = VIR_STRDUP(p + strlen("rbd:")); - if (!def->src) { - virReportOOMError(); + if (!def->src) goto error; - } /* old-style CEPH_ARGS env variable is parsed later */ if (!old_style_ceph_args && qemuParseRBDString(def) < 0) goto cleanup; @@ -8039,10 +7977,8 @@ qemuParseCommandLineDisk(virCapsPtr qemuCaps, def->type = VIR_DOMAIN_DISK_TYPE_NETWORK; def->protocol = VIR_DOMAIN_DISK_PROTOCOL_SHEEPDOG; def->src = VIR_STRDUP(p + strlen("sheepdog:")); - if (!def->src) { - virReportOOMError(); + if (!def->src) goto error; - } /* def->src must be [vdiname] or [host]:[port]:[vdiname] */ port = strchr(def->src, ':'); @@ -8055,24 +7991,18 @@ qemuParseCommandLineDisk(virCapsPtr qemuCaps, 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; def->hosts->port = VIR_STRDUP(port); - if (!def->hosts->port) { - virReportOOMError(); + if (!def->hosts->port) goto error; - } def->hosts->transport = VIR_DOMAIN_DISK_PROTO_TRANS_TCP; def->hosts->socket = NULL; def->src = VIR_STRDUP(vdi); - if (!def->src) { - virReportOOMError(); + if (!def->src) goto error; - } } VIR_FREE(p); @@ -8098,10 +8028,8 @@ qemuParseCommandLineDisk(virCapsPtr qemuCaps, def->device = VIR_DOMAIN_DISK_DEVICE_FLOPPY; } else if (STREQ(keywords[i], "format")) { def->driverName = VIR_STRDUP("qemu"); - if (!def->driverName) { - virReportOOMError(); + if (!def->driverName) goto error; - } def->format = virStorageFileFormatTypeFromString(values[i]); } else if (STREQ(keywords[i], "cache")) { if (STREQ(values[i], "off") || @@ -8252,10 +8180,8 @@ qemuParseCommandLineDisk(virCapsPtr qemuCaps, def->dst = VIR_STRDUP("hda"); } - if (!def->dst) { - virReportOOMError(); + if (!def->dst) goto error; - } if (STREQ(def->dst, "xvda")) def->dst[3] = 'a' + idx; else @@ -8353,10 +8279,8 @@ qemuParseCommandLineNet(virCapsPtr qemuCaps, 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 */ @@ -8609,12 +8533,12 @@ qemuParseCommandLineChr(virDomainChrSourceDefPtr source, source->type = VIR_DOMAIN_CHR_TYPE_FILE; source->data.file.path = VIR_STRDUP(val+strlen("file:")); if (!source->data.file.path) - goto no_memory; + goto error; } else if (STRPREFIX(val, "pipe:")) { source->type = VIR_DOMAIN_CHR_TYPE_PIPE; source->data.file.path = VIR_STRDUP(val+strlen("pipe:")); if (!source->data.file.path) - goto no_memory; + goto error; } else if (STREQ(val, "stdio")) { source->type = VIR_DOMAIN_CHR_TYPE_STDIO; } else if (STRPREFIX(val, "udp:")) { @@ -8658,7 +8582,7 @@ qemuParseCommandLineChr(virDomainChrSourceDefPtr source, if (STRNEQ(svc2, "0")) { source->data.udp.bindService = VIR_STRDUP(svc2); if (!source->data.udp.bindService) - goto no_memory; + goto error; } } } else if (STRPREFIX(val, "tcp:") || @@ -8733,10 +8657,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; @@ -8814,7 +8736,7 @@ qemuParseCommandLineCPU(virDomainDefPtr dom, if (i == dom->clock.ntimers) { if (VIR_REALLOC_N(dom->clock.timers, i+1) < 0 || VIR_ALLOC(dom->clock.timers[i]) < 0) - goto no_memory; + goto error; dom->clock.timers[i]->name = VIR_DOMAIN_TIMER_NAME_KVMCLOCK; dom->clock.timers[i]->present = -1; dom->clock.timers[i]->tickpolicy = -1; @@ -9059,11 +8981,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", @@ -9082,7 +9004,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, def->onPoweroff = VIR_DOMAIN_LIFECYCLE_DESTROY; def->virtType = VIR_DOMAIN_VIRT_QEMU; if (!(def->emulator = VIR_STRDUP(progargv[0]))) - goto no_memory; + goto error; if (strstr(def->emulator, "kvm")) { def->virtType = VIR_DOMAIN_VIRT_KVM; @@ -9097,7 +9019,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, def->os.type = VIR_STRDUP("hvm"); } if (!def->os.type) - goto no_memory; + goto error; if (STRPREFIX(def->emulator, "qemu")) path = def->emulator; @@ -9136,7 +9058,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; } } @@ -9155,7 +9077,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:")) { @@ -9163,7 +9085,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, vnc->data.vnc.socket = VIR_STRDUP(val + 5); if (!vnc->data.vnc.socket) { virDomainGraphicsDefFree(vnc); - goto no_memory; + goto error; } } else { /* @@ -9205,7 +9127,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")) { @@ -9234,7 +9156,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; @@ -9258,7 +9180,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, disk->device = VIR_DOMAIN_DISK_DEVICE_CDROM; disk->dst = VIR_STRDUP("hdc"); if (!disk->dst) - goto no_memory; + goto error; disk->readonly = 1; } else { if (STRPREFIX(arg, "-fd")) { @@ -9273,11 +9195,11 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, } disk->dst = VIR_STRDUP(arg + 1); if (!disk->dst) - goto no_memory; + goto error; } disk->src = VIR_STRDUP(val); if (!disk->src) - goto no_memory; + goto error; if (disk->type == VIR_DOMAIN_DISK_TYPE_NETWORK) { char *port; @@ -9307,15 +9229,15 @@ 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; disk->hosts->port = VIR_STRDUP(port); if (!disk->hosts->port) - goto no_memory; + goto error; disk->src = VIR_STRDUP(vdi); if (!disk->src) - goto no_memory; + goto error; } break; case VIR_DOMAIN_DISK_PROTOCOL_GLUSTER: @@ -9333,7 +9255,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, if (!(disk->src || disk->nhosts > 0) || !disk->dst) - goto no_memory; + goto error; if (virDomainDiskDefAssignAddress(qemuCaps, disk) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -9343,7 +9265,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")) { @@ -9363,23 +9285,23 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, } else if (STREQ(arg, "-kernel")) { WANT_VALUE(); if (!(def->os.kernel = VIR_STRDUP(val))) - goto no_memory; + goto error; } else if (STREQ(arg, "-bios")) { WANT_VALUE(); if (!(def->os.loader = VIR_STRDUP(val))) - goto no_memory; + goto error; } else if (STREQ(arg, "-initrd")) { WANT_VALUE(); if (!(def->os.initrd = VIR_STRDUP(val))) - goto no_memory; + goto error; } else if (STREQ(arg, "-append")) { WANT_VALUE(); if (!(def->os.cmdline = VIR_STRDUP(val))) - goto no_memory; + goto error; } else if (STREQ(arg, "-dtb")) { WANT_VALUE(); if (!(def->os.dtb = VIR_STRDUP(val))) - goto no_memory; + goto error; } else if (STREQ(arg, "-boot")) { const char *token = NULL; WANT_VALUE(); @@ -9424,7 +9346,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, process = strstr(val, ",process="); if (process == NULL) { if (!(def->name = VIR_STRDUP(val))) - goto no_memory; + goto error; } else { if (!(def->name = strndup(val, process - val))) goto no_memory; @@ -9438,7 +9360,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, params = strchr(val, ','); if (params == NULL) { if (!(def->os.machine = VIR_STRDUP(val))) - goto no_memory; + goto error; } else { if (!(def->os.machine = strndup(val, params - val))) goto no_memory; @@ -9477,7 +9399,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; @@ -9497,7 +9419,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; @@ -9509,7 +9431,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; @@ -9517,15 +9439,15 @@ 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; disk->src = VIR_STRDUP(val + strlen("disk:")); if (!disk->src) - goto no_memory; + goto error; if (STRPREFIX(disk->src, "/dev/")) disk->type = VIR_DOMAIN_DISK_TYPE_BLOCK; else @@ -9534,7 +9456,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, disk->bus = VIR_DOMAIN_DISK_BUS_USB; if (!(disk->dst = VIR_STRDUP("sda")) || VIR_REALLOC_N(def->disks, def->ndisks+1) < 0) - goto no_memory; + goto error; def->disks[def->ndisks++] = disk; disk = NULL; } else { @@ -9543,7 +9465,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; } @@ -9555,7 +9477,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; } @@ -9565,7 +9487,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++; @@ -9578,7 +9500,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")) { @@ -9603,11 +9525,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; } @@ -9621,7 +9543,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; @@ -9636,7 +9558,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, WANT_VALUE(); def->os.bootloader = VIR_STRDUP(val); if (!def->os.bootloader) - goto no_memory; + goto error; } else if (STREQ(arg, "-vmwarevga")) { video = VIR_DOMAIN_VIDEO_TYPE_VMVGA; } else if (STREQ(arg, "-std-vga")) { @@ -9661,7 +9583,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; @@ -9670,7 +9592,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, WANT_VALUE(); if (pidfile) if (!(*pidfile = VIR_STRDUP(val))) - goto no_memory; + goto error; } else if (STREQ(arg, "-incoming")) { WANT_VALUE(); /* ignore, used via restore/migrate APIs */ @@ -9680,7 +9602,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, virDomainChrSourceDefPtr chr; if (VIR_ALLOC(chr) < 0) - goto no_memory; + goto error; if (qemuParseCommandLineChr(chr, val) < 0) { virDomainChrSourceDefFree(chr); @@ -9734,10 +9656,10 @@ 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; cmd->args[cmd->num_args] = VIR_STRDUP(arg); if (cmd->args[cmd->num_args] == NULL) - goto no_memory; + goto error; cmd->num_args++; } } @@ -9768,13 +9690,13 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, } hosts = VIR_STRDUP(strchr(ceph_args, ' ') + 1); if (!hosts) - goto no_memory; + goto error; first_rbd_disk->nhosts = 0; token = strtok_r(hosts, ",", &saveptr); 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) { @@ -9782,14 +9704,14 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, port = VIR_STRDUP(port); if (!port) { VIR_FREE(hosts); - goto no_memory; + goto error; } } first_rbd_disk->hosts[first_rbd_disk->nhosts].port = port; first_rbd_disk->hosts[first_rbd_disk->nhosts].name = VIR_STRDUP(token); if (!first_rbd_disk->hosts[first_rbd_disk->nhosts].name) { VIR_FREE(hosts); - goto no_memory; + goto error; } first_rbd_disk->hosts[first_rbd_disk->nhosts].transport = VIR_DOMAIN_DISK_PROTO_TRANS_TCP; first_rbd_disk->hosts[first_rbd_disk->nhosts].socket = NULL; @@ -9814,7 +9736,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, virDomainVirtTypeToString(def->virtType)); if (defaultMachine != NULL) if (!(def->os.machine = VIR_STRDUP(defaultMachine))) - goto no_memory; + goto error; } if (!nographics && def->ngraphics == 0) { @@ -9822,23 +9744,23 @@ 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 (display && !(sdl->data.sdl.display = VIR_STRDUP(display))) { VIR_FREE(sdl); - goto no_memory; + goto error; } if (xauth && !(sdl->data.sdl.xauth = VIR_STRDUP(xauth))) { VIR_FREE(sdl); - goto no_memory; + goto error; } if (VIR_REALLOC_N(def->graphics, def->ngraphics+1) < 0) { virDomainGraphicsDefFree(sdl); - goto no_memory; + goto error; } def->graphics[def->ngraphics++] = sdl; } @@ -9846,7 +9768,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 @@ -9858,7 +9780,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; } @@ -9869,7 +9791,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; @@ -9950,35 +9872,27 @@ static int qemuParseProcFileStrings(int pid_value, const 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 (!(str[nstr-1] = VIR_STRDUP(tmp))) { - virReportOOMError(); + if (!(str[nstr-1] = VIR_STRDUP(tmp))) goto cleanup; - } /* Skip arg */ tmp += strlen(tmp); /* Skip \0 separator */ tmp++; } - if (VIR_EXPAND_N(str, nstr, 1) < 0) { - virReportOOMError(); + if (VIR_EXPAND_N(str, nstr, 1) < 0) goto cleanup; - } str[nstr-1] = NULL; @@ -10021,10 +9935,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 f407554..4ce9a0e 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -145,31 +145,31 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged) if (privileged) { if (virAsprintf(&cfg->logDir, "%s/log/libvirt/qemu", LOCALSTATEDIR) < 0) - goto no_memory; + goto error; if ((cfg->configBaseDir = VIR_STRDUP(SYSCONFDIR "/libvirt")) == NULL) - goto no_memory; + 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; @@ -181,11 +181,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); @@ -194,7 +194,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); @@ -202,34 +202,34 @@ 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 (!(cfg->vncListen = VIR_STRDUP("127.0.0.1"))) - goto no_memory; + goto error; if (!(cfg->vncTLSx509certdir = VIR_STRDUP(SYSCONFDIR "/pki/libvirt-vnc"))) - goto no_memory; + goto error; if (!(cfg->spiceListen = VIR_STRDUP("127.0.0.1"))) - goto no_memory; + goto error; if (!(cfg->spiceTLSx509certdir = VIR_STRDUP(SYSCONFDIR "/pki/libvirt-spice"))) - goto no_memory; + goto error; cfg->remotePortMin = QEMU_REMOTE_PORT_MIN; cfg->remotePortMax = QEMU_REMOTE_PORT_MAX; @@ -259,8 +259,6 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged) return cfg; -no_memory: - virReportOOMError(); error: virObjectUnref(cfg); return NULL; @@ -351,8 +349,8 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg, CHECK_TYPE(NAME, VIR_CONF_STRING); \ if (p && p->str) { \ VIR_FREE(VAR); \ - if (!(VAR = VIR_STRDUP(p->str))) \ - goto no_memory; \ + if (!(VAR = VIR_STRDUP(p->str))) \ + goto cleanup; \ } GET_VALUE_BOOL("vnc_auto_unix_socket", cfg->vncAutoUnixSocket); @@ -380,11 +378,11 @@ 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 (!(cfg->securityDriverNames[i] = VIR_STRDUP(pp->str))) - goto no_memory; + goto cleanup; } cfg->securityDriverNames[len] = NULL; } else { @@ -392,7 +390,7 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg, if (p && p->str) { if (VIR_ALLOC_N(cfg->securityDriverNames, 2) < 0 || !(cfg->securityDriverNames[0] = VIR_STRDUP(p->str))) - goto no_memory; + goto cleanup; cfg->securityDriverNames[1] = NULL; } @@ -486,7 +484,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) { @@ -496,7 +494,7 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg, goto cleanup; } if (!(cfg->cgroupDeviceACL[i] = VIR_STRDUP(pp->str))) - goto no_memory; + goto cleanup; } cfg->cgroupDeviceACL[i] = NULL; } @@ -532,10 +530,6 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg, cleanup: virConfFree(conf); return ret; - -no_memory: - virReportOOMError(); - goto cleanup; } #undef GET_VALUE_BOOL #undef GET_VALUE_LONG @@ -569,7 +563,7 @@ virCapsPtr virQEMUDriverCreateCapabilities(virQEMUDriverPtr driver) /* Basic host arch / guest machine capabilities */ if (!(caps = virQEMUCapsInit(driver->qemuCapsCache))) - goto no_memory; + goto error; if (cfg->allowDiskFormatProbing) { caps->defaultDiskDriverName = NULL; @@ -595,15 +589,15 @@ 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]); model = virSecurityManagerGetModel(sec_managers[i]); if (!(caps->host.secModels[i].model = VIR_STRDUP(model))) - goto no_memory; + goto error; if (!(caps->host.secModels[i].doi = VIR_STRDUP(doi))) - goto no_memory; + goto error; VIR_DEBUG("Initialized caps for security driver \"%s\" with " "DOI \"%s\"", model, doi); } @@ -612,8 +606,6 @@ virCapsPtr virQEMUDriverCreateCapabilities(virQEMUDriverPtr driver) virObjectUnref(cfg); return caps; -no_memory: - virReportOOMError(); error: VIR_FREE(sec_managers); virObjectUnref(caps); @@ -724,10 +716,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; @@ -862,10 +852,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; @@ -876,7 +864,6 @@ virQEMUCloseCallbacksGetForConn(virQEMUCloseCallbacksPtr closeCallbacks, if (data.oom) { VIR_FREE(list->entries); VIR_FREE(list); - virReportOOMError(); return NULL; } @@ -949,10 +936,8 @@ qemuGetSharedDiskKey(const char *disk_path) return NULL; } - if (virAsprintf(&key, "%d:%d", maj, min) < 0) { - virReportOOMError(); + if (virAsprintf(&key, "%d:%d", maj, min) < 0) return NULL; - } return key; } @@ -1064,21 +1049,15 @@ qemuSharedDiskEntryCopy(const qemuSharedDiskEntryPtr entry) qemuSharedDiskEntryPtr 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 (!(ret->domains[i] = VIR_STRDUP(entry->domains[i]))) { - virReportOOMError(); + if (!(ret->domains[i] = VIR_STRDUP(entry->domains[i]))) goto cleanup; - } ret->ref++; } @@ -1138,7 +1117,6 @@ qemuAddSharedDisk(virQEMUDriverPtr driver, if ((VIR_EXPAND_N(new_entry->domains, new_entry->ref, 1) < 0) || !(new_entry->domains[new_entry->ref - 1] = VIR_STRDUP(name))) { qemuSharedDiskEntryFree(new_entry, NULL); - virReportOOMError(); goto cleanup; } @@ -1151,7 +1129,6 @@ qemuAddSharedDisk(virQEMUDriverPtr driver, (VIR_ALLOC_N(entry->domains, 1) < 0) || !(entry->domains[0] = VIR_STRDUP(name))) { qemuSharedDiskEntryFree(entry, NULL); - virReportOOMError(); goto cleanup; } diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 78b4dd7..5669467 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -344,10 +344,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))) { @@ -389,10 +387,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"); @@ -535,10 +531,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); @@ -547,7 +541,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"); @@ -568,10 +562,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; @@ -614,9 +608,6 @@ qemuDomainDefNamespaceParse(xmlDocPtr xml ATTRIBUTE_UNUSED, return 0; -no_memory: - virReportOOMError(); - error: VIR_FREE(nodes); qemuDomainDefNamespaceFree(cmd); @@ -1178,7 +1169,6 @@ qemuDomainDefFormatBuf(virQEMUDriverPtr driver, ncontrollers = def->ncontrollers; if (VIR_ALLOC_N(def->controllers, ncontrollers - 1) < 0) { controllers = NULL; - virReportOOMError(); goto cleanup; } @@ -1364,10 +1354,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 @@ -1525,20 +1513,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); @@ -1670,10 +1654,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) { @@ -1882,10 +1864,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 95bcbe7..de5ef5e 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -591,7 +591,7 @@ qemuStartup(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; @@ -738,7 +738,7 @@ qemuStartup(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, @@ -820,8 +820,6 @@ qemuStartup(bool privileged, virNWFilterRegisterCallbackDriver(&qemuCallbackDriver); return 0; -out_of_memory: - virReportOOMError(); error: if (conn) virConnectClose(conn); @@ -903,10 +901,8 @@ qemuStop(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 @@ -1451,10 +1447,8 @@ qemuCanonicalizeMachine(virDomainDefPtr def, virQEMUCapsPtr qemuCaps) if (STRNEQ(canon, def->os.machine)) { char *tmp; - if (!(tmp = VIR_STRDUP(canon))) { - virReportOOMError(); + if (!(tmp = VIR_STRDUP(canon))) return -1; - } VIR_FREE(def->os.machine); def->os.machine = tmp; } @@ -2043,8 +2037,7 @@ static char *qemuDomainGetOSType(virDomainPtr dom) { if (!(vm = qemuDomObjFromDomain(dom))) goto cleanup; - if (!(type = VIR_STRDUP(vm->def->os.type))) - virReportOOMError(); + type = VIR_STRDUP(vm->def->os.type); cleanup: if (vm) @@ -2718,10 +2711,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; @@ -3008,7 +2999,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; } @@ -3409,10 +3399,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); @@ -3477,10 +3465,8 @@ static void processWatchdogEvent(void *data, void *opaque) if (virAsprintf(&dumpfile, "%s/%s-%u", cfg->autoDumpPath, wdEvent->vm->def->name, - (unsigned int)time(NULL)) < 0) { - virReportOOMError(); + (unsigned int)time(NULL)) < 0) goto unlock; - } if (qemuDomainObjBeginAsyncJob(driver, wdEvent->vm, QEMU_ASYNC_JOB_DUMP) < 0) { @@ -3642,15 +3628,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); @@ -3914,10 +3896,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; } @@ -3981,10 +3961,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, @@ -4172,10 +4150,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", @@ -4578,7 +4554,6 @@ static int qemuDomainGetSecurityLabelList(virDomainPtr dom, len++; if (VIR_ALLOC_N((*seclabels), len) < 0) { - virReportOOMError(); VIR_FREE(mgrs); goto cleanup; } @@ -4743,10 +4718,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, @@ -5058,10 +5031,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); @@ -5235,10 +5206,8 @@ static char *qemuDomainXMLFromNative(virConnectPtr conn, goto cleanup; if (!def->name && - !(def->name = VIR_STRDUP("unnamed"))) { - virReportOOMError(); + !(def->name = VIR_STRDUP("unnamed"))) goto cleanup; - } xml = qemuDomainDefFormatXML(driver, def, VIR_DOMAIN_XML_INACTIVE); @@ -5305,10 +5274,8 @@ static char *qemuDomainXMLToNative(virConnectPtr conn, (brname = virDomainNetGetActualBridgeName(net))) { char *brnamecopy = VIR_STRDUP(brname); - if (!brnamecopy) { - virReportOOMError(); + if (!brnamecopy) goto cleanup; - } virDomainActualNetDefFree(net->data.network.actual); @@ -6151,10 +6118,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) @@ -6166,10 +6131,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; @@ -6182,10 +6145,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; @@ -6749,8 +6710,6 @@ static char *qemuGetSchedulerType(virDomainPtr dom, } ret = VIR_STRDUP("posix"); - if (!ret) - virReportOOMError(); cleanup: return ret; @@ -6791,10 +6750,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; @@ -6870,10 +6827,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; @@ -7195,10 +7150,8 @@ qemuDomainGetBlkioParameters(virDomainPtr dom, } if (!param->value.s) { param->value.s = VIR_STRDUP(""); - if (!param->value.s) { - virReportOOMError(); + if (!param->value.s) goto cleanup; - } } param->type = VIR_TYPED_PARAM_STRING; if (virStrcpyStatic(param->field, @@ -8388,10 +8341,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) { @@ -8771,10 +8722,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]; @@ -8805,20 +8754,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, @@ -8826,10 +8771,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, @@ -9147,10 +9090,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) { @@ -10736,10 +10677,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 @@ -10803,7 +10742,6 @@ qemuDomainSnapshotCreateInactiveExternal(virQEMUDriverPtr driver, VIR_FREE(defdisk->src); if (!(defdisk->src = VIR_STRDUP(snapdisk->file))) { /* we cannot rollback here in a sane way */ - virReportOOMError(); goto cleanup; } defdisk->format = snapdisk->format; @@ -11095,10 +11033,8 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver, if (virAsprintf(&device, "drive-%s", disk->info.alias) < 0 || !(source = VIR_STRDUP(snap->file)) || (persistDisk && - !(persistSource = VIR_STRDUP(source)))) { - virReportOOMError(); + !(persistSource = VIR_STRDUP(source)))) goto cleanup; - } /* create the stub file and set selinux labels; manipulate disk in * place, in a way that can be reverted on failure. */ @@ -11175,10 +11111,8 @@ qemuDomainSnapshotUndoSingleDiskActive(virQEMUDriverPtr driver, if (!(source = VIR_STRDUP(origdisk->src)) || (persistDisk && - !(persistSource = VIR_STRDUP(source)))) { - virReportOOMError(); + !(persistSource = VIR_STRDUP(source)))) goto cleanup; - } qemuDomainPrepareDiskChainElement(driver, vm, cgroup, disk, origdisk->src, VIR_DISK_CHAIN_NO_ACCESS); @@ -11236,10 +11170,8 @@ qemuDomainSnapshotCreateDiskActive(virQEMUDriverPtr driver, /* 'cgroup' is still NULL if cgroups are disabled. */ 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 " @@ -11798,10 +11730,8 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain, if (vm->current_snapshot) { if (!(flags & VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE)) { snap->def->parent = VIR_STRDUP(vm->current_snapshot->def->name); - if (snap->def->parent == NULL) { - virReportOOMError(); + if (snap->def->parent == NULL) goto cleanup; - } } if (update_current) { vm->current_snapshot->def->current = false; @@ -12591,7 +12521,6 @@ qemuDomainSnapshotReparentChildren(void *payload, snap->def->parent = VIR_STRDUP(rep->parent->def->name); if (snap->def->parent == NULL) { - virReportOOMError(); rep->err = -1; return; } @@ -12807,10 +12736,8 @@ static virDomainPtr qemuDomainAttach(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; @@ -13034,10 +12961,8 @@ qemuDiskPathToAlias(virDomainObjPtr vm, const char *path, int *idx) goto cleanup; 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: @@ -13536,10 +13461,8 @@ qemuDomainBlockCopy(virDomainPtr dom, const char *path, } if (!format && disk->mirrorFormat > 0) format = virStorageFileFormatTypeToString(disk->mirrorFormat); - if (!(mirror = VIR_STRDUP(dest))) { - virReportOOMError(); + if (!(mirror = VIR_STRDUP(dest))) goto endjob; - } if (qemuDomainPrepareDiskChainElement(driver, vm, cgroup, disk, dest, VIR_DISK_CHAIN_READ_WRITE) < 0) { @@ -14199,10 +14122,8 @@ qemuDomainGetDiskErrors(virDomainPtr dom, if (n == nerrors) break; - if (!(errors[n].disk = VIR_STRDUP(disk->dst))) { - virReportOOMError(); + if (!(errors[n].disk = VIR_STRDUP(disk->dst))) goto endjob; - } errors[n].error = info->io_status; n++; } @@ -14261,13 +14182,13 @@ qemuDomainSetMetadata(virDomainPtr dom, VIR_FREE(vm->def->description); if (metadata && !(vm->def->description = VIR_STRDUP(metadata))) - goto no_memory; + goto cleanup; break; case VIR_DOMAIN_METADATA_TITLE: VIR_FREE(vm->def->title); if (metadata && !(vm->def->title = VIR_STRDUP(metadata))) - goto no_memory; + goto cleanup; break; case VIR_DOMAIN_METADATA_ELEMENT: virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s", @@ -14289,13 +14210,13 @@ qemuDomainSetMetadata(virDomainPtr dom, VIR_FREE(persistentDef->description); if (metadata && !(persistentDef->description = VIR_STRDUP(metadata))) - goto no_memory; + goto cleanup; break; case VIR_DOMAIN_METADATA_TITLE: VIR_FREE(persistentDef->title); if (metadata && !(persistentDef->title = VIR_STRDUP(metadata))) - goto no_memory; + goto cleanup; break; case VIR_DOMAIN_METADATA_ELEMENT: virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s", @@ -14321,9 +14242,6 @@ cleanup: virObjectUnref(caps); virObjectUnref(cfg); return ret; -no_memory: - virReportOOMError(); - goto cleanup; } static char * @@ -14381,10 +14299,7 @@ qemuDomainGetMetadata(virDomainPtr dom, goto cleanup; } - if (!(ret = VIR_STRDUP(field))) { - virReportOOMError(); - goto cleanup; - } + ret = VIR_STRDUP(field); cleanup: if (vm) @@ -14580,10 +14495,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(group, priv->nvcpupids, sum_cpu_time, n) < 0) goto cleanup; diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 18c2cf3..d52e8ed 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -269,10 +269,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)) { @@ -379,10 +377,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)) { @@ -432,10 +428,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; @@ -526,10 +520,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)) { @@ -630,10 +622,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)) { @@ -700,10 +690,8 @@ int qemuDomainAttachNetDevice(virConnectPtr conn, virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); /* 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 @@ -797,12 +785,12 @@ int qemuDomainAttachNetDevice(virConnectPtr conn, if (tapfd != -1) { if (virAsprintf(&tapfd_name, "fd-%s", net->info.alias) < 0) - goto no_memory; + goto cleanup; } if (vhostfd != -1) { if (virAsprintf(&vhostfd_name, "vhostfd-%s", net->info.alias) < 0) - goto no_memory; + goto cleanup; } if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_NETDEV) && @@ -951,7 +939,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", @@ -964,7 +952,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", @@ -973,10 +961,6 @@ try_remove: VIR_FREE(hostnet_name); } goto cleanup; - -no_memory: - virReportOOMError(); - goto cleanup; } @@ -991,10 +975,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) @@ -1010,10 +992,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; - } } } @@ -1089,10 +1069,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)) @@ -1132,10 +1110,8 @@ int qemuDomainAttachHostUsbDevice(virQEMUDriverPtr driver, goto error; } - 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 error; - } if (qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_DEVICES)) { virCgroupPtr cgroup = NULL; @@ -1288,10 +1264,8 @@ qemuDomainNetGetBridgeName(virConnectPtr conn, virDomainNetDefPtr net) goto cleanup; } /* we need a copy, not just a pointer to the original */ - if (!(brname = VIR_STRDUP(tmpbr))) { - virReportOOMError(); + if (!(brname = VIR_STRDUP(tmpbr))) goto cleanup; - } } else if (actualType == VIR_DOMAIN_NET_TYPE_NETWORK) { int active; virErrorPtr errobj; @@ -1545,10 +1519,8 @@ qemuDomainChangeNet(virQEMUDriverPtr driver, /* ifname: check if it's set in newdev. If not, retain the autogenerated one */ if (!(newdev->ifname || - (newdev->ifname = VIR_STRDUP(olddev->ifname)))) { - virReportOOMError(); + (newdev->ifname = VIR_STRDUP(olddev->ifname)))) goto cleanup; - } if (STRNEQ_NULLABLE(olddev->ifname, newdev->ifname)) { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", _("cannot modify network device tap name")); @@ -1574,10 +1546,8 @@ qemuDomainChangeNet(virQEMUDriverPtr driver, } /* grab alias from olddev if not set in newdev */ if (!(newdev->info.alias || - (newdev->info.alias = VIR_STRDUP(olddev->info.alias)))) { - virReportOOMError(); + (newdev->info.alias = VIR_STRDUP(olddev->info.alias)))) goto cleanup; - } if (STRNEQ_NULLABLE(olddev->info.alias, newdev->info.alias)) { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", _("cannot modify network device alias")); @@ -2082,10 +2052,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)) { @@ -2194,10 +2162,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) { @@ -2651,10 +2617,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 d8edefc..9b11d93 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -228,7 +228,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, @@ -257,7 +257,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'; @@ -267,8 +267,6 @@ qemuDomainExtractTLSSubject(const char *certdir) return subject; -no_memory: - virReportOOMError(); error: VIR_FREE(certfile); VIR_FREE(pemdata); @@ -285,7 +283,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) { @@ -316,16 +314,12 @@ qemuMigrationCookieGraphicsAlloc(virQEMUDriverPtr driver, #endif } if (!(mig->listen = VIR_STRDUP(listenAddr))) - goto no_memory; + goto error; virObjectUnref(cfg); return mig; -no_memory: - virReportOOMError(); -#ifdef WITH_GNUTLS error: -#endif qemuMigrationCookieGraphicsFree(mig); virObjectUnref(cfg); return NULL; @@ -340,12 +334,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; @@ -378,8 +372,6 @@ qemuMigrationCookieNetworkAlloc(virQEMUDriverPtr driver ATTRIBUTE_UNUSED, } return mig; -no_memory: - virReportOOMError(); error: qemuMigrationCookieNetworkFree(mig); return NULL; @@ -393,14 +385,14 @@ qemuMigrationCookieNew(virDomainObjPtr dom) const char *name; if (VIR_ALLOC(mig) < 0) - goto no_memory; + goto error; if (priv->origname) name = priv->origname; else name = dom->def->name; if (!(mig->name = VIR_STRDUP(name))) - goto no_memory; + goto error; memcpy(mig->uuid, dom->def->uuid, VIR_UUID_BUFLEN); if (!(mig->localHostname = virGetHostname(NULL))) @@ -413,8 +405,6 @@ qemuMigrationCookieNew(virDomainObjPtr dom) return mig; -no_memory: - virReportOOMError(); error: qemuMigrationCookieFree(mig); return NULL; @@ -530,10 +520,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; @@ -683,7 +671,7 @@ qemuMigrationCookieGraphicsXMLParse(xmlXPathContextPtr ctxt) char *tmp; if (VIR_ALLOC(grap) < 0) - goto no_memory; + return NULL; if (!(tmp = virXPathString("string(./graphics/@type)", ctxt))) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -719,8 +707,6 @@ qemuMigrationCookieGraphicsXMLParse(xmlXPathContextPtr ctxt) return grap; -no_memory: - virReportOOMError(); error: qemuMigrationCookieGraphicsFree(grap); return NULL; @@ -730,7 +716,7 @@ error: static qemuMigrationCookieNetworkPtr qemuMigrationCookieNetworkXMLParse(xmlXPathContextPtr ctxt) { - qemuMigrationCookieNetworkPtr optr; + qemuMigrationCookieNetworkPtr optr = NULL; int i; int n; xmlNodePtr *interfaces = NULL; @@ -738,7 +724,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, @@ -748,7 +734,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 */ @@ -769,8 +755,6 @@ cleanup: ctxt->node = save_ctxt; return optr; -no_memory: - virReportOOMError(); error: VIR_FREE(interfaces); qemuMigrationCookieNetworkFree(optr); @@ -939,10 +923,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) { @@ -1122,10 +1104,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) @@ -1224,10 +1204,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", - host, port, diskAlias) < 0)) { - virReportOOMError(); + host, port, diskAlias) < 0)) goto error; - } if (qemuDomainObjEnterMonitorAsync(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT) < 0) @@ -1308,10 +1286,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, @@ -1373,10 +1349,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) @@ -2090,10 +2064,8 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver, /* QEMU will be started with -incoming stdio * (which qemu_command might convert to exec:cat or fd:n) */ - if (!(migrateFrom = VIR_STRDUP("stdio"))) { - virReportOOMError(); + if (!(migrateFrom = VIR_STRDUP("stdio"))) goto cleanup; - } } else { virQEMUCapsPtr qemuCaps = NULL; struct addrinfo *info = NULL; @@ -2119,10 +2091,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, @@ -2378,10 +2348,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 @@ -2395,12 +2363,9 @@ 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 (!(STRPREFIX(uri_in, "tcp://")) || + virAsprintf(&uri_str, "tcp://%s", p) < 0) goto cleanup; - } - } uri = virURIParse(uri_str ? uri_str : uri_in); VIR_FREE(uri_str); @@ -2426,10 +2391,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; @@ -2513,10 +2476,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; @@ -2622,7 +2583,7 @@ qemuMigrationStartTunnel(virStreamPtr st, } if (VIR_ALLOC(io) < 0) - goto no_memory; + goto error; io->st = st; io->sock = sock; @@ -2639,8 +2600,6 @@ qemuMigrationStartTunnel(virStreamPtr st, return io; -no_memory: - virReportOOMError(); error: VIR_FORCE_CLOSE(wakeupFD[0]); VIR_FORCE_CLOSE(wakeupFD[1]); @@ -2693,10 +2652,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; @@ -2988,10 +2945,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 { @@ -3079,10 +3034,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 7788ce4..09951a4 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -484,10 +484,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; } @@ -857,12 +855,9 @@ void qemuMonitorClose(qemuMonitorPtr mon) char *qemuMonitorNextCommandID(qemuMonitorPtr mon) { - char *id; + char *id = NULL; - if (virAsprintf(&id, "libvirt-%d", ++mon->nextSerial) < 0) { - virReportOOMError(); - return NULL; - } + ignore_value(virAsprintf(&id, "libvirt-%d", ++mon->nextSerial)); return id; } @@ -1936,10 +1931,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); @@ -1968,15 +1961,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); @@ -2017,10 +2006,8 @@ int qemuMonitorMigrateToFile(qemuMonitorPtr mon, } argstr = virArgvToString(argv); - if (!argstr) { - virReportOOMError(); + if (!argstr) goto cleanup; - } /* Migrate to file */ virBufferEscapeShell(&buf, target); @@ -2042,10 +2029,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); @@ -2074,10 +2059,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 7a45be0..1f12618 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); @@ -963,10 +957,8 @@ qemuMonitorJSONHumanCommandWithFd(qemuMonitorPtr mon, else *reply_str = VIR_STRDUP(""); - if (!*reply_str) { - virReportOOMError(); + if (!*reply_str) goto cleanup; - } } ret = 0; @@ -1203,10 +1195,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); @@ -1546,10 +1536,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); @@ -2853,10 +2841,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); @@ -2947,10 +2933,8 @@ static int qemuMonitorJSONExtractPtyPaths(virJSONValuePtr reply, if (STRPREFIX(type, "pty:")) { char *path = VIR_STRDUP(type + strlen("pty:")); - if (!path) { - virReportOOMError(); + if (!path) goto cleanup; - } if (virHashAddEntry(paths, id, path) < 0) { virReportError(VIR_ERR_OPERATION_FAILED, @@ -3052,10 +3036,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); @@ -3109,10 +3091,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, @@ -3174,9 +3154,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; } @@ -3866,10 +3844,8 @@ int qemuMonitorJSONGetVersion(qemuMonitorPtr mon, _("query-version reply was missing 'package' version")); goto cleanup; } - if (!(*package = VIR_STRDUP(tmp))) { - virReportOOMError(); + if (!(*package = VIR_STRDUP(tmp))) goto cleanup; - } } ret = 0; @@ -3919,20 +3895,16 @@ int qemuMonitorJSONGetMachines(qemuMonitorPtr mon, goto cleanup; } - if (VIR_ALLOC_N(infolist, n) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(infolist, n) < 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; @@ -3942,10 +3914,8 @@ int qemuMonitorJSONGetMachines(qemuMonitorPtr mon, goto cleanup; } - if (!(info->name = VIR_STRDUP(tmp))) { - virReportOOMError(); + if (!(info->name = VIR_STRDUP(tmp))) goto cleanup; - } if (virJSONValueObjectHasKey(child, "is-default") && virJSONValueObjectGetBoolean(child, "is-default", &info->isDefault) < 0) { @@ -3960,10 +3930,8 @@ int qemuMonitorJSONGetMachines(qemuMonitorPtr mon, _("query-machines reply has malformed 'alias' data")); goto cleanup; } - if (!(info->alias = VIR_STRDUP(tmp))) { - virReportOOMError(); + if (!(info->alias = VIR_STRDUP(tmp))) goto cleanup; - } } } @@ -4032,10 +4000,8 @@ int qemuMonitorJSONGetCPUDefinitions(qemuMonitorPtr mon, goto cleanup; } - if (VIR_ALLOC_N(cpulist, n) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(cpulist, n) < 0) goto cleanup; - } for (i = 0 ; i < n ; i++) { virJSONValuePtr child = virJSONValueArrayGet(data, i); @@ -4047,10 +4013,8 @@ int qemuMonitorJSONGetCPUDefinitions(qemuMonitorPtr mon, goto cleanup; } - if (!(cpulist[i] = VIR_STRDUP(tmp))) { - virReportOOMError(); + if (!(cpulist[i] = VIR_STRDUP(tmp))) goto cleanup; - } } ret = n; @@ -4106,10 +4070,8 @@ int qemuMonitorJSONGetCommands(qemuMonitorPtr mon, goto cleanup; } - if (VIR_ALLOC_N(commandlist, n) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(commandlist, n) < 0) goto cleanup; - } for (i = 0 ; i < n ; i++) { virJSONValuePtr child = virJSONValueArrayGet(data, i); @@ -4121,10 +4083,8 @@ int qemuMonitorJSONGetCommands(qemuMonitorPtr mon, goto cleanup; } - if (!(commandlist[i] = VIR_STRDUP(tmp))) { - virReportOOMError(); + if (!(commandlist[i] = VIR_STRDUP(tmp))) goto cleanup; - } } ret = n; @@ -4185,10 +4145,8 @@ int qemuMonitorJSONGetEvents(qemuMonitorPtr mon, goto cleanup; } - if (VIR_ALLOC_N(eventlist, n) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(eventlist, n) < 0) goto cleanup; - } for (i = 0 ; i < n ; i++) { virJSONValuePtr child = virJSONValueArrayGet(data, i); @@ -4200,10 +4158,8 @@ int qemuMonitorJSONGetEvents(qemuMonitorPtr mon, goto cleanup; } - if (!(eventlist[i] = VIR_STRDUP(tmp))) { - virReportOOMError(); + if (!(eventlist[i] = VIR_STRDUP(tmp))) goto cleanup; - } } ret = n; @@ -4310,10 +4266,8 @@ int qemuMonitorJSONGetObjectTypes(qemuMonitorPtr mon, goto cleanup; } - if (VIR_ALLOC_N(typelist, n) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(typelist, n) < 0) goto cleanup; - } for (i = 0 ; i < n ; i++) { virJSONValuePtr child = virJSONValueArrayGet(data, i); @@ -4325,10 +4279,8 @@ int qemuMonitorJSONGetObjectTypes(qemuMonitorPtr mon, goto cleanup; } - if (!(typelist[i] = VIR_STRDUP(tmp))) { - virReportOOMError(); + if (!(typelist[i] = VIR_STRDUP(tmp))) goto cleanup; - } } ret = n; @@ -4392,10 +4344,8 @@ int qemuMonitorJSONGetObjectProps(qemuMonitorPtr mon, goto cleanup; } - if (VIR_ALLOC_N(proplist, n) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(proplist, n) < 0) goto cleanup; - } for (i = 0 ; i < n ; i++) { virJSONValuePtr child = virJSONValueArrayGet(data, i); @@ -4407,10 +4357,8 @@ int qemuMonitorJSONGetObjectProps(qemuMonitorPtr mon, goto cleanup; } - if (!(proplist[i] = VIR_STRDUP(tmp))) { - virReportOOMError(); + if (!(proplist[i] = VIR_STRDUP(tmp))) goto cleanup; - } } ret = n; @@ -4461,10 +4409,8 @@ qemuMonitorJSONGetTargetArch(qemuMonitorPtr mon) goto cleanup; } - if (!(ret = VIR_STRDUP(arch))) { - virReportOOMError(); + if (!(ret = VIR_STRDUP(arch))) goto cleanup; - } cleanup: virJSONValueFree(cmd); @@ -4553,18 +4499,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; @@ -4587,10 +4533,6 @@ cleanup: virJSONValueFree(cmd); virJSONValueFree(reply); return ret; - -no_memory: - virReportOOMError(); - goto cleanup; } int @@ -4607,19 +4549,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; diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c index 9323ebf..d4026cf 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; @@ -259,10 +255,8 @@ qemuMonitorTextCommandWithHandler(qemuMonitorPtr mon, *reply = msg.rxBuffer; } else { *reply = VIR_STRDUP(""); - if (!*reply) { - virReportOOMError(); + if (!*reply) return -1; - } } } @@ -351,7 +345,6 @@ qemuMonitorSendDiskPassphrase(qemuMonitorPtr mon, msg->txLength + passphrase_len + 1 + 1) < 0) { memset(passphrase, 0, passphrase_len); VIR_FREE(passphrase); - virReportOOMError(); return -1; } @@ -462,10 +455,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; @@ -773,10 +764,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; @@ -1062,10 +1051,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; @@ -1096,10 +1083,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, @@ -1140,10 +1125,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; @@ -1171,10 +1154,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; @@ -1207,10 +1188,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); @@ -1242,10 +1221,8 @@ int qemuMonitorTextSetCPU(qemuMonitorPtr mon, int cpu, int 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); @@ -1275,10 +1252,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; @@ -1311,15 +1286,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; @@ -1360,15 +1331,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; @@ -1409,10 +1376,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; @@ -1433,10 +1398,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; @@ -1597,10 +1560,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"); @@ -1616,10 +1577,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; @@ -1673,10 +1632,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); @@ -1698,15 +1655,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; @@ -1736,10 +1689,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; @@ -1768,10 +1719,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); @@ -1786,10 +1735,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); @@ -1874,10 +1821,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; @@ -1915,17 +1860,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; @@ -1961,10 +1902,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; @@ -1994,17 +1933,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) @@ -2047,10 +1982,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; @@ -2087,10 +2020,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; @@ -2120,10 +2051,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; @@ -2152,10 +2081,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; @@ -2178,10 +2105,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; @@ -2204,10 +2129,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; @@ -2284,10 +2207,8 @@ int qemuMonitorTextGetPtyPaths(qemuMonitorPtr mon, /* Path is everything after needle to the end of the line */ *eol = '\0'; char *path = VIR_STRDUP(needle + strlen(NEEDLE)); - if (path == NULL) { - virReportOOMError(); + if (path == NULL) goto cleanup; - } if (virHashAddEntry(paths, id, path) < 0) { virReportError(VIR_ERR_OPERATION_FAILED, @@ -2318,10 +2239,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; @@ -2405,19 +2324,15 @@ int qemuMonitorTextAttachDrive(qemuMonitorPtr mon, int tryOldSyntax = 0; 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; @@ -2545,10 +2460,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; @@ -2586,15 +2499,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) @@ -2624,15 +2533,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; @@ -2672,17 +2577,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; @@ -2719,15 +2620,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; @@ -2768,16 +2665,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; @@ -2809,10 +2702,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; @@ -2854,10 +2745,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; @@ -2909,10 +2798,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; @@ -2947,10 +2834,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); @@ -3039,10 +2924,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; @@ -3070,10 +2953,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; @@ -3104,10 +2985,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 6ec85d8..9488791 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -90,10 +90,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", @@ -467,7 +465,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); @@ -856,8 +853,6 @@ qemuProcessHandleWatchdog(qemuMonitorPtr mon ATTRIBUTE_UNUSED, vm = NULL; VIR_FREE(wdEvent); } - } else { - virReportOOMError(); } } @@ -1042,7 +1037,6 @@ qemuProcessHandleGraphics(qemuMonitorPtr mon ATTRIBUTE_UNUSED, return 0; no_memory: - virReportOOMError(); if (localAddr) { VIR_FREE(localAddr->service); VIR_FREE(localAddr->node); @@ -1527,10 +1521,8 @@ qemuProcessLookupPTYs(virDomainChrDefPtr *devices, VIR_FREE(chr->source.data.file.path); chr->source.data.file.path = VIR_STRDUP(path); - if (chr->source.data.file.path == NULL) { - virReportOOMError(); + if (chr->source.data.file.path == NULL) return -1; - } } } @@ -1681,10 +1673,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, @@ -1724,10 +1714,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; - } } qemuProcessReadLogFD(logfd, buf, buf_size, strlen(buf)); virReportError(VIR_ERR_INTERNAL_ERROR, @@ -1765,10 +1753,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; } @@ -1809,10 +1795,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))) { @@ -2558,10 +2542,8 @@ qemuProcessPrepareMonitorChr(virQEMUDriverConfigPtr cfg, monConfig->data.nix.listen = true; if (virAsprintf(&monConfig->data.nix.path, "%s/%s.monitor", - cfg->libDir, vm) < 0) { - virReportOOMError(); + cfg->libDir, vm) < 0) return -1; - } return 0; } @@ -2717,10 +2699,8 @@ qemuProcessUpdateState(virQEMUDriverPtr driver, virDomainObjPtr vm) } if (newState != VIR_DOMAIN_NOSTATE) { - if (!msg) { - virReportOOMError(); + if (!msg) return -1; - } VIR_DEBUG("Domain %s %s while its monitor was disconnected;" " changing state to %s (%s)", @@ -3144,10 +3124,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; @@ -3426,10 +3404,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 (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC) graphics->listens[0].address = VIR_STRDUP(cfg->vncListen); @@ -3437,7 +3413,6 @@ int qemuProcessStart(virConnectPtr conn, graphics->listens[0].address = VIR_STRDUP(cfg->spiceListen); if (!graphics->listens[0].address) { VIR_SHRINK_N(graphics->listens, graphics->nListens, 1); - virReportOOMError(); goto cleanup; } } @@ -3510,10 +3485,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) @@ -3580,7 +3553,6 @@ int qemuProcessStart(virConnectPtr conn, } if ((timestamp = virTimeStringNow()) == NULL) { - virReportOOMError(); goto cleanup; } else { if (safewrite(logfile, timestamp, strlen(timestamp)) < 0 || @@ -3935,9 +3907,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())) { if (safewrite(logfile, timestamp, strlen(timestamp)) < 0 || safewrite(logfile, SHUTDOWN_POSTFIX, strlen(SHUTDOWN_POSTFIX)) < 0) { @@ -4197,7 +4167,7 @@ int qemuProcessAttach(virConnectPtr conn ATTRIBUTE_UNUSED, VIR_FREE(priv->pidfile); if (pidfile && !(priv->pidfile = VIR_STRDUP(pidfile))) - goto no_memory; + goto cleanup; VIR_DEBUG("Detect security driver config"); sec_managers = virSecurityManagerGetNested(driver->securityManager); @@ -4213,16 +4183,16 @@ 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; if (!(seclabeldef->model = VIR_STRDUP(model))) - goto no_memory; + goto cleanup; if (!(seclabeldef->label = VIR_STRDUP(seclabel->label))) - goto no_memory; + goto cleanup; VIR_FREE(seclabel); } @@ -4257,7 +4227,6 @@ int qemuProcessAttach(virConnectPtr conn ATTRIBUTE_UNUSED, } if ((timestamp = virTimeStringNow()) == NULL) { - virReportOOMError(); goto cleanup; } else { if (safewrite(logfile, timestamp, strlen(timestamp)) < 0 || @@ -4351,8 +4320,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 diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index ca0ec4e..c85cdb1 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -369,8 +369,8 @@ static void remoteClientCloseFunc(virNetClientPtr client ATTRIBUTE_UNUSED, #define EXTRACT_URI_ARG_STR(ARG_NAME, ARG_VAR) \ if (STRCASEEQ(var->name, ARG_NAME)) { \ VIR_FREE(ARG_VAR); \ - if (!(ARG_VAR = VIR_STRDUP(var->value))) \ - goto no_memory; \ + if (!(ARG_VAR = VIR_STRDUP(var->value))) \ + goto failed; \ var->ignore = 1; \ continue; \ } @@ -496,13 +496,13 @@ 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 (!(port = VIR_STRDUP(LIBVIRTD_TLS_PORT))) - goto no_memory; + goto failed; } else if (transport == trans_tcp) { if (!(port = VIR_STRDUP(LIBVIRTD_TCP_PORT))) - goto no_memory; + goto failed; } /* Port not used for unix, ext., default for ssh */ if (conn->uri && conn->uri->server) @@ -511,11 +511,11 @@ doRemoteOpen(virConnectPtr conn, priv->hostname = VIR_STRDUP("localhost"); if (!priv->hostname) - goto no_memory; + goto failed; if (conn->uri && conn->uri->user && !(username = VIR_STRDUP(conn->uri->user))) - goto no_memory; + goto failed; /* Get the variables from the query string. * Then we need to reconstruct the query string (because @@ -559,7 +559,7 @@ doRemoteOpen(virConnectPtr conn, STRPREFIX(conn->uri->scheme, "remote+"))) { /* Allow remote serve to probe */ if (!(name = VIR_STRDUP(""))) - goto no_memory; + goto failed; } else { virURI tmpuri = { .scheme = conn->uri->scheme, @@ -589,7 +589,7 @@ doRemoteOpen(virConnectPtr conn, } else { /* Probe URI server side */ if (!(name = VIR_STRDUP(""))) - goto no_memory; + goto failed; } VIR_DEBUG("proceeding with name = %s", name); @@ -643,7 +643,7 @@ doRemoteOpen(virConnectPtr conn, sockname = VIR_STRDUP(LIBVIRTD_PRIV_UNIX_SOCKET); if (sockname == NULL) - goto no_memory; + goto failed; } VIR_DEBUG("Starting LibSSH2 session"); @@ -675,7 +675,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 { @@ -684,7 +684,7 @@ doRemoteOpen(virConnectPtr conn, else sockname = VIR_STRDUP(LIBVIRTD_PRIV_UNIX_SOCKET); if (sockname == NULL) - goto no_memory; + goto failed; } VIR_DEBUG("Proceeding with sockname %s", sockname); } @@ -707,7 +707,7 @@ doRemoteOpen(virConnectPtr conn, case trans_ssh: if (!command && !(command = VIR_STRDUP("ssh"))) - goto no_memory; + goto failed; if (!sockname) { if (flags & VIR_DRV_OPEN_REMOTE_RO) @@ -715,7 +715,7 @@ doRemoteOpen(virConnectPtr conn, else sockname = VIR_STRDUP(LIBVIRTD_PRIV_UNIX_SOCKET); if (!sockname) - goto no_memory; + goto failed; } if (!(priv->client = virNetClientNewSSH(priv->hostname, @@ -869,9 +869,6 @@ doRemoteOpen(virConnectPtr conn, return retcode; -no_memory: - virReportOOMError(); - failed: virObjectUnref(priv->remoteProgram); virObjectUnref(priv->lxcProgram); @@ -890,10 +887,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", @@ -1420,17 +1415,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; @@ -1484,18 +1475,14 @@ 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: */ val[i].field = VIR_STRDUP(params[i].field); - if (val[i].field == NULL) { - virReportOOMError(); + if (val[i].field == NULL) goto cleanup; - } val[i].value.type = params[i].type; switch (params[i].type) { case VIR_TYPED_PARAM_INT: @@ -1518,10 +1505,8 @@ remoteSerializeTypedParameters(virTypedParameterPtr params, break; case VIR_TYPED_PARAM_STRING: val[i].value.remote_typed_param_value_u.s = VIR_STRDUP(params[i].value.s); - if (val[i].value.remote_typed_param_value_u.s == NULL) { - virReportOOMError(); + if (val[i].value.remote_typed_param_value_u.s == NULL) goto cleanup; - } break; default: virReportError(VIR_ERR_RPC, _("unknown parameter type: %d"), @@ -1558,12 +1543,8 @@ remoteDeserializeTypedParameters(remote_typed_param *ret_params_val, _("returned number of parameters exceeds limit")); goto cleanup; } - } else { - if (VIR_ALLOC_N(*params, ret_params_len) < 0) { - virReportOOMError(); - goto cleanup; - } - } + } else if (VIR_ALLOC_N(*params, ret_params_len) < 0) + goto cleanup; *nparams = ret_params_len; /* Deserialise the result. */ @@ -1608,10 +1589,8 @@ remoteDeserializeTypedParameters(remote_typed_param *ret_params_val, case VIR_TYPED_PARAM_STRING: param->value.s = VIR_STRDUP(ret_param->value.remote_typed_param_value_u.s); - if (!param->value.s) { - virReportOOMError(); + if (!param->value.s) goto cleanup; - } break; default: virReportError(VIR_ERR_RPC, _("unknown parameter type: %d"), @@ -1651,10 +1630,8 @@ remoteDeserializeDomainDiskErrors(remote_domain_disk_error *ret_errors_val, } for (i = 0; i < ret_errors_len; i++) { - if (!(errors[i].disk = VIR_STRDUP(ret_errors_val[i].disk))) { - virReportOOMError(); + if (!(errors[i].disk = VIR_STRDUP(ret_errors_val[i].disk))) goto error; - } errors[i].error = ret_errors_val[i].error; } @@ -2811,17 +2788,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; @@ -2874,17 +2847,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; @@ -2937,17 +2906,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; @@ -3000,17 +2965,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; @@ -3063,17 +3024,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; @@ -3264,17 +3221,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; @@ -3328,17 +3281,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; @@ -4811,10 +4760,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; @@ -5068,10 +5015,8 @@ remoteQemuDomainMonitorCommand(virDomainPtr domain, const char *cmd, goto done; *result = VIR_STRDUP(ret.result); - if (*result == NULL) { - virReportOOMError(); + if (*result == NULL) goto cleanup; - } rv = 0; @@ -5711,16 +5656,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; @@ -5774,16 +5715,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; @@ -5883,10 +5820,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); } diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl index e5424a0..cbc83c8 100755 --- a/src/rpc/gendispatch.pl +++ b/src/rpc/gendispatch.pl @@ -599,10 +599,8 @@ elsif ($opt_b) { push(@vars_list, "const char *$1"); push(@ret_list, "/* We have to VIR_STRDUP because remoteDispatchClientRequest will"); push(@ret_list, " * free this string after it's been serialised. */"); - push(@ret_list, "if (!(ret->type = VIR_STRDUP(type))) {"); - push(@ret_list, " virReportOOMError();"); + push(@ret_list, "if (!(ret->type = VIR_STRDUP(type)))"); push(@ret_list, " goto cleanup;"); - push(@ret_list, "}"); } else { push(@vars_list, "char *$1"); push(@ret_list, "ret->$1 = $1;"); @@ -618,16 +616,13 @@ elsif ($opt_b) { 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" . " *$1_p = VIR_STRDUP($1);\n" . - " if (*$1_p == NULL) {\n" . - " virReportOOMError();\n" . + " if (*$1_p == NULL)\n" . " goto cleanup;\n" . - " }\n"); + " \n"); $single_ret_var = $1; $single_ret_by_ref = 0; @@ -906,10 +901,8 @@ elsif ($opt_b) { 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"; } @@ -1561,7 +1554,6 @@ elsif ($opt_k) { print " for (--i; i >= 0; --i)\n"; print " VIR_FREE(${single_ret_list_name}[i]);\n"; print "\n"; - print " virReportOOMError();\n"; print " goto cleanup;\n"; print " }\n"; print " }\n"; diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c index 2adac17..40ab7aa 100644 --- a/src/rpc/virnetclient.c +++ b/src/rpc/virnetclient.c @@ -318,17 +318,14 @@ static virNetClientPtr virNetClientNew(virNetSocketPtr sock, client->wakeupSendFD = wakeupFD[1]; wakeupFD[0] = wakeupFD[1] = -1; - if (hostname && - !(client->hostname = VIR_STRDUP(hostname))) - goto no_memory; + if (hostname && !(client->hostname = VIR_STRDUP(hostname))) + goto error; PROBE(RPC_CLIENT_NEW, "client=%p sock=%p", client, client->sock); return client; -no_memory: - virReportOOMError(); error: VIR_FORCE_CLOSE(wakeupFD[0]); VIR_FORCE_CLOSE(wakeupFD[1]); @@ -416,7 +413,7 @@ virNetClientPtr virNetClientNewLibSSH2(const char *host, } } else { if (!(knownhosts = VIR_STRDUP(knownHostsPath))) - goto no_memory; + goto cleanup; } } @@ -440,7 +437,7 @@ virNetClientPtr virNetClientNewLibSSH2(const char *host, } } else { if (!(privkey = VIR_STRDUP(privkeyPath))) - goto no_memory; + goto cleanup; } } @@ -886,7 +883,6 @@ int virNetClientAddProgram(virNetClientPtr client, return 0; no_memory: - virReportOOMError(); virObjectUnlock(client); return -1; } @@ -906,7 +902,6 @@ int virNetClientAddStream(virNetClientPtr client, return 0; no_memory: - virReportOOMError(); virObjectUnlock(client); return -1; } @@ -984,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)); @@ -1236,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; @@ -1891,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", @@ -1967,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 ced6eda..03cf246 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 296cef8..f1b8ec3 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_MAX + 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; diff --git a/src/rpc/virnetsaslcontext.c b/src/rpc/virnetsaslcontext.c index 0d2d7a4..57c8968 100644 --- a/src/rpc/virnetsaslcontext.c +++ b/src/rpc/virnetsaslcontext.c @@ -386,10 +386,8 @@ char *virNetSASLSessionListMechanisms(virNetSASLSessionPtr sasl) err, sasl_errdetail(sasl->conn)); goto cleanup; } - if (!(ret = VIR_STRDUP(mechlist))) { - virReportOOMError(); + if (!(ret = VIR_STRDUP(mechlist))) goto cleanup; - } cleanup: virObjectUnlock(sasl); diff --git a/src/rpc/virnetserver.c b/src/rpc/virnetserver.c index fef6ae8..eafb537 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); @@ -389,10 +385,8 @@ virNetServerPtr virNetServerNew(size_t min_workers, srv->autoShutdownInhibitFd = -1; if (mdnsGroupName && - !(srv->mdnsGroupName = VIR_STRDUP(mdnsGroupName))) { - virReportOOMError(); + !(srv->mdnsGroupName = VIR_STRDUP(mdnsGroupName))) goto error; - } if (srv->mdnsGroupName) { if (!(srv->mdns = virNetServerMDNSNew())) goto error; @@ -936,10 +930,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; @@ -957,8 +951,6 @@ int virNetServerAddSignalHandler(virNetServerPtr srv, virObjectUnlock(srv); return 0; -no_memory: - virReportOOMError(); error: VIR_FREE(sigdata); virObjectUnlock(srv); @@ -974,7 +966,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); @@ -995,8 +987,6 @@ int virNetServerAddService(virNetServerPtr srv, virObjectUnlock(srv); return 0; -no_memory: - virReportOOMError(); error: virObjectUnlock(srv); return -1; @@ -1016,7 +1006,6 @@ int virNetServerAddProgram(virNetServerPtr srv, return 0; no_memory: - virReportOOMError(); virObjectUnlock(srv); return -1; } diff --git a/src/rpc/virnetserverclient.c b/src/rpc/virnetserverclient.c index c117ec6..77d62f1 100644 --- a/src/rpc/virnetserverclient.c +++ b/src/rpc/virnetserverclient.c @@ -240,10 +240,8 @@ int virNetServerClientAddFilter(virNetServerClientPtr client, virNetServerClientFilterPtr *place; int ret; - if (VIR_ALLOC(filter) < 0) { - virReportOOMError(); + if (VIR_ALLOC(filter) < 0) return -1; - } virObjectLock(client); @@ -315,7 +313,6 @@ virNetServerClientCheckAccess(virNetServerClientPtr client) */ confirm->bufferLength = 1; if (VIR_ALLOC_N(confirm->buffer, confirm->bufferLength) < 0) { - virReportOOMError(); virNetMessageFree(confirm); return -1; } @@ -377,10 +374,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, @@ -671,32 +666,23 @@ virNetServerClientCreateIdentity(virNetServerClientPtr client) goto cleanup; if (!(groupname = virGetGroupName(gid))) goto cleanup; - if (virAsprintf(&processid, "%lld", - (long long)pid) < 0) { - virReportOOMError(); + if (virAsprintf(&processid, "%lld", (long long)pid) < 0) goto cleanup; - } } #if WITH_SASL if (client->sasl) { const char *identity = virNetSASLSessionGetIdentity(client->sasl); - if (identity && - !(saslname = VIR_STRDUP(identity))) { - virReportOOMError(); + if (identity && !(saslname = VIR_STRDUP(identity))) goto cleanup; - } } #endif #if WITH_GNUTLS if (client->tls) { const char *identity = virNetTLSSessionGetX509DName(client->tls); - if (identity && - !(x509dname = VIR_STRDUP(identity))) { - virReportOOMError(); + if (identity && !(x509dname = VIR_STRDUP(identity))) goto cleanup; - } } #endif @@ -1230,7 +1216,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++; @@ -1333,7 +1318,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 1089d3d..a05f296 100644 --- a/src/rpc/virnetservermdns.c +++ b/src/rpc/virnetservermdns.c @@ -272,10 +272,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; @@ -337,10 +335,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", @@ -412,10 +408,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; @@ -474,14 +468,11 @@ 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 (!(group->name = VIR_STRDUP(name))) { VIR_FREE(group); - virReportOOMError(); return NULL; } group->mdns = mdns; @@ -519,15 +510,12 @@ 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 (!(entry->type = VIR_STRDUP(type))) { VIR_FREE(entry); - virReportOOMError(); return NULL; } entry->next = group->entry; diff --git a/src/rpc/virnetserverprogram.c b/src/rpc/virnetserverprogram.c index b80923d..e9bc5c6 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 2915355..fbb2fc2 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 f492194..de90d7e 100644 --- a/src/rpc/virnetsocket.c +++ b/src/rpc/virnetsocket.c @@ -298,10 +298,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; @@ -801,10 +799,8 @@ virNetSocketNewConnectLibSSH2(const char *host, if (virNetSSHSessionSetChannelCommand(sess, command) != 0) goto error; - if (!(authMethodNext = authMethodsCopy = VIR_STRDUP(authMethods))) { - virReportOOMError(); + if (!(authMethodNext = authMethodsCopy = VIR_STRDUP(authMethods))) goto error; - } while ((authMethod = strsep(&authMethodNext, ","))) { if (STRCASEEQ(authMethod, "keyboard-interactive")) @@ -1181,10 +1177,8 @@ int virNetSocketGetSecurityContext(virNetSocketPtr sock, goto cleanup; } - if (!(*context = VIR_STRDUP(seccon))) { - virReportOOMError(); + if (!(*context = VIR_STRDUP(seccon))) goto cleanup; - } ret = 0; cleanup: @@ -1427,10 +1421,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 e13625c..f931072 100644 --- a/src/rpc/virnetsshsession.c +++ b/src/rpc/virnetsshsession.c @@ -375,7 +375,6 @@ virNetSSHCheckHostKey(virNetSSHSessionPtr sess) keyhash, sess->hostname, sess->port, "y", "n") < 0) { - virReportOOMError(); VIR_FREE(keyhash); return -1; } @@ -632,10 +631,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", @@ -738,7 +735,6 @@ virNetSSHAuthenticateKeyboardInteractive(virNetSSHSessionPtr sess, "authentication credentials")); return -1; case VIR_NET_SSH_AUTHCB_OOM: - virReportOOMError(); return -1; case VIR_NET_SSH_AUTHCB_RETR_ERR: virReportError(VIR_ERR_SSH, "%s", @@ -976,7 +972,6 @@ virNetSSHSessionAuthAddPasswordAuth(virNetSSHSessionPtr sess, no_memory: VIR_FREE(user); VIR_FREE(pass); - virReportOOMError(); virObjectUnlock(sess); return -1; } @@ -1011,7 +1006,6 @@ virNetSSHSessionAuthAddAgentAuth(virNetSSHSessionPtr sess, no_memory: VIR_FREE(user); - virReportOOMError(); virObjectUnlock(sess); return -1; } @@ -1059,7 +1053,6 @@ no_memory: VIR_FREE(user); VIR_FREE(pass); VIR_FREE(file); - virReportOOMError(); virObjectUnlock(sess); return -1; } @@ -1096,7 +1089,6 @@ virNetSSHSessionAuthAddKeyboardAuth(virNetSSHSessionPtr sess, no_memory: VIR_FREE(user); - virReportOOMError(); virObjectUnlock(sess); return -1; @@ -1111,10 +1103,8 @@ virNetSSHSessionSetChannelCommand(virNetSSHSessionPtr sess, VIR_FREE(sess->channelCommand); - if (command && !(sess->channelCommand = VIR_STRDUP(command))) { - virReportOOMError(); + if (command && !(sess->channelCommand = VIR_STRDUP(command))) ret = -1; - } virObjectUnlock(sess); return ret; @@ -1138,7 +1128,7 @@ virNetSSHSessionSetHostKeyVerification(virNetSSHSessionPtr sess, VIR_FREE(sess->hostname); if (hostname && !(sess->hostname = VIR_STRDUP(hostname))) - goto no_memory; + goto error; /* load the known hosts file */ if (hostsfile) { @@ -1163,15 +1153,13 @@ virNetSSHSessionSetHostKeyVerification(virNetSSHSessionPtr sess, if (!(flags & VIR_NET_SSH_HOSTKEY_FILE_READONLY)) { VIR_FREE(sess->knownHostsFile); if (!(sess->knownHostsFile = VIR_STRDUP(hostsfile))) - goto no_memory; + goto error; } } virObjectUnlock(sess); return 0; -no_memory: - virReportOOMError(); error: virObjectUnlock(sess); return -1; diff --git a/src/rpc/virnettlscontext.c b/src/rpc/virnettlscontext.c index 5b02ad0..15bf82b 100644 --- a/src/rpc/virnettlscontext.c +++ b/src/rpc/virnettlscontext.c @@ -310,10 +310,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) { @@ -861,7 +859,6 @@ static int virNetTLSContextLocateCredentials(const char *pkipath, return 0; out_of_memory: - virReportOOMError(); VIR_FREE(*cacert); VIR_FREE(*cacrl); VIR_FREE(*key); @@ -1028,10 +1025,8 @@ static int virNetTLSContextValidCertificate(virNetTLSContextPtr ctxt, "[session]", gnutls_strerror(ret)); goto authfail; } - if (!(sess->x509dname = VIR_STRDUP(dname))) { - virReportOOMError(); + if (!(sess->x509dname = VIR_STRDUP(dname))) goto authfail; - } VIR_DEBUG("Peer DN is %s", dname); if (virNetTLSContextCheckCertDN(cert, "[session]", sess->hostname, dname, @@ -1169,10 +1164,8 @@ virNetTLSSessionPtr virNetTLSSessionNew(virNetTLSContextPtr ctxt, return NULL; if (hostname && - !(sess->hostname = VIR_STRDUP(hostname))) { - virReportOOMError(); + !(sess->hostname = VIR_STRDUP(hostname))) goto error; - } if ((err = gnutls_init(&sess->session, ctxt->isServer ? GNUTLS_SERVER : GNUTLS_CLIENT)) != 0) { diff --git a/src/secret/secret_driver.c b/src/secret/secret_driver.c index 83d7315..1c790e7 100644 --- a/src/secret/secret_driver.c +++ b/src/secret/secret_driver.c @@ -172,10 +172,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); @@ -219,14 +217,12 @@ static char * secretComputePath(virSecretDriverStatePtr driver, const virSecretEntry *secret, const char *suffix) { - char *ret; + char *ret = NULL; char uuidstr[VIR_UUID_STRING_BUFLEN]; 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; } @@ -396,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; @@ -445,10 +439,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; @@ -457,10 +449,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; @@ -585,10 +575,8 @@ secretListSecrets(virConnectPtr conn, char **uuids, int maxuuids) char *uuidstr; 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++; @@ -648,12 +636,8 @@ secretListAllSecrets(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) { /* filter by whether it's ephemeral */ @@ -796,10 +780,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; @@ -917,10 +899,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); @@ -1003,10 +983,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; diff --git a/src/security/security_apparmor.c b/src/security/security_apparmor.c index 54c96cd..861b261 100644 --- a/src/security/security_apparmor.c +++ b/src/security/security_apparmor.c @@ -76,16 +76,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; } } @@ -131,10 +128,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; @@ -146,10 +141,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; @@ -230,10 +223,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; } @@ -315,10 +306,8 @@ AppArmorSetSecurityUSBLabel(virUSBDevicePtr dev ATTRIBUTE_UNUSED, if (reload_profile(ptr->mgr, def, file, true) < 0) { const virSecurityLabelDefPtr secdef = virDomainDefGetSecurityLabelDef( def, SECURITY_APPARMOR_NAME); - if (!secdef) { - virReportOOMError(); + if (!secdef) return -1; - } virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot update AppArmor profile \'%s\'"), secdef->imagelabel); @@ -337,10 +326,8 @@ AppArmorSetSecurityPCILabel(virPCIDevicePtr dev ATTRIBUTE_UNUSED, if (reload_profile(ptr->mgr, def, file, true) < 0) { const virSecurityLabelDefPtr secdef = virDomainDefGetSecurityLabelDef( def, SECURITY_APPARMOR_NAME); - if (!secdef) { - virReportOOMError(); + if (!secdef) return -1; - } virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot update AppArmor profile \'%s\'"), secdef->imagelabel); @@ -364,10 +351,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, @@ -460,10 +445,8 @@ AppArmorGenSecurityLabel(virSecurityManagerPtr mgr ATTRIBUTE_UNUSED, goto err; } - if (!secdef->model && !(secdef->model = VIR_STRDUP(SECURITY_APPARMOR_NAME))) { - virReportOOMError(); + if (!secdef->model && !(secdef->model = VIR_STRDUP(SECURITY_APPARMOR_NAME))) goto err; - } /* Now that we have a label, load the profile into the kernel. */ if (load_profile(mgr, secdef->label, def, NULL, false) < 0) { @@ -901,10 +884,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? */ @@ -921,10 +902,8 @@ AppArmorGetMountOptions(virSecurityManagerPtr mgr ATTRIBUTE_UNUSED, { char *opts; - if (!(opts = VIR_STRDUP(""))) { - virReportOOMError(); + if (!(opts = VIR_STRDUP(""))) return NULL; - } return opts; } diff --git a/src/security/security_dac.c b/src/security/security_dac.c index ea7aeb2..5f27971 100644 --- a/src/security/security_dac.c +++ b/src/security/security_dac.c @@ -77,10 +77,8 @@ int parseIds(const char *label, uid_t *uidPtr, gid_t *gidPtr) char *group = NULL; tmp_label = VIR_STRDUP(label); - if (tmp_label == NULL) { - virReportOOMError(); + if (tmp_label == NULL) goto cleanup; - } /* Split label */ sep = strchr(tmp_label, ':'); @@ -635,10 +633,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)) { @@ -677,10 +673,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)) { @@ -954,10 +948,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 b671a91..e53ac70 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); @@ -690,10 +688,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_nop.c b/src/security/security_nop.c index d2a067e..5de3cc3 100644 --- a/src/security/security_nop.c +++ b/src/security/security_nop.c @@ -182,10 +182,8 @@ static char *virSecurityDomainGetMountOptionsNop(virSecurityManagerPtr mgr ATTRI { char *opts; - if (!(opts = VIR_STRDUP(""))) { - virReportOOMError(); + if (!(opts = VIR_STRDUP(""))) return NULL; - } return opts; } diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c index 821d99d..0f589c8 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -133,20 +133,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) @@ -195,10 +191,8 @@ virSecuritySELinuxMCSGetProcessRange(char **sens, goto cleanup; } - if (!(*sens = VIR_STRDUP(context_range_get(ourContext)))) { - virReportOOMError(); + if (!(*sens = VIR_STRDUP(context_range_get(ourContext)))) goto cleanup; - } /* Find and blank out the category part (if any) */ tmp = strchr(*sens, ':'); @@ -305,10 +299,8 @@ virSecuritySELinuxContextAddRange(security_context_t src, goto cleanup; } - if (!(ret = VIR_STRDUP(str))) { - virReportOOMError(); + if (!(ret = VIR_STRDUP(str))) goto cleanup; - } cleanup: if (srccon) context_free(srccon); @@ -378,10 +370,8 @@ virSecuritySELinuxGenNewContext(const char *basecontext, _("Unable to format SELinux context")); goto cleanup; } - if (!(ret = VIR_STRDUP(str))) { - virReportOOMError(); + if (!(ret = VIR_STRDUP(str))) goto cleanup; - } VIR_DEBUG("Generated context '%s'", ret); cleanup: freecon(ourSecContext); @@ -514,10 +504,8 @@ virSecuritySELinuxQEMUInitialize(virSecurityManagerPtr mgr) ptr++; if (*ptr != '\0') { data->alt_domain_context = VIR_STRDUP(ptr); - if (!data->alt_domain_context) { - virReportOOMError(); + if (!data->alt_domain_context) goto error; - } ptr = strchrnul(data->alt_domain_context, '\n'); if (ptr && *ptr == '\n') *ptr = '\0'; @@ -538,10 +526,8 @@ virSecuritySELinuxQEMUInitialize(virSecurityManagerPtr mgr) if (ptr && *ptr == '\n') { *ptr = '\0'; data->content_context = VIR_STRDUP(ptr+1); - if (!data->content_context) { - virReportOOMError(); + if (!data->content_context) goto error; - } ptr = strchrnul(data->content_context, '\n'); if (ptr && *ptr == '\n') *ptr = '\0'; @@ -637,10 +623,8 @@ virSecuritySELinuxGenSecurityLabel(virSecurityManagerPtr mgr, range = context_range_get(ctx); if (!range || - !(mcs = VIR_STRDUP(range))) { - virReportOOMError(); + !(mcs = VIR_STRDUP(range))) goto cleanup; - } break; case VIR_DOMAIN_SECLABEL_DYNAMIC: @@ -710,10 +694,8 @@ virSecuritySELinuxGenSecurityLabel(virSecurityManagerPtr mgr, } if (!seclabel->model && - !(seclabel->model = VIR_STRDUP(SECURITY_SELINUX_NAME))) { - virReportOOMError(); + !(seclabel->model = VIR_STRDUP(SECURITY_SELINUX_NAME))) goto cleanup; - } rc = 0; @@ -1297,15 +1279,11 @@ 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 (!(path = VIR_STRDUP(dev->source.caps.u.storage.block))) { - virReportOOMError(); + if (!(path = VIR_STRDUP(dev->source.caps.u.storage.block))) return -1; - } } ret = virSecuritySELinuxSetFilecon(path, secdef->imagelabel); VIR_FREE(path); @@ -1315,15 +1293,11 @@ 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 (!(path = VIR_STRDUP(dev->source.caps.u.misc.chardev))) { - virReportOOMError(); + if (!(path = VIR_STRDUP(dev->source.caps.u.misc.chardev))) return -1; - } } ret = virSecuritySELinuxSetFilecon(path, secdef->imagelabel); VIR_FREE(path); @@ -1454,15 +1428,11 @@ 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 (!(path = VIR_STRDUP(dev->source.caps.u.storage.block))) { - virReportOOMError(); + if (!(path = VIR_STRDUP(dev->source.caps.u.storage.block))) return -1; - } } ret = virSecuritySELinuxRestoreSecurityFileLabel(mgr, path); VIR_FREE(path); @@ -1472,15 +1442,11 @@ 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 (!(path = VIR_STRDUP(dev->source.caps.u.misc.chardev))) { - virReportOOMError(); + if (!(path = VIR_STRDUP(dev->source.caps.u.misc.chardev))) return -1; - } } ret = virSecuritySELinuxRestoreSecurityFileLabel(mgr, path); VIR_FREE(path); @@ -1571,10 +1537,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)) { @@ -1638,10 +1602,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)) { @@ -2270,10 +2232,8 @@ virSecuritySELinuxGenImageLabel(virSecurityManagerPtr mgr, range = context_range_get(ctx); if (range) { mcs = VIR_STRDUP(range); - if (!mcs) { - virReportOOMError(); + if (!mcs) goto cleanup; - } if (!(label = virSecuritySELinuxGenNewContext(data->file_context, mcs, true))) goto cleanup; @@ -2300,17 +2260,13 @@ 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 && - !(opts = VIR_STRDUP(""))) { - virReportOOMError(); + !(opts = VIR_STRDUP(""))) return NULL; - } VIR_DEBUG("imageLabel=%s opts=%s", secdef ? secdef->imagelabel : "(null)", opts); 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; diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c index c33f811..df5db24 100644 --- a/src/storage/storage_backend.c +++ b/src/storage/storage_backend.c @@ -163,13 +163,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; } @@ -475,10 +473,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 = 0; def->private = 0; @@ -487,10 +483,8 @@ virStorageGenerateQcowEncryption(virConnectPtr conn, def->usage_type = VIR_SECRET_USAGE_TYPE_VOLUME; def->usage.volume = VIR_STRDUP(vol->target.path); - if (def->usage.volume == NULL) { - virReportOOMError(); + if (def->usage.volume == NULL) goto cleanup; - } xml = virSecretDefFormat(def); virSecretDefFree(def); def = NULL; @@ -724,10 +718,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); @@ -922,10 +914,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); @@ -1233,10 +1223,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); @@ -1258,10 +1246,8 @@ virStorageBackendUpdateVolTargetInfoFD(virStorageVolTargetPtr target, } else { target->perms.label = VIR_STRDUP(filecon); freecon(filecon); - if (target->perms.label == NULL) { - virReportOOMError(); + if (target->perms.label == NULL) return -1; - } } #else target->perms.label = NULL; @@ -1421,7 +1407,6 @@ virStorageBackendStablePath(virStoragePoolObjPtr pool, if (virAsprintf(&stablepath, "%s/%s", pool->def->target.path, dent->d_name) == -1) { - virReportOOMError(); closedir(dh); return NULL; } @@ -1448,9 +1433,6 @@ virStorageBackendStablePath(virStoragePoolObjPtr pool, stablepath = VIR_STRDUP(devpath); - if (stablepath == NULL) - virReportOOMError(); - return stablepath; } @@ -1482,10 +1464,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); @@ -1507,14 +1487,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) { @@ -1552,10 +1528,8 @@ virStorageBackendRunProgRegex(virStoragePoolObjPtr pool, /* NB vars[0] is the full pattern, so we offset j by 1 */ p[vars[j+1].rm_eo] = '\0'; if ((groups[ngroup++] = - VIR_STRDUP(p + vars[j+1].rm_so)) == NULL) { - virReportOOMError(); + VIR_STRDUP(p + vars[j+1].rm_so)) == NULL) goto cleanup; - } } /* We're matching on the last regex, so callback time */ @@ -1621,10 +1595,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 66ae301..fdc25bf 100644 --- a/src/storage/storage_backend_disk.c +++ b/src/storage/storage_backend_disk.c @@ -48,14 +48,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; } @@ -65,17 +62,13 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr pool, * strip the path to form a reasonable pool-unique name */ tmp = strrchr(groups[0], '/'); - if ((vol->name = VIR_STRDUP(tmp ? tmp + 1 : groups[0])) == NULL) { - virReportOOMError(); + if ((vol->name = VIR_STRDUP(tmp ? tmp + 1 : groups[0])) == NULL) return -1; - } } if (vol->target.path == NULL) { - if ((devpath = VIR_STRDUP(groups[0])) == NULL) { - virReportOOMError(); + if ((devpath = VIR_STRDUP(groups[0])) == NULL) return -1; - } /* Now figure out the stable path * @@ -91,17 +84,13 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr pool, if (vol->key == NULL) { /* XXX base off a unique key of the underlying disk */ - if ((vol->key = VIR_STRDUP(vol->target.path)) == NULL) { - virReportOOMError(); + if ((vol->key = VIR_STRDUP(vol->target.path)) == NULL) return -1; - } } 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, @@ -119,10 +108,8 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr pool, } if ((vol->source.extents[0].path = - VIR_STRDUP(pool->def->source.devices[0].path)) == NULL) { - virReportOOMError(); + VIR_STRDUP(pool->def->source.devices[0].path)) == NULL) return -1; - } } /* Refresh allocation/capacity/perms */ @@ -484,10 +471,8 @@ virStorageBackendDiskPartFormat(virStoragePoolObjPtr pool, return -1; } } - if ((*partFormat = VIR_STRDUP(partedFormat)) == NULL) { - virReportOOMError(); + if ((*partFormat = VIR_STRDUP(partedFormat)) == NULL) return -1; - } } else { /* create primary partition as long as it is possible and after that check if an extended partition exists @@ -495,10 +480,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 */ @@ -506,10 +489,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; } } @@ -526,10 +507,8 @@ virStorageBackendDiskPartFormat(virStoragePoolObjPtr pool, } } } else { - if ((*partFormat = VIR_STRDUP("primary")) == NULL) { - virReportOOMError(); + if ((*partFormat = VIR_STRDUP("primary")) == NULL) return -1; - } } return 0; } diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c index 82f8691..43bb513 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: @@ -201,17 +199,13 @@ 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 (!(src->hosts[0].name = VIR_STRDUP(state->host)) || - !(src->dir = VIR_STRDUP(path))) { - virReportOOMError(); + !(src->dir = VIR_STRDUP(path))) goto cleanup; - } src->format = VIR_STORAGE_POOL_NETFS_NFS; ret = 0; @@ -284,10 +278,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++) @@ -389,16 +381,12 @@ 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 ((src = VIR_STRDUP(pool->def->source.devices[0].path)) == NULL) { - virReportOOMError(); + if ((src = VIR_STRDUP(pool->def->source.devices[0].path)) == NULL) return -1; - } } if (netauto) @@ -571,10 +559,8 @@ virStorageBackendFileSystemProbe(const char *device, goto error; } - if ((libblkid_format = VIR_STRDUP(format)) == NULL) { - virReportOOMError(); + if ((libblkid_format = VIR_STRDUP(format)) == NULL) goto error; - } names[0] = libblkid_format; names[1] = NULL; @@ -749,10 +735,8 @@ virStorageBackendFileSystemBuild(virConnectPtr conn ATTRIBUTE_UNUSED, goto error; } - if ((parent = VIR_STRDUP(pool->def->target.path)) == NULL) { - virReportOOMError(); + if ((parent = VIR_STRDUP(pool->def->target.path)) == NULL) goto error; - } if (!(p = strrchr(parent, '/'))) { virReportError(VIR_ERR_INVALID_ARG, _("path '%s' is not absolute"), @@ -831,20 +815,20 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn ATTRIBUTE_UNUSED, int backingStoreFormat; if (VIR_ALLOC(vol) < 0) - goto no_memory; + goto cleanup; if ((vol->name = VIR_STRDUP(ent->d_name)) == NULL) - goto no_memory; + goto cleanup; vol->type = VIR_STORAGE_VOL_FILE; vol->target.format = VIR_STORAGE_FILE_RAW; /* Real value is filled in during probe */ if (virAsprintf(&vol->target.path, "%s/%s", pool->def->target.path, vol->name) == -1) - goto no_memory; + goto cleanup; if ((vol->key = VIR_STRDUP(vol->target.path)) == NULL) - goto no_memory; + goto cleanup; if ((ret = virStorageBackendProbeTarget(&vol->target, &backingStore, @@ -895,7 +879,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; } @@ -916,11 +900,7 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn ATTRIBUTE_UNUSED, return 0; -no_memory: - virReportOOMError(); - /* fallthrough */ - - cleanup: +cleanup: if (dir) closedir(dir); virStorageVolDefFree(vol); @@ -998,10 +978,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, @@ -1012,10 +990,8 @@ virStorageBackendFileSystemVolCreate(virConnectPtr conn ATTRIBUTE_UNUSED, VIR_FREE(vol->key); vol->key = VIR_STRDUP(vol->target.path); - if (vol->key == NULL) { - virReportOOMError(); + if (vol->key == NULL) return -1; - } return 0; } @@ -1197,7 +1173,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 32c321e..c66d8da 100644 --- a/src/storage/storage_backend_iscsi.c +++ b/src/storage/storage_backend_iscsi.c @@ -108,10 +108,8 @@ virStorageBackendISCSIPortal(virStoragePoolSourcePtr source) if (virAsprintf(&portal, "%s:%d,1", ipaddr, source->hosts[0].port ? - source->hosts[0].port : 3260) < 0) { - virReportOOMError(); + source->hosts[0].port : 3260) < 0) return NULL; - } return portal; } @@ -125,10 +123,8 @@ virStorageBackendISCSIExtractSession(virStoragePoolObjPtr pool, char **session = data; if (STREQ(groups[1], pool->def->source.devices[0].path)) { - if ((*session = VIR_STRDUP(groups[0])) == NULL) { - virReportOOMError(); + if ((*session = VIR_STRDUP(groups[0])) == NULL) return -1; - } } return 0; @@ -285,10 +281,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); @@ -411,10 +405,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 (virStorageBackendSCSIGetHostNumber(sysfs_path, &host) < 0) { virReportSystemError(errno, @@ -462,14 +454,11 @@ virStorageBackendISCSIGetTargets(virStoragePoolObjPtr pool ATTRIBUTE_UNUSED, struct virStorageBackendISCSITargetList *list = data; char *target; - if (!(target = VIR_STRDUP(groups[1]))) { - virReportOOMError(); + if (!(target = VIR_STRDUP(groups[1]))) return -1; - } if (VIR_REALLOC_N(list->targets, list->ntargets + 1) < 0) { VIR_FREE(target); - virReportOOMError(); return -1; } @@ -607,17 +596,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; @@ -626,10 +611,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 4287384..49b14da 100644 --- a/src/storage/storage_backend_logical.c +++ b/src/storage/storage_backend_logical.c @@ -92,32 +92,24 @@ 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; - if ((vol->name = VIR_STRDUP(groups[0])) == NULL) { - virReportOOMError(); + if ((vol->name = VIR_STRDUP(groups[0])) == NULL) 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", @@ -129,19 +121,15 @@ 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; } if (vol->key == NULL && - (vol->key = VIR_STRDUP(groups[2])) == NULL) { - virReportOOMError(); + (vol->key = VIR_STRDUP(groups[2])) == NULL) goto cleanup; - } if (virStorageBackendUpdateVolInfo(vol, 1) < 0) goto cleanup; @@ -157,10 +145,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, @@ -182,28 +168,22 @@ virStorageBackendLogicalMakeVol(virStoragePoolObjPtr pool, regex = VIR_STRDUP(regex_unit); 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) { @@ -361,10 +341,8 @@ virStorageBackendLogicalFindPoolSourcesFunc(virStoragePoolObjPtr pool ATTRIBUTE_ pvname = VIR_STRDUP(groups[0]); vgname = VIR_STRDUP(groups[1]); - if (pvname == NULL || vgname == NULL) { - virReportOOMError(); + if (pvname == NULL || vgname == NULL) goto err_no_memory; - } thisSource = NULL; for (i = 0 ; i < sourceList->nsources; i++) { @@ -383,10 +361,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 err_no_memory; - } dev = &thisSource->devices[thisSource->ndevice]; thisSource->ndevice++; @@ -476,10 +452,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; @@ -722,10 +696,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, @@ -825,10 +797,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 ccd0f1c..c03fc2c 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, @@ -100,16 +94,12 @@ virStorageBackendMpathNewVol(virStoragePoolObjPtr pool, /* XXX should use logical unit's UUID instead */ vol->key = VIR_STRDUP(vol->target.path); - if (vol->key == NULL) { - virReportOOMError(); + if (vol->key == NULL) 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; @@ -223,10 +213,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 167c32a..b9a22d7 100644 --- a/src/storage/storage_backend_rbd.c +++ b/src/storage/storage_backend_rbd.c @@ -237,18 +237,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; @@ -307,7 +303,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) @@ -324,19 +320,19 @@ 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; vol->name = VIR_STRDUP(name); if (vol->name == NULL) { VIR_FREE(vol); - goto out_of_memory; + goto cleanup; } name += strlen(name) + 1; @@ -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 a698bd0..90104fc 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) { @@ -188,8 +186,7 @@ virStorageBackendSCSISerial(const char *dev) *nl = '\0'; } else { VIR_FREE(serial); - if (!(serial = VIR_STRDUP(dev))) - virReportOOMError(); + serial = VIR_STRDUP(dev); } #ifdef WITH_UDEV @@ -214,7 +211,6 @@ virStorageBackendSCSINewLun(virStoragePoolObjPtr pool, int retval = 0; if (VIR_ALLOC(vol) < 0) { - virReportOOMError(); retval = -1; goto out; } @@ -227,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; } @@ -285,7 +279,6 @@ virStorageBackendSCSINewLun(virStoragePoolObjPtr pool, if (VIR_REALLOC_N(pool->volumes.objs, pool->volumes.count + 1) < 0) { - virReportOOMError(); retval = -1; goto free_vol; } @@ -311,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); @@ -336,7 +327,6 @@ getNewStyleBlockDevice(const char *lun_path, *block_device = VIR_STRDUP(block_dirent->d_name); if (*block_device == NULL) { - virReportOOMError(); closedir(block_dir); retval = -1; goto out; @@ -376,7 +366,6 @@ getOldStyleBlockDevice(const char *lun_path ATTRIBUTE_UNUSED, *block_device = VIR_STRDUP(blockp); if (*block_device == NULL) { - virReportOOMError(); retval = -1; goto out; } @@ -402,10 +391,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) { @@ -515,7 +502,6 @@ virStorageBackendSCSIFindLUs(virStoragePoolObjPtr pool, virFileWaitForDevices(); if (virAsprintf(&device_path, "/sys/bus/scsi/devices") < 0) { - virReportOOMError(); goto out; } @@ -597,7 +583,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; } @@ -640,10 +625,8 @@ virStorageBackendSCSICheckPool(virConnectPtr conn ATTRIBUTE_UNUSED, char *path; *isActive = false; - if (virAsprintf(&path, "/sys/class/scsi_host/%s", pool->def->source.adapter) < 0) { - virReportOOMError(); + if (virAsprintf(&path, "/sys/class/scsi_host/%s", pool->def->source.adapter) < 0) return -1; - } 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 cf7365f..c123cdf 100644 --- a/src/storage/storage_backend_sheepdog.c +++ b/src/storage/storage_backend_sheepdog.c @@ -264,16 +264,12 @@ 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); - if (virAsprintf(&vol->target.path, "%s", vol->name) == -1) { - virReportOOMError(); + if (virAsprintf(&vol->target.path, "%s", vol->name) == -1) goto cleanup; - } cleanup: virCommandFree(cmd); diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index bada675..b7cc252 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -145,7 +145,7 @@ storageDriverStartup(bool privileged, if (privileged) { if ((base = VIR_STRDUP(SYSCONFDIR "/libvirt")) == NULL) - goto out_of_memory; + goto error; } else { base = virGetUserConfigDirectory(); if (!base) @@ -157,11 +157,11 @@ storageDriverStartup(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); @@ -174,8 +174,6 @@ storageDriverStartup(bool privileged, storageDriverUnlock(driverState); return 0; -out_of_memory: - virReportOOMError(); error: VIR_FREE(base); storageDriverUnlock(driverState); @@ -338,7 +336,6 @@ storageListPools(virConnectPtr conn, if (virStoragePoolObjIsActive(driver->pools.objs[i])) { if (!(names[got] = VIR_STRDUP(driver->pools.objs[i]->def->name))) { virStoragePoolObjUnlock(driver->pools.objs[i]); - virReportOOMError(); goto cleanup; } got++; @@ -386,7 +383,6 @@ storageListDefinedPools(virConnectPtr conn, if (!virStoragePoolObjIsActive(driver->pools.objs[i])) { if (!(names[got] = VIR_STRDUP(driver->pools.objs[i]->def->name))) { virStoragePoolObjUnlock(driver->pools.objs[i]); - virReportOOMError(); goto cleanup; } got++; @@ -1117,10 +1113,8 @@ storagePoolListVolumes(virStoragePoolPtr obj, } for (i = 0 ; i < pool->volumes.count && n < maxnames ; i++) { - if ((names[n++] = VIR_STRDUP(pool->volumes.objs[i]->name)) == NULL) { - virReportOOMError(); + if ((names[n++] = VIR_STRDUP(pool->volumes.objs[i]->name)) == NULL) goto cleanup; - } } virStoragePoolObjUnlock(pool); @@ -1173,10 +1167,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 (!(vol = virGetStorageVol(pool->conn, obj->def->name, @@ -1381,10 +1373,8 @@ storageVolumeCreateXML(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, @@ -1410,7 +1400,6 @@ storageVolumeCreateXML(virStoragePoolPtr obj, virStorageVolDefPtr buildvoldef = NULL; if (VIR_ALLOC(buildvoldef) < 0) { - virReportOOMError(); voldef = NULL; goto cleanup; } @@ -1559,10 +1548,8 @@ storageVolumeCreateXMLFrom(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) { @@ -2020,10 +2007,8 @@ storageVolumeWipeInternal(virStorageVolDefPtr def, ret = storageVolumeZeroSparseFile(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, @@ -2341,8 +2326,6 @@ storageVolumeGetPath(virStorageVolPtr obj) { } ret = VIR_STRDUP(vol->target.path); - if (ret == NULL) - virReportOOMError(); cleanup: if (pool) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index fe07d0b..611acda 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -239,7 +239,6 @@ testBuildCapabilities(virConnectPtr conn) { return caps; no_memory: - virReportOOMError(); virObjectUnref(caps); return NULL; } @@ -347,10 +346,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++) { @@ -456,15 +453,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) { @@ -544,10 +537,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")); @@ -571,10 +562,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; @@ -714,10 +703,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); @@ -748,26 +735,20 @@ 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 == NULL) { def->key = VIR_STRDUP(def->target.path); - if (def->key == NULL) { - virReportOOMError(); + if (def->key == NULL) goto error; - } } pool->def->allocation += def->allocation; @@ -799,10 +780,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")); @@ -834,10 +813,8 @@ static int testOpenFromFile(virConnectPtr conn, privconn->nextDomID = 1; privconn->numCells = 0; - if ((privconn->path = VIR_STRDUP(file)) == NULL) { - virReportOOMError(); + if ((privconn->path = VIR_STRDUP(file)) == NULL) goto error; - } memmove(&privconn->nodeInfo, &defaultNodeInfo, sizeof(defaultNodeInfo)); nodeInfo = &privconn->nodeInfo; @@ -1948,10 +1925,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); @@ -2067,10 +2042,7 @@ cleanup: } static char *testGetOSType(virDomainPtr dom ATTRIBUTE_UNUSED) { - char *ret = VIR_STRDUP("linux"); - if (!ret) - virReportOOMError(); - return ret; + return VIR_STRDUP("linux"); } static unsigned long long testGetMaxMemory(virDomainPtr domain) { @@ -2722,16 +2694,10 @@ cleanup: static char *testDomainGetSchedulerType(virDomainPtr domain ATTRIBUTE_UNUSED, int *nparams) { - char *type = NULL; - if (nparams) *nparams = 1; - type = VIR_STRDUP("fair"); - if (!type) - virReportOOMError(); - - return type; + return VIR_STRDUP("fair"); } static int @@ -3038,7 +3004,6 @@ static int testListNetworks(virConnectPtr conn, char **const names, int nnames) return n; no_memory: - virReportOOMError(); for (n = 0 ; n < nnames ; n++) VIR_FREE(names[n]); testDriverUnlock(privconn); @@ -3081,7 +3046,6 @@ static int testListDefinedNetworks(virConnectPtr conn, char **const names, int n return n; no_memory: - virReportOOMError(); for (n = 0 ; n < nnames ; n++) VIR_FREE(names[n]); testDriverUnlock(privconn); @@ -3388,10 +3352,8 @@ static char *testNetworkGetBridgeName(virNetworkPtr network) { goto cleanup; } - if (!(bridge = VIR_STRDUP(privnet->def->bridge))) { - virReportOOMError(); + if (!(bridge = VIR_STRDUP(privnet->def->bridge))) goto cleanup; - } cleanup: if (privnet) @@ -3513,7 +3475,6 @@ static int testListInterfaces(virConnectPtr conn, char **const names, int nnames return n; no_memory: - virReportOOMError(); for (n = 0 ; n < nnames ; n++) VIR_FREE(names[n]); testDriverUnlock(privconn); @@ -3559,7 +3520,6 @@ static int testListDefinedInterfaces(virConnectPtr conn, char **const names, int return n; no_memory: - virReportOOMError(); for (n = 0 ; n < nnames ; n++) VIR_FREE(names[n]); testDriverUnlock(privconn); @@ -3888,10 +3848,8 @@ static int testStoragePoolObjSetDefaults(virStoragePoolObjPtr pool) { pool->def->available = defaultPoolCap - defaultPoolAlloc; pool->configFile = VIR_STRDUP("\0"); - if (!pool->configFile) { - virReportOOMError(); + if (!pool->configFile) return -1; - } return 0; } @@ -4007,7 +3965,6 @@ testStorageListPools(virConnectPtr conn, return n; no_memory: - virReportOOMError(); for (n = 0 ; n < nnames ; n++) VIR_FREE(names[n]); testDriverUnlock(privconn); @@ -4054,7 +4011,6 @@ testStorageListDefinedPools(virConnectPtr conn, return n; no_memory: - virReportOOMError(); for (n = 0 ; n < nnames ; n++) VIR_FREE(names[n]); testDriverUnlock(privconn); @@ -4186,8 +4142,6 @@ testStorageFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSED, case VIR_STORAGE_POOL_LOGICAL: ret = VIR_STRDUP(defaultPoolSourcesLogicalXML); - if (!ret) - virReportOOMError(); break; case VIR_STORAGE_POOL_NETFS: @@ -4197,9 +4151,8 @@ testStorageFindPoolSources(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: @@ -4655,10 +4608,8 @@ testStoragePoolListVolumes(virStoragePoolPtr pool, } for (i = 0 ; i < privpool->volumes.count && n < maxnames ; i++) { - if ((names[n++] = VIR_STRDUP(privpool->volumes.objs[i]->name)) == NULL) { - virReportOOMError(); + if ((names[n++] = VIR_STRDUP(privpool->volumes.objs[i]->name)) == NULL) goto cleanup; - } } virStoragePoolObjUnlock(privpool); @@ -4710,10 +4661,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, @@ -4905,23 +4854,17 @@ testStorageVolumeCreateXML(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; - } privvol->key = VIR_STRDUP(privvol->target.path); - if (privvol->key == NULL) { - virReportOOMError(); + if (privvol->key == NULL) goto cleanup; - } privpool->def->allocation += privvol->allocation; privpool->def->available = (privpool->def->capacity - @@ -5000,23 +4943,17 @@ testStorageVolumeCreateXMLFrom(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; - } privvol->key = VIR_STRDUP(privvol->target.path); - if (privvol->key == NULL) { - virReportOOMError(); + if (privvol->key == NULL) goto cleanup; - } privpool->def->allocation += privvol->allocation; privpool->def->available = (privpool->def->capacity - @@ -5241,8 +5178,6 @@ testStorageVolumeGetPath(virStorageVolPtr vol) { } ret = VIR_STRDUP(privvol->target.path); - if (ret == NULL) - virReportOOMError(); cleanup: if (privpool) @@ -5401,8 +5336,6 @@ testNodeDeviceGetParent(virNodeDevicePtr dev) if (obj->def->parent) { ret = VIR_STRDUP(obj->def->parent); - if (!ret) - virReportOOMError(); } else { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("no parent for this device")); @@ -5521,10 +5454,8 @@ testNodeDeviceCreateXML(virConnectPtr conn, /* 'name' is supposed to be filled in by the node device backend, which * we don't have. Use WWPN instead. */ VIR_FREE(def->name); - if (!(def->name = VIR_STRDUP(wwpn))) { - virReportOOMError(); + if (!(def->name = VIR_STRDUP(wwpn))) goto cleanup; - } /* Fill in a random 'host' value, since this would also come from * the backend */ @@ -5576,10 +5507,8 @@ testNodeDeviceDestroy(virNodeDevicePtr dev) } parent_name = VIR_STRDUP(obj->def->parent); - if (parent_name == NULL) { - virReportOOMError(); + if (parent_name == NULL) goto out; - } /* virNodeDeviceGetParentHost will cause the device object's lock to be * taken, so we have to dup the parent's name and drop the lock @@ -5758,10 +5687,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; } @@ -5785,10 +5712,8 @@ testDomainScreenshot(virDomainPtr dom ATTRIBUTE_UNUSED, virCheckFlags(0, NULL); - if (!(ret = VIR_STRDUP("image/png"))) { - virReportOOMError(); + if (!(ret = VIR_STRDUP("image/png"))) return NULL; - } if (virFDStreamOpenFile(st, PKGDATADIR "/libvirtLogo.png", 0, 0, O_RDONLY < 0)) VIR_FREE(ret); diff --git a/src/uml/uml_conf.c b/src/uml/uml_conf.c index 83db9c7..c16c079 100644 --- a/src/uml/uml_conf.c +++ b/src/uml/uml_conf.c @@ -124,7 +124,7 @@ umlConnectTapDevice(virConnectPtr conn, strchr(net->ifname, '%')) { VIR_FREE(net->ifname); if (!(net->ifname = VIR_STRDUP(VIR_NET_GENERATED_PREFIX "%d"))) - goto no_memory; + goto error; /* avoid exposing vnet%d in getXMLDesc or error outputs */ template_ifname = true; } @@ -150,8 +150,6 @@ umlConnectTapDevice(virConnectPtr conn, return 0; -no_memory: - virReportOOMError(); error: return -1; } @@ -294,32 +292,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: @@ -330,10 +320,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: @@ -348,7 +336,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; } @@ -449,7 +436,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); } @@ -464,7 +451,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); @@ -474,7 +461,7 @@ virCommandPtr umlBuildCommandLine(virConnectPtr conn, char *args, *next_arg; char *cmdline; if ((cmdline = VIR_STRDUP(vm->def->os.cmdline)) == NULL) - goto no_memory; + goto error; args = cmdline; while (*args == ' ') @@ -490,10 +477,7 @@ virCommandPtr umlBuildCommandLine(virConnectPtr conn, return cmd; - no_memory: - virReportOOMError(); - error: - +error: virCommandFree(cmd); return NULL; } diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c index fade87b..f4f2024 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; @@ -250,7 +248,6 @@ requery: if (res && STRPREFIX(res, "pts:")) { VIR_FREE(def->source.data.file.path); if ((def->source.data.file.path = VIR_STRDUP(res + 4)) == NULL) { - virReportOOMError(); VIR_FREE(res); VIR_FREE(cmd); return -1; @@ -773,10 +770,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"))) { @@ -815,10 +810,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; @@ -954,10 +947,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'; @@ -1037,10 +1028,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) { @@ -1075,10 +1064,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); @@ -1646,8 +1633,7 @@ static char *umlDomainGetOSType(virDomainPtr dom) { goto cleanup; } - if (!(type = VIR_STRDUP(vm->def->os.type))) - virReportOOMError(); + type = VIR_STRDUP(vm->def->os.type); cleanup: if (vm) @@ -2028,18 +2014,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); @@ -2154,10 +2136,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; diff --git a/src/util/iohelper.c b/src/util/iohelper.c index 0e9b937..d7da302 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 b60a81b..2685d8a 100644 --- a/src/util/virauth.c +++ b/src/util/virauth.c @@ -52,7 +52,7 @@ int virAuthGetConfigFilePath(virConnectPtr conn, if (authenv) { VIR_DEBUG("Using path from env '%s'", authenv); if (!(*path = VIR_STRDUP(authenv))) - goto no_memory; + goto cleanup; return 0; } @@ -63,7 +63,7 @@ int virAuthGetConfigFilePath(virConnectPtr conn, VIR_DEBUG("Using path from URI '%s'", conn->uri->params[i].value); if (!(*path = VIR_STRDUP(conn->uri->params[i].value))) - goto no_memory; + goto cleanup; return 0; } } @@ -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) @@ -82,7 +82,7 @@ int virAuthGetConfigFilePath(virConnectPtr conn, VIR_FREE(*path); if (!(*path = VIR_STRDUP(SYSCONFDIR "/libvirt/auth.conf"))) - 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; } @@ -136,11 +132,8 @@ virAuthGetCredential(virConnectPtr conn, &tmp) < 0) goto cleanup; - if (tmp && - !(*value = VIR_STRDUP(tmp))) { - virReportOOMError(); + if (tmp && !(*value = VIR_STRDUP(tmp))) goto cleanup; - } ret = 0; diff --git a/src/util/virauthconfig.c b/src/util/virauthconfig.c index d56eddc..ea21118 100644 --- a/src/util/virauthconfig.c +++ b/src/util/virauthconfig.c @@ -42,15 +42,11 @@ virAuthConfigPtr virAuthConfigNew(const char *path) { virAuthConfigPtr auth; - if (VIR_ALLOC(auth) < 0) { - virReportOOMError(); + if (VIR_ALLOC(auth) < 0) goto error; - } - if (!(auth->path = VIR_STRDUP(path))) { - virReportOOMError(); + if (!(auth->path = VIR_STRDUP(path))) goto error; - } if (!(auth->keyfile = virKeyFileNew())) goto error; @@ -72,15 +68,11 @@ virAuthConfigPtr virAuthConfigNewData(const char *path, { virAuthConfigPtr auth; - if (VIR_ALLOC(auth) < 0) { - virReportOOMError(); + if (VIR_ALLOC(auth) < 0) goto error; - } - if (!(auth->path = VIR_STRDUP(path))) { - virReportOOMError(); + if (!(auth->path = VIR_STRDUP(path))) goto error; - } if (!(auth->keyfile = virKeyFileNew())) goto error; @@ -125,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; @@ -142,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/vircommand.c b/src/util/vircommand.c index c653f7b..2b8f87e 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -1805,17 +1805,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; @@ -1889,10 +1885,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; } @@ -2436,7 +2430,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 190b773..373ca82 100644 --- a/src/util/virconf.c +++ b/src/util/virconf.c @@ -174,10 +174,8 @@ virConfNew(void) { virConfPtr ret; - if (VIR_ALLOC(ret) < 0) { - virReportOOMError(); + if (VIR_ALLOC(ret) < 0) return NULL; - } ret->filename = NULL; ret->flags = 0; @@ -226,10 +224,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; @@ -539,7 +535,6 @@ virConfParseValue(virConfParserCtxtPtr ctxt) return NULL; } if (VIR_ALLOC(ret) < 0) { - virReportOOMError(); virConfFreeList(lst); VIR_FREE(str); return NULL; @@ -901,13 +896,11 @@ virConfSetValue(virConfPtr conf, if (!cur) { if (VIR_ALLOC(cur) < 0) { - virReportOOMError(); virConfFreeValue(value); return -1; } cur->comment = NULL; if (!(cur->name = VIR_STRDUP(setting))) { - virReportOOMError(); virConfFreeValue(value); VIR_FREE(cur); return -1; diff --git a/src/util/virdnsmasq.c b/src/util/virdnsmasq.c index 538cae2..66a817a 100644 --- a/src/util/virdnsmasq.c +++ b/src/util/virdnsmasq.c @@ -137,8 +137,7 @@ addnhostsAdd(dnsmasqAddnHostsfile *addnhostsfile, return 0; - alloc_error: - virReportOOMError(); +alloc_error: VIR_FREE(ipstr); return -1; } @@ -149,19 +148,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; @@ -348,8 +343,7 @@ hostsfileAdd(dnsmasqHostsfile *hostsfile, return 0; - alloc_error: - virReportOOMError(); +alloc_error: VIR_FREE(ipstr); return -1; } @@ -360,19 +354,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; @@ -464,15 +454,11 @@ dnsmasqContextNew(const char *network_name, { dnsmasqContext *ctx; - if (VIR_ALLOC(ctx) < 0) { - virReportOOMError(); + if (VIR_ALLOC(ctx) < 0) return NULL; - } - if (!(ctx->config_dir = VIR_STRDUP(config_dir))) { - virReportOOMError(); + if (!(ctx->config_dir = VIR_STRDUP(config_dir))) goto error; - } if (!(ctx->hostsfile = hostsfileNew(network_name, config_dir))) goto error; @@ -772,10 +758,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); @@ -803,7 +787,6 @@ dnsmasqCapsNewEmpty(const char *binaryPath) return caps; error: - virReportOOMError(); virObjectUnref(caps); return NULL; } diff --git a/src/util/vireventpoll.c b/src/util/vireventpoll.c index 996cb7b..8a183a0 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 c32baf6..2339855 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -194,10 +194,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); @@ -409,10 +407,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'"), @@ -535,10 +531,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) { diff --git a/src/util/virhash.c b/src/util/virhash.c index 3808707..7327b89 100644 --- a/src/util/virhash.c +++ b/src/util/virhash.c @@ -127,10 +127,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; @@ -142,7 +140,6 @@ virHashTablePtr virHashCreateFull(ssize_t size, table->keyFree = keyFree; if (VIR_ALLOC_N(table->table, size) < 0) { - virReportOOMError(); VIR_FREE(table); return NULL; } @@ -202,7 +199,6 @@ virHashGrow(virHashTablePtr table, size_t size) return -1; if (VIR_ALLOC_N(table->table, size) < 0) { - virReportOOMError(); table->table = oldtable; return -1; } @@ -300,7 +296,6 @@ virHashAddOrUpdateEntry(virHashTablePtr table, const void *name, } if (VIR_ALLOC(entry) < 0 || !(new_name = table->keyCopy(name))) { - virReportOOMError(); VIR_FREE(entry); return -1; } @@ -671,10 +666,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 ec94012..0ec99c4 100644 --- a/src/util/viridentity.c +++ b/src/util/viridentity.c @@ -153,10 +153,8 @@ virIdentityPtr virIdentityGetSystem(void) } seccontext = VIR_STRDUP(con); freecon(con); - if (!seccontext) { - virReportOOMError(); + if (!seccontext) goto cleanup; - } #endif if (!(ret = virIdentityNew())) @@ -247,10 +245,8 @@ int virIdentitySetAttr(virIdentityPtr ident, goto cleanup; } - if (!(ident->attrs[attr] = VIR_STRDUP(value))) { - virReportOOMError(); + if (!(ident->attrs[attr] = VIR_STRDUP(value))) goto cleanup; - } ret = 0; diff --git a/src/util/virinitctl.c b/src/util/virinitctl.c index ac9ada5..67519da 100644 --- a/src/util/virinitctl.c +++ b/src/util/virinitctl.c @@ -128,16 +128,10 @@ 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 (!(path = VIR_STRDUP(VIR_INITCTL_FIFO))) { - virReportOOMError(); - return -1; - } - } + } else if (!(path = VIR_STRDUP(VIR_INITCTL_FIFO))) + return -1; if ((fd = open(path, O_WRONLY|O_NONBLOCK|O_CLOEXEC|O_NOCTTY)) < 0) { if (errno == ENOENT) { diff --git a/src/util/viriptables.c b/src/util/viriptables.c index 6e5022c..3e4c6cb 100644 --- a/src/util/viriptables.c +++ b/src/util/viriptables.c @@ -368,8 +368,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; @@ -859,10 +858,8 @@ iptablesForwardMasquerade(iptablesContext *ctx, 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'."), @@ -882,10 +879,8 @@ iptablesForwardMasquerade(iptablesContext *ctx, portRangeStr ? portRangeStr : ""); } - if (r < 0) { - virReportOOMError(); + if (r < 0) goto cleanup; - } virCommandAddArgList(cmd, "--jump", "SNAT", "--to-source", natRangeStr, NULL); diff --git a/src/util/virjson.c b/src/util/virjson.c index e4a78dc..08cd414 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -1094,8 +1094,7 @@ char *virJSONValueToString(virJSONValuePtr object, goto cleanup; } - if (!(ret = VIR_STRDUP((const char *)str))) - virReportOOMError(); + ret = VIR_STRDUP((const char *) str); cleanup: yajl_gen_free(g); diff --git a/src/util/virkeyfile.c b/src/util/virkeyfile.c index 38ed42e..bc6f11a 100644 --- a/src/util/virkeyfile.c +++ b/src/util/virkeyfile.c @@ -286,10 +286,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 4e32f15..83efd2d 100644 --- a/src/util/virlockspace.c +++ b/src/util/virlockspace.c @@ -64,17 +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 (!(ret = VIR_STRDUP(resname))) { - virReportOOMError(); - return NULL; - } - } + if (lockspace->dir) + ignore_value(virAsprintf(&ret, "%s/%s", lockspace->dir, resname)); + else + ret = VIR_STRDUP(resname); return ret; } @@ -133,10 +126,10 @@ virLockSpaceResourceNew(virLockSpacePtr lockspace, res->flags = flags; if (!(res->name = VIR_STRDUP(resname))) - goto no_memory; + goto error; if (!(res->path = virLockSpaceGetResourcePath(lockspace, resname))) - goto no_memory; + goto error; if (flags & VIR_LOCK_SPACE_ACQUIRE_AUTOCREATE) { while (1) { @@ -225,14 +218,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; @@ -264,7 +255,7 @@ virLockSpacePtr virLockSpaceNew(const char *directory) if (directory && !(lockspace->dir = VIR_STRDUP(directory))) - goto no_memory; + goto error; if (!(lockspace->resources = virHashCreate(VIR_LOCKSPACE_TABLE_SIZE, virLockSpaceResourceDataFree))) @@ -290,8 +281,6 @@ virLockSpacePtr virLockSpaceNew(const char *directory) return lockspace; -no_memory: - virReportOOMError(); error: virLockSpaceFree(lockspace); return NULL; @@ -324,10 +313,8 @@ virLockSpacePtr virLockSpaceNewPostExecRestart(virJSONValuePtr object) if (virJSONValueObjectHasKey(object, "directory")) { const char *dir = virJSONValueObjectGetString(object, "directory"); - if (!(lockspace->dir = VIR_STRDUP(dir))) { - virReportOOMError(); + if (!(lockspace->dir = VIR_STRDUP(dir))) goto error; - } } if (!(resources = virJSONValueObjectGet(object, "resources"))) { @@ -350,10 +337,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"))) { @@ -363,7 +348,6 @@ virLockSpacePtr virLockSpaceNewPostExecRestart(virJSONValuePtr object) goto error; } if (!(res->name = VIR_STRDUP(tmp))) { - virReportOOMError(); virLockSpaceResourceFree(res); goto error; } @@ -375,7 +359,6 @@ virLockSpacePtr virLockSpaceNewPostExecRestart(virJSONValuePtr object) goto error; } if (!(res->path = VIR_STRDUP(tmp))) { - virReportOOMError(); virLockSpaceResourceFree(res); goto error; } @@ -421,7 +404,6 @@ virLockSpacePtr virLockSpaceNewPostExecRestart(virJSONValuePtr object) res->nOwners = m; if (VIR_ALLOC_N(res->owners, res->nOwners) < 0) { - virReportOOMError(); virLockSpaceResourceFree(res); goto error; } @@ -460,10 +442,8 @@ virJSONValuePtr virLockSpacePreExecRestart(virLockSpacePtr lockspace) virJSONValuePtr resources; virHashKeyValuePairPtr pairs = NULL, tmp; - if (!object) { - virReportOOMError(); + if (!object) return NULL; - } virMutexLock(&lockspace->lock); @@ -486,10 +466,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); @@ -650,10 +628,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/virnetdev.c b/src/util/virnetdev.c index 773ae48..92ef2ff 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -259,10 +259,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"), @@ -296,10 +294,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; @@ -449,10 +445,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); @@ -946,13 +940,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 @@ -960,13 +948,7 @@ 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); } /** @@ -997,10 +979,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++) { @@ -1563,16 +1543,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); @@ -1601,10 +1577,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 09a7ff1..f68e308 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, @@ -563,10 +554,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 f4bc370..3e5f21c 100644 --- a/src/util/virnetdevbridge.c +++ b/src/util/virnetdevbridge.c @@ -107,10 +107,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)]; @@ -156,10 +154,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 d2cf238..b53df8d 100644 --- a/src/util/virnetdevmacvlan.c +++ b/src/util/virnetdevmacvlan.c @@ -775,15 +775,15 @@ virNetDevMacVLanVPortProfileRegisterCallback(const char *ifname, if (virtPortProfile && virNetlinkEventServiceIsRunning(NETLINK_ROUTE)) { if (VIR_ALLOC(calld) < 0) - goto memory_error; + goto error; if ((calld->cr_ifname = VIR_STRDUP(ifname)) == NULL) - goto memory_error; + goto error; if (VIR_ALLOC(calld->virtPortProfile) < 0) - goto memory_error; + goto error; memcpy(calld->virtPortProfile, virtPortProfile, sizeof(*virtPortProfile)); virMacAddrSet(&calld->macaddress, macaddress); if ((calld->linkdev = VIR_STRDUP(linkdev)) == NULL) - goto memory_error; + goto error; memcpy(calld->vmuuid, vmuuid, sizeof(calld->vmuuid)); calld->vmOp = vmOp; @@ -796,8 +796,6 @@ virNetDevMacVLanVPortProfileRegisterCallback(const char *ifname, return 0; -memory_error: - virReportOOMError(); error: virNetlinkCallbackDataFree(calld); return -1; @@ -941,14 +939,11 @@ create_name: } if (!(*res_ifname = VIR_STRDUP(cr_ifname))) { VIR_FORCE_CLOSE(rc); /* sets rc to -1 */ - virReportOOMError(); goto disassociate_exit; } } else { - if (!(*res_ifname = VIR_STRDUP(cr_ifname))) { - virReportOOMError(); + if (!(*res_ifname = VIR_STRDUP(cr_ifname))) goto disassociate_exit; - } rc = 0; } diff --git a/src/util/virnetdevopenvswitch.c b/src/util/virnetdevopenvswitch.c index 80f479b..4d8c78b 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; } if (virtVlan && virtVlan->nTags > 0) { @@ -147,10 +147,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 d2d6838..5da5aed 100644 --- a/src/util/virnetdevtap.c +++ b/src/util/virnetdevtap.c @@ -171,10 +171,8 @@ int virNetDevTapCreate(char **ifname, } VIR_FREE(*ifname); - if (!(*ifname = VIR_STRDUP(ifr.ifr_name))) { - virReportOOMError(); + if (!(*ifname = VIR_STRDUP(ifr.ifr_name))) goto cleanup; - } if (tapfd) *tapfd = fd; else diff --git a/src/util/virnetdevveth.c b/src/util/virnetdevveth.c index 5ed1167..d09cab0 100644 --- a/src/util/virnetdevveth.c +++ b/src/util/virnetdevveth.c @@ -55,18 +55,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 2fe2017..e05e7e6 100644 --- a/src/util/virnetdevvlan.c +++ b/src/util/virnetdevvlan.c @@ -82,10 +82,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 288aba0..ed365f1 100644 --- a/src/util/virnetdevvportprofile.c +++ b/src/util/virnetdevvportprofile.c @@ -411,10 +411,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. @@ -1048,7 +1046,6 @@ virNetDevVPortProfileOp8021Qbh(const char *ifname, } else { physfndev = VIR_STRDUP(ifname); if (!physfndev) { - virReportOOMError(); rc = -1; goto cleanup; } diff --git a/src/util/virnetlink.c b/src/util/virnetlink.c index 0b36fdc..204eef3 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 117e50d..3001d90 100644 --- a/src/util/virobject.c +++ b/src/util/virobject.c @@ -146,7 +146,6 @@ virClassPtr virClassNew(virClassPtr parent, no_memory: VIR_FREE(klass); - virReportOOMError(); return NULL; } @@ -189,10 +188,8 @@ void *virObjectNew(virClassPtr klass) virObjectPtr obj = NULL; char *somebytes; - if (VIR_ALLOC_N(somebytes, klass->objectSize) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(somebytes, klass->objectSize) < 0) return NULL; - } obj = (virObjectPtr)somebytes; obj->magic = klass->magic; diff --git a/src/util/virpci.c b/src/util/virpci.c index d58a15e..5977099 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -476,10 +476,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); @@ -842,12 +840,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 @@ -855,12 +848,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 @@ -868,12 +856,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); } static int @@ -1354,10 +1337,8 @@ virPCIGetAddrString(unsigned domain, dev = virPCIDeviceNew(domain, bus, slot, function); if (dev != NULL) { - if ((*pciConfigAddr = VIR_STRDUP(dev->name)) == NULL) { - virReportOOMError(); + if ((*pciConfigAddr = VIR_STRDUP(dev->name)) == NULL) goto cleanup; - } ret = 0; } @@ -1376,10 +1357,8 @@ virPCIDeviceNew(unsigned 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; @@ -1395,10 +1374,8 @@ virPCIDeviceNew(unsigned 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, @@ -1560,10 +1537,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; @@ -1665,10 +1640,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, @@ -1685,10 +1658,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; @@ -1925,10 +1896,8 @@ virPCIGetDeviceAddressFromSysfsLink(const char *device_link, } config_address = basename(device_path); - if (VIR_ALLOC(*bdf) != 0) { - virReportOOMError(); + if (VIR_ALLOC(*bdf) != 0) goto out; - } if (virPCIParseDeviceAddress(config_address, *bdf) != 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -2030,7 +1999,6 @@ virPCIGetVirtualFunctions(const char *sysfs_path, if (VIR_ALLOC_N(*virtual_functions, *num_virtual_functions + 1) < 0) { - virReportOOMError(); VIR_FREE(config_addr); goto error; } @@ -2068,10 +2036,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); @@ -2132,27 +2098,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); } /* @@ -2183,9 +2139,7 @@ virPCIGetNetName(char *device_link_sysfs_path, char **netname) /* Assume a single directory entry */ *netname = VIR_STRDUP(entry->d_name); - if (!*netname) - virReportOOMError(); - else + if (*netname) ret = 0; break; } diff --git a/src/util/virportallocator.c b/src/util/virportallocator.c index 590bb57..8e89eea 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 c7b859d..0f23c3e 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -418,10 +418,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)) @@ -465,10 +463,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; @@ -511,10 +507,8 @@ int virProcessGetNamespaces(pid_t pid, *fdlist = NULL; if (virAsprintf(&nsdir, "/proc/%llu/ns", - (unsigned long long)pid) < 0) { - virReportOOMError(); + (unsigned long long)pid) < 0) goto cleanup; - } if (!(dh = opendir(nsdir))) { virReportSystemError(errno, @@ -528,15 +522,11 @@ int virProcessGetNamespaces(pid_t pid, if (de->d_name[0] == '.') continue; - if (VIR_EXPAND_N(*fdlist, *nfdlist, 1) < 0) { - virReportOOMError(); + if (VIR_EXPAND_N(*fdlist, *nfdlist, 1) < 0) goto cleanup; - } - if (virAsprintf(&nsfile, "%s/%s", nsdir, de->d_name) < 0) { - virReportOOMError(); + if (virAsprintf(&nsfile, "%s/%s", nsdir, de->d_name) < 0) goto cleanup; - } if ((fd = open(nsfile, O_RDWR)) < 0) { virReportSystemError(errno, diff --git a/src/util/virrandom.c b/src/util/virrandom.c index 6734787..f620907 100644 --- a/src/util/virrandom.c +++ b/src/util/virrandom.c @@ -179,10 +179,8 @@ virRandomGenerateWWN(char **wwn, } if (virAsprintf(wwn, "5" "%s%09llx", oui, - (unsigned long long)virRandomBits(36)) < 0) { - virReportOOMError(); + (unsigned long long)virRandomBits(36)) < 0) return -1; - } return 0; } diff --git a/src/util/virsexpr.c b/src/util/virsexpr.c index 872c9aa..0400a71 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; } @@ -405,10 +403,8 @@ sexpr_lookup_key(const struct sexpr *sexpr, const char *node) buffer = VIR_STRDUP(node); - if (buffer == NULL) { - virReportOOMError(); + if (buffer == NULL) return NULL; - } ptr = buffer; token = strsep(&ptr, "/"); diff --git a/src/util/virsocketaddr.c b/src/util/virsocketaddr.c index b308d0f..fc065d7 100644 --- a/src/util/virsocketaddr.c +++ b/src/util/virsocketaddr.c @@ -300,7 +300,6 @@ virSocketAddrFormatFull(virSocketAddrPtr addr, return addrstr; no_memory: - virReportOOMError(); return NULL; } diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 73a358b..274221b 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -319,10 +319,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'; @@ -397,10 +395,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; /* @@ -440,10 +436,8 @@ vmdk4GetBackingStore(char **res, } *end = '\0'; *res = VIR_STRDUP(start); - if (*res == NULL) { - virReportOOMError(); + if (*res == NULL) goto cleanup; - } ret = BACKING_STORE_OK; @@ -482,10 +476,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'; @@ -525,10 +517,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))) { @@ -687,10 +677,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, @@ -708,10 +696,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); @@ -776,7 +762,6 @@ virStorageFileGetMetadataInternal(const char *path, if (backing != NULL) { meta->backingStore = VIR_STRDUP(backing); if (meta->backingStore == NULL) { - virReportOOMError(); VIR_FREE(backing); goto cleanup; } @@ -850,10 +835,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); @@ -1095,10 +1078,8 @@ int virStorageFileIsSharedFSType(const char *path, struct statfs sb; int statfs_ret; - if ((dirpath = VIR_STRDUP(path)) == NULL) { - virReportOOMError(); + if ((dirpath = VIR_STRDUP(path)) == NULL) return -1; - } do { diff --git a/src/util/virstring.c b/src/util/virstring.c index de7035f..902113b 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -85,8 +85,10 @@ char **virStringSplit(const char *string, if (VIR_RESIZE_N(tokens, maxtokens, ntokens, 1) < 0) goto no_memory; - if (!(tokens[ntokens] = strndup(remainder, len))) + if (!(tokens[ntokens] = strndup(remainder, len))) { + virReportOOMError(); goto no_memory; + } ntokens++; remainder = tmp + delimlen; tmp = strstr(remainder, delim); @@ -108,7 +110,6 @@ char **virStringSplit(const char *string, return tokens; no_memory: - virReportOOMError(); for (i = 0 ; i < ntokens ; i++) VIR_FREE(tokens[i]); VIR_FREE(tokens); @@ -144,12 +145,8 @@ char *virStringJoin(const char **strings, return NULL; } ret = virBufferContentAndReset(&buf); - if (!ret) { - if (!(ret = VIR_STRDUP(""))) { - virReportOOMError(); - return NULL; - } - } + if (!ret) + ret = VIR_STRDUP(""); return ret; } diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c index e397960..bc079ee 100644 --- a/src/util/virsysinfo.c +++ b/src/util/virsysinfo.c @@ -331,10 +331,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]; processor->processor_manufacturer = VIR_STRDUP(manufacturer); if (!virSysinfoParseDelimited(procline, "version", @@ -778,7 +776,7 @@ virSysinfoRead(void) { goto cleanup; if (VIR_ALLOC(ret) < 0) - goto no_memory; + goto cleanup; ret->type = VIR_SYSINFO_SMBIOS; 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/virtypedparam.c b/src/util/virtypedparam.c index fb1fcc0..7124d07 100644 --- a/src/util/virtypedparam.c +++ b/src/util/virtypedparam.c @@ -152,10 +152,8 @@ virTypedParameterAssign(virTypedParameterPtr param, const char *name, param->value.s = va_arg(ap, char *); if (!param->value.s) param->value.s = VIR_STRDUP(""); - if (!param->value.s) { - virReportOOMError(); + if (!param->value.s) goto cleanup; - } break; default: virReportError(VIR_ERR_INTERNAL_ERROR, @@ -248,10 +246,8 @@ virTypedParameterAssignFromStr(virTypedParameterPtr param, const char *name, } break; case VIR_TYPED_PARAM_STRING: - if (!(param->value.s = VIR_STRDUP(val))) { - virReportOOMError(); + if (!(param->value.s = VIR_STRDUP(val))) goto cleanup; - } break; default: virReportError(VIR_ERR_INTERNAL_ERROR, @@ -604,10 +600,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, @@ -654,10 +648,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, @@ -704,10 +696,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, @@ -754,10 +744,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, @@ -804,10 +792,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, @@ -854,10 +840,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, @@ -907,16 +891,12 @@ 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 (value && !(str = VIR_STRDUP(value))) { - virReportOOMError(); + if (value && !(str = VIR_STRDUP(value))) goto error; - } if (virTypedParameterAssign(*params + n, name, VIR_TYPED_PARAM_STRING, str) < 0) { @@ -969,10 +949,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 a986aa4..4c01f51 100644 --- a/src/util/viruri.c +++ b/src/util/viruri.c @@ -55,7 +55,6 @@ virURIParamAppend(virURIPtr uri, no_memory: VIR_FREE(pname); VIR_FREE(pvalue); - virReportOOMError(); return -1; } @@ -168,33 +167,33 @@ virURIParse(const char *uri) } if (VIR_ALLOC(ret) < 0) - goto no_memory; + goto error; if (xmluri->scheme && !(ret->scheme = VIR_STRDUP(xmluri->scheme))) - goto no_memory; + goto error; if (xmluri->server && !(ret->server = VIR_STRDUP(xmluri->server))) - goto no_memory; + goto error; ret->port = xmluri->port; if (xmluri->path && !(ret->path = VIR_STRDUP(xmluri->path))) - goto no_memory; + goto error; #ifdef HAVE_XMLURI_QUERY_RAW if (xmluri->query_raw && !(ret->query = VIR_STRDUP(xmluri->query_raw))) - goto no_memory; + goto error; #else if (xmluri->query && !(ret->query = VIR_STRDUP(xmluri->query))) - goto no_memory; + goto error; #endif if (xmluri->fragment && !(ret->fragment = VIR_STRDUP(xmluri->fragment))) - goto no_memory; + goto error; if (xmluri->user && !(ret->user = VIR_STRDUP(xmluri->user))) - goto no_memory; + goto error; /* First check: does it even make sense to jump inside */ if (ret->server != NULL && @@ -220,8 +219,6 @@ virURIParse(const char *uri) return ret; -no_memory: - virReportOOMError(); error: xmlFreeURI(xmluri); virURIFree(ret); @@ -264,10 +261,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 02c4e69..03adfaa 100644 --- a/src/util/virusb.c +++ b/src/util/virusb.c @@ -95,10 +95,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; @@ -333,10 +331,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; @@ -352,7 +348,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; } @@ -455,10 +450,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 cd9d5cb..cec4bf1 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -342,10 +342,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'; } @@ -1310,19 +1308,12 @@ cleanup: char * virFileBuildPath(const char *dir, const char *name, const char *ext) { - char *path; + char *path = NULL; - if (ext == NULL) { - if (virAsprintf(&path, "%s/%s", dir, name) < 0) { - virReportOOMError(); - return NULL; - } - } else { - if (virAsprintf(&path, "%s/%s%s", dir, name, ext) < 0) { - virReportOOMError(); - return NULL; - } - } + if (ext == NULL) + ignore_value(virAsprintf(&path, "%s/%s", dir, name)); + else + ignore_value(virAsprintf(&path, "%s/%s%s", dir, name, ext)); return path; } @@ -1528,10 +1519,8 @@ virFileSanitizePath(const char *path) int idx = 0; cleanpath = VIR_STRDUP(path); - if (!cleanpath) { - virReportOOMError(); + if (!cleanpath) return NULL; - } /* Need to sanitize: * // -> // @@ -1901,10 +1890,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'; @@ -1997,8 +1984,6 @@ char *virGetHostname(virConnectPtr conn ATTRIBUTE_UNUSED) freeaddrinfo(info); check_and_return: - if (result == NULL) - virReportOOMError(); return result; } @@ -2023,10 +2008,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): @@ -2037,7 +2020,6 @@ static char *virGetUserEnt(uid_t uid, */ while ((rc = getpwuid_r(uid, &pwbuf, strbuf, strbuflen, &pw)) == ERANGE) { if (VIR_RESIZE_N(strbuf, strbuflen, strbuflen, strbuflen) < 0) { - virReportOOMError(); VIR_FREE(strbuf); return NULL; } @@ -2056,8 +2038,6 @@ static char *virGetUserEnt(uid_t uid, ret = VIR_STRDUP(pw->pw_name); VIR_FREE(strbuf); - if (!ret) - virReportOOMError(); return ret; } @@ -2076,10 +2056,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): @@ -2090,7 +2068,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; } @@ -2106,8 +2083,6 @@ static char *virGetGroupEnt(gid_t gid) ret = VIR_STRDUP(gr->gr_name); VIR_FREE(strbuf); - if (!ret) - virReportOOMError(); return ret; } @@ -2123,20 +2098,13 @@ static char *virGetXDGDirectory(const char *xdgenvname, const char *xdgdefdir) char *ret = NULL; char *home = virGetUserEnt(geteuid(), VIR_USER_ENT_DIRECTORY); - if (path && path[0]) { - if (virAsprintf(&ret, "%s/libvirt", path) < 0) - goto no_memory; - } else { - if (virAsprintf(&ret, "%s/%s/libvirt", home, xdgdefdir) < 0) - goto no_memory; - } + if (path && path[0]) + ignore_value(virAsprintf(&ret, "%s/libvirt", path)); + else + ignore_value(virAsprintf(&ret, "%s/%s/libvirt", home, xdgdefdir)); - cleanup: VIR_FREE(home); return ret; - no_memory: - virReportOOMError(); - goto cleanup; } char *virGetUserConfigDirectory(void) @@ -2158,10 +2126,8 @@ char *virGetUserRuntimeDirectory(void) } else { char *ret; - if (virAsprintf(&ret, "%s/libvirt", path) < 0) { - virReportOOMError(); + if (virAsprintf(&ret, "%s/libvirt", path) < 0) return NULL; - } return ret; } @@ -2195,16 +2161,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) { @@ -2279,16 +2241,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) { @@ -2376,14 +2334,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; } @@ -2443,10 +2399,8 @@ virGetWin32SpecialFolder(int csidl, char **path) if (SHGetSpecialFolderLocation(NULL, csidl, &pidl) == S_OK) { if (SHGetPathFromIDList(pidl, buf)) { - if (!(*path = VIR_STRDUP(buf))) { - virReportOOMError(); + if (!(*path = VIR_STRDUP(buf))) ret = -1; - } } CoTaskMemFree(pidl); } @@ -2477,10 +2431,8 @@ virGetWin32DirectoryRoot(char **path) strcpy(windowsdir, "C:\\"); } - if (!(*path = VIR_STRDUP(windowsdir))) { - virReportOOMError(); + if (!(*path = VIR_STRDUP(windowsdir))) ret = -1; - } return ret; } @@ -2515,12 +2467,8 @@ virGetUserDirectory(void) /* USERPROFILE is probably the closest equivalent to $HOME? */ dir = getenv("USERPROFILE"); - if (dir) { - if (!(ret = VIR_STRDUP(dir))) { - virReportOOMError(); - return NULL; - } - } + if (dir && !(ret = VIR_STRDUP(dir))) + return NULL; if (!ret && virGetWin32SpecialFolder(CSIDL_PROFILE, &ret) < 0) @@ -2970,10 +2918,8 @@ virGetUnprivSGIOSysfsPath(const char *path, if (virAsprintf(&sysfs_path, "%s/%d:%d/queue/unpriv_sgio", sysfs_dir ? sysfs_dir : SYSFS_DEV_BLOCK_PATH, - maj, min) < 0) { - virReportOOMError(); + maj, min) < 0) return NULL; - } return sysfs_path; } @@ -2997,10 +2943,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); @@ -3081,10 +3025,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; @@ -3118,10 +3060,8 @@ virIsCapableFCHost(const char *sysfs_prefix, if (virAsprintf(&sysfs_path, "%shost%d", sysfs_prefix ? sysfs_prefix : SYSFS_FC_HOST_PATH, - host) < 0) { - virReportOOMError(); + host) < 0) return -1; - } if (access(sysfs_path, F_OK) == 0) ret = 0; @@ -3142,19 +3082,15 @@ virIsCapableVport(const char *sysfs_prefix, "%shost%d%s", sysfs_prefix ? sysfs_prefix : SYSFS_FC_HOST_PATH, host, - "vport_create") < 0) { - virReportOOMError(); + "vport_create") < 0) return -1; - } if (virAsprintf(&scsi_host_path, "%shost%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)) @@ -3193,10 +3129,8 @@ virManageVport(const int parent_host, "%shost%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); @@ -3204,10 +3138,8 @@ virManageVport(const int parent_host, "%shost%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, @@ -3220,10 +3152,8 @@ virManageVport(const int parent_host, if (virAsprintf(&vport_name, "%s:%s", wwnn, - wwpn) < 0) { - virReportOOMError(); + wwpn) < 0) goto cleanup; - } if (virFileWriteStr(operation_path, vport_name, 0) == 0) ret = 0; diff --git a/src/util/virxml.c b/src/util/virxml.c index ce8496e..634817c 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -89,9 +89,6 @@ virXPathString(const char *xpath, } ret = VIR_STRDUP((char *) obj->stringval); xmlXPathFreeObject(obj); - if (ret == NULL) { - virReportOOMError(); - } return ret; } @@ -610,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, diff --git a/src/vbox/vbox_MSCOMGlue.c b/src/vbox/vbox_MSCOMGlue.c index 6cebfaf..fc4e6b3 100644 --- a/src/vbox/vbox_MSCOMGlue.c +++ b/src/vbox/vbox_MSCOMGlue.c @@ -369,10 +369,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); @@ -531,10 +529,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 afc0283..a06d5b1 100644 --- a/src/vbox/vbox_XPCOMCGlue.c +++ b/src/vbox/vbox_XPCOMCGlue.c @@ -91,10 +91,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) { @@ -107,10 +105,8 @@ tryLoadOne(const char *dir, bool setAppHome, bool ignoreMissing, } else { name = VIR_STRDUP(DYNLIB_NAME); - if (name == NULL) { - virReportOOMError(); + if (name == NULL) return -1; - } } /* diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index a61d755..becb0af 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -1039,10 +1039,8 @@ static virDrvOpenStatus vboxOpen(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 || @@ -1845,12 +1843,7 @@ static char *vboxDomainGetOSType(virDomainPtr dom ATTRIBUTE_UNUSED) { * is supposed to pass the ABI name and not the domain * operating system driver as I had imagined ;) */ - char *osType = VIR_STRDUP("hvm"); - - if (osType == NULL) - virReportOOMError(); - - return osType; + return VIR_STRDUP("hvm"); } static int vboxDomainSetMemory(virDomainPtr dom, unsigned long memory) { @@ -2238,10 +2231,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); @@ -2416,12 +2407,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 */ @@ -2467,13 +2455,6 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) { sdlPresent = 1; if (valueDisplayUtf8) sdlDisplay = VIR_STRDUP(valueDisplayUtf8); - if (sdlDisplay == NULL) { - virReportOOMError(); - /* just don't go to cleanup yet as it is ok to have - * sdlDisplay as NULL and we check it below if it - * exist and then only use it there - */ - } totalPresent++; } @@ -2481,13 +2462,6 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) { guiPresent = 1; if (valueDisplayUtf8) guiDisplay = VIR_STRDUP(valueDisplayUtf8); - if (guiDisplay == NULL) { - virReportOOMError(); - /* just don't go to cleanup yet as it is ok to have - * guiDisplay as NULL and we check it below if it - * exist and then only use it there - */ - } totalPresent++; } VBOX_UTF8_FREE(valueDisplayUtf8); @@ -2519,12 +2493,6 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) { tmp = getenv("DISPLAY"); if (tmp != NULL) { def->graphics[def->ngraphics]->data.desktop.display = VIR_STRDUP(tmp); - if (def->graphics[def->ngraphics]->data.desktop.display == NULL) { - virReportOOMError(); - /* just don't go to cleanup yet as it is ok to have - * display as NULL - */ - } } totalPresent++; def->ngraphics++; @@ -2637,8 +2605,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(); + } } } @@ -2732,13 +2699,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; } @@ -2791,7 +2756,6 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) { if (!(def->disks[diskCount]->src)) { VBOX_RELEASE(medium); VBOX_RELEASE(storageController); - virReportOOMError(); error = true; break; } @@ -2867,10 +2831,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]; @@ -2880,10 +2842,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; @@ -2893,10 +2853,8 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) { VBOX_UTF8_FREE(hostPath); VBOX_UTF16_FREE(hostPathUtf16); - if (def->fss[i]->src == NULL) { - virReportOOMError(); + if (def->fss[i]->src == NULL) goto sharedFoldersCleanup; - } sharedFolder->vtbl->GetName(sharedFolder, &nameUtf16); VBOX_UTF16_TO_UTF8(nameUtf16, &name); @@ -2904,10 +2862,8 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) { VBOX_UTF8_FREE(name); VBOX_UTF16_FREE(nameUtf16); - if (def->fss[i]->dst == NULL) { - virReportOOMError(); + if (def->fss[i]->dst == NULL) goto sharedFoldersCleanup; - } sharedFolder->vtbl->GetWritable(sharedFolder, &writable); def->fss[i]->readonly = !writable; @@ -2940,11 +2896,8 @@ 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(); - } + for (i = 0; i < def->nnets; i++) + ignore_value(VIR_ALLOC(def->nets[i])); } /* Now get the details about the network cards here */ @@ -3090,11 +3043,9 @@ sharedFoldersCleanup: } else { VIR_FREE(def->sounds); def->nsounds = 0; - virReportOOMError(); } } else { def->nsounds = 0; - virReportOOMError(); } } VBOX_RELEASE(audioAdapter); @@ -3129,11 +3080,9 @@ sharedFoldersCleanup: def->disks[def->ndisks - 1]->dst = VIR_STRDUP("hdc"); } else { def->ndisks--; - virReportOOMError(); } } else { def->ndisks--; - virReportOOMError(); } VBOX_UTF8_FREE(location); @@ -3176,11 +3125,9 @@ sharedFoldersCleanup: def->disks[def->ndisks - 1]->dst = VIR_STRDUP("fda"); } else { def->ndisks--; - virReportOOMError(); } } else { def->ndisks--; - virReportOOMError(); } VBOX_UTF8_FREE(location); @@ -3216,11 +3163,8 @@ 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(); - } + for (i = 0; i < def->nserials; i++) + ignore_value(VIR_ALLOC(def->serials[i])); } /* Now get the details about the serial ports here */ @@ -3300,11 +3244,8 @@ 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(); - } + for (i = 0; i < def->nparallels; i++) + ignore_value(VIR_ALLOC(def->parallels[i])); } /* Now get the details about the parallel ports here */ @@ -3420,12 +3361,10 @@ sharedFoldersCleanup: VBOX_UTF8_FREE(productIdUtf8); USBFilterCount++; - } else - virReportOOMError(); + } } } - } else - virReportOOMError(); + } } } @@ -3487,7 +3426,6 @@ static int vboxListDefinedDomains(virConnectPtr conn, char ** const names, int m VBOX_UTF16_FREE(machineNameUtf16); VBOX_UTF8_FREE(machineName); if (!names[j]) { - virReportOOMError(); for (; j >= 0 ; j--) VIR_FREE(names[j]); ret = -1; @@ -3591,13 +3529,6 @@ vboxStartMachine(virDomainPtr dom, int i, IMachine *machine, sdlPresent = 1; if (valueDisplayUtf8) { sdlDisplay = VIR_STRDUP(valueDisplayUtf8); - if (sdlDisplay == NULL) { - virReportOOMError(); - /* just don't go to cleanup yet as it is ok to have - * sdlDisplay as NULL and we check it below if it - * exist and then only use it there - */ - } } } @@ -3605,13 +3536,6 @@ vboxStartMachine(virDomainPtr dom, int i, IMachine *machine, guiPresent = 1; if (valueDisplayUtf8) { guiDisplay = VIR_STRDUP(valueDisplayUtf8); - if (guiDisplay == NULL) { - virReportOOMError(); - /* just don't go to cleanup yet as it is ok to have - * guiDisplay as NULL and we check it below if it - * exist and then only use it there - */ - } } } } @@ -3637,9 +3561,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); } @@ -3652,9 +3574,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); } @@ -4806,31 +4726,15 @@ vboxAttachDisplay(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine) if ((def->graphics[i]->type == VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP) && (guiPresent == 0)) { guiPresent = 1; - if (def->graphics[i]->data.desktop.display) { + if (def->graphics[i]->data.desktop.display) guiDisplay = VIR_STRDUP(def->graphics[i]->data.desktop.display); - if (guiDisplay == NULL) { - virReportOOMError(); - /* just don't go to cleanup yet as it is ok to have - * guiDisplay as NULL and we check it below if it - * exist and then only use it there - */ - } - } } if ((def->graphics[i]->type == VIR_DOMAIN_GRAPHICS_TYPE_SDL) && (sdlPresent == 0)) { sdlPresent = 1; - if (def->graphics[i]->data.sdl.display) { + if (def->graphics[i]->data.sdl.display) sdlDisplay = VIR_STRDUP(def->graphics[i]->data.sdl.display); - if (sdlDisplay == NULL) { - virReportOOMError(); - /* just don't go to cleanup yet as it is ok to have - * sdlDisplay as NULL and we check it below if it - * exist and then only use it there - */ - } - } } } @@ -4958,9 +4862,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, @@ -5385,17 +5287,13 @@ static int vboxDomainAttachDeviceImpl(virDomainPtr dom, virDomainDeviceDefPtr dev = NULL; nsresult rc; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return ret; - } def->os.type = VIR_STRDUP("hvm"); - if (def->os.type == NULL) { - virReportOOMError(); + if (def->os.type == NULL) goto cleanup; - } dev = virDomainDeviceDefParse(data->caps, def, xml, VIR_DOMAIN_XML_INACTIVE); @@ -5620,17 +5518,13 @@ 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; - } def->os.type = VIR_STRDUP("hvm"); - if (def->os.type == NULL) { - virReportOOMError(); + if (def->os.type == NULL) goto cleanup; - } dev = virDomainDeviceDefParse(data->caps, def, xml, VIR_DOMAIN_XML_INACTIVE); @@ -5788,10 +5682,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); @@ -6057,7 +5949,7 @@ vboxDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot, if (VIR_ALLOC(def) < 0 || !(def->name = VIR_STRDUP(snapshot->name))) - goto no_memory; + goto cleanup; rc = snap->vtbl->GetDescription(snap, &str16); if (NS_FAILED(rc)) { @@ -6072,7 +5964,7 @@ vboxDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot, def->description = VIR_STRDUP(str8); VBOX_UTF8_FREE(str8); if (!def->description) - goto no_memory; + goto cleanup; } rc = snap->vtbl->GetTimeStamp(snap, ×tamp); @@ -6105,7 +5997,7 @@ vboxDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot, def->parent = VIR_STRDUP(str8); VBOX_UTF8_FREE(str8); if (!def->parent) - goto no_memory; + goto cleanup; } rc = snap->vtbl->GetOnline(snap, &online); @@ -6130,10 +6022,6 @@ cleanup: VBOX_RELEASE(machine); vboxIIDUnalloc(&domiid); return ret; - -no_memory: - virReportOOMError(); - goto cleanup; } static int @@ -6216,10 +6104,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 */ @@ -6254,10 +6140,8 @@ vboxDomainSnapshotListNames(virDomainPtr dom, VBOX_UTF16_FREE(nameUtf16); names[i] = VIR_STRDUP(name); VBOX_UTF8_FREE(name); - if (!names[i]) { - virReportOOMError(); + if (!names[i]) goto cleanup; - } } if (count <= nameslen) @@ -7205,7 +7089,6 @@ static IVirtualBoxCallback *vboxAllocCallbackObj(void) { */ if ((VIR_ALLOC(vboxCallback) < 0) || (VIR_ALLOC(vboxCallback->vtbl) < 0)) { VIR_FREE(vboxCallback); - virReportOOMError(); return NULL; } @@ -7535,11 +7418,8 @@ static int vboxListNetworks(virConnectPtr conn, char **const names, int nnames) VIR_DEBUG("nnames[%d]: %s", ret, nameUtf8); names[ret] = VIR_STRDUP(nameUtf8); - if (names[ret] == NULL) { - virReportOOMError(); - } else { + if (names[ret]) ret++; - } VBOX_UTF8_FREE(nameUtf8); VBOX_UTF16_FREE(nameUtf16); @@ -7617,11 +7497,8 @@ static int vboxListDefinedNetworks(virConnectPtr conn, char **const names, int n VIR_DEBUG("nnames[%d]: %s", ret, nameUtf8); names[ret] = VIR_STRDUP(nameUtf8); - if (names[ret] == NULL) { - virReportOOMError(); - } else { + if (names[ret] == NULL) ret++; - } VBOX_UTF8_FREE(nameUtf8); VBOX_UTF16_FREE(nameUtf16); @@ -7790,7 +7667,6 @@ static virNetworkPtr vboxNetworkDefineCreateXML(virConnectPtr conn, const char * if (virAsprintf(&networkNameUtf8, "HostInterfaceNetworking-%s", networkInterfaceNameUtf8) < 0) { VBOX_RELEASE(host); VBOX_RELEASE(networkInterface); - virReportOOMError(); goto cleanup; } } @@ -7935,10 +7811,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); @@ -8024,10 +7898,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); @@ -8096,21 +7968,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); @@ -8175,7 +8041,6 @@ static char *vboxNetworkGetXMLDesc(virNetworkPtr network, } } else { ipdef->nranges = 0; - virReportOOMError(); } ipdef->nhosts = 1; @@ -8184,7 +8049,6 @@ static char *vboxNetworkGetXMLDesc(virNetworkPtr network, if (ipdef->hosts[0].name == NULL) { VIR_FREE(ipdef->hosts); ipdef->nhosts = 0; - virReportOOMError(); } else { PRUnichar *macAddressUtf16 = NULL; PRUnichar *ipAddressUtf16 = NULL; @@ -8238,11 +8102,8 @@ static char *vboxNetworkGetXMLDesc(virNetworkPtr network, DEBUGIID("Network UUID", vboxnet0IID.value); vboxIIDUnalloc(&vboxnet0IID); VBOX_UTF16_FREE(networkNameUtf16); - } else { - virReportOOMError(); } } - VBOX_RELEASE(networkInterface); } @@ -8303,11 +8164,8 @@ static int vboxStorageListPools(virConnectPtr conn ATTRIBUTE_UNUSED, if (nnames == 1) { names[numActive] = VIR_STRDUP("default-pool"); - if (names[numActive] == NULL) { - virReportOOMError(); - } else { + if (names[numActive]) numActive++; - } } return numActive; } @@ -8391,11 +8249,8 @@ static int vboxStoragePoolListVolumes(virStoragePoolPtr pool, char **const names if (nameUtf8) { VIR_DEBUG("nnames[%d]: %s", numActive, nameUtf8); names[numActive] = VIR_STRDUP(nameUtf8); - if (names[numActive] == NULL) { - virReportOOMError(); - } else { + if (names[numActive]) numActive++; - } VBOX_UTF8_FREE(nameUtf8); } @@ -9094,8 +8949,6 @@ static char *vboxStorageVolGetPath(virStorageVolPtr vol) { if (hddLocationUtf8) { ret = VIR_STRDUP(hddLocationUtf8); - if (!ret) - virReportOOMError(); VIR_DEBUG("Storage Volume Name: %s", vol->name); VIR_DEBUG("Storage Volume Path: %s", hddLocationUtf8); @@ -9158,7 +9011,6 @@ vboxDomainScreenshot(virDomainPtr dom, } if (virAsprintf(&tmp, "%s/cache/libvirt/vbox.screendump.XXXXXX", LOCALSTATEDIR) < 0) { - virReportOOMError(); VBOX_RELEASE(machine); return NULL; } @@ -9279,7 +9131,7 @@ vboxListAllDomains(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; @@ -9294,7 +9146,7 @@ vboxListAllDomains(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]; @@ -9395,10 +9247,6 @@ cleanup: vboxArrayRelease(&machines); return ret; - -no_memory: - virReportOOMError(); - goto cleanup; } #undef MATCH diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c index babc81a..b772001 100644 --- a/src/vmware/vmware_conf.c +++ b/src/vmware/vmware_conf.c @@ -87,10 +87,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(); @@ -187,10 +185,8 @@ vmwareLoadDomains(struct vmware_driver *driver) pDomain = vm->privateData; pDomain->vmxPath = VIR_STRDUP(vmxPath); - if (pDomain->vmxPath == NULL) { - virReportOOMError(); + if (pDomain->vmxPath == NULL) goto cleanup; - } vmwareDomainConfigDisplay(pDomain, vmdef); @@ -324,7 +320,6 @@ vmwareParsePath(char *path, char **directory, char **filename) return 0; no_memory: - virReportOOMError(); return -1; } @@ -332,16 +327,10 @@ 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(); + if (virAsprintf(vmxPath, "%s/%s.vmx", directoryName, name) < 0) return -1; - } - } + } else if (virAsprintf(vmxPath, "%s.vmx", name) < 0) + return -1; return 0; } @@ -401,10 +390,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; @@ -443,11 +430,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 @@ -464,10 +447,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; @@ -504,12 +485,5 @@ cleanup: char * vmwareCopyVMXFileName(const char *datastorePath, void *opaque ATTRIBUTE_UNUSED) { - char *path = VIR_STRDUP(datastorePath); - - if (path == NULL) { - virReportOOMError(); - return NULL; - } - - return path; + return VIR_STRDUP(datastorePath); } diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c index c133ebd..559126a 100644 --- a/src/vmware/vmware_driver.c +++ b/src/vmware/vmware_driver.c @@ -126,10 +126,8 @@ vmwareOpen(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; @@ -353,10 +351,8 @@ vmwareDomainDefineXML(virConnectPtr conn, const char *xml) goto cleanup; pDomain = vm->privateData; - if ((pDomain->vmxPath = VIR_STRDUP(vmxPath)) == NULL) { - virReportOOMError(); + if ((pDomain->vmxPath = VIR_STRDUP(vmxPath)) == NULL) goto cleanup; - } vmwareDomainConfigDisplay(pDomain, vmdef); @@ -788,10 +784,9 @@ vmwareGetOSType(virDomainPtr dom) goto cleanup; } - if (!(ret = VIR_STRDUP(vm->def->os.type))) - virReportOOMError(); + ret = VIR_STRDUP(vm->def->os.type); - cleanup: +cleanup: if (vm) virObjectUnlock(vm); return ret; diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index 0f771cb..3dad170 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -539,10 +539,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 */ @@ -671,10 +669,8 @@ virVMXGetConfigString(virConfPtr conf, const char *name, char **string, *string = VIR_STRDUP(value->str); - if (*string == NULL) { - virReportOOMError(); + if (*string == NULL) return -1; - } return 0; } @@ -1114,10 +1110,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]; @@ -1278,10 +1272,8 @@ virVMXParseConfig(virVMXContext *ctx, virCapsPtr caps, const char *vmx) } /* 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; @@ -1423,10 +1415,8 @@ virVMXParseConfig(virVMXContext *ctx, virCapsPtr caps, const char *vmx) cpumasklen = 0; def->cpumask = virBitmapNew(VIR_DOMAIN_CPUMASK_LEN); - if (!def->cpumask) { - virReportOOMError(); + if (!def->cpumask) goto cleanup; - } while (*current != '\0') { virSkipSpaces(¤t); @@ -1513,10 +1503,8 @@ virVMXParseConfig(virVMXContext *ctx, virCapsPtr caps, const char *vmx) /* def:os */ def->os.type = VIR_STRDUP("hvm"); - if (def->os.type == NULL) { - virReportOOMError(); + if (def->os.type == NULL) goto cleanup; - } /* vmx:guestOS -> def:os.arch */ if (virVMXGetConfigString(conf, "guestOS", &guestOS, true) < 0) { @@ -1546,10 +1534,8 @@ virVMXParseConfig(virVMXContext *ctx, virCapsPtr caps, const char *vmx) /* 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; @@ -1562,10 +1548,8 @@ virVMXParseConfig(virVMXContext *ctx, virCapsPtr caps, const char *vmx) } /* 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; @@ -1687,10 +1671,8 @@ virVMXParseConfig(virVMXContext *ctx, virCapsPtr caps, const char *vmx) 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; @@ -1708,10 +1690,8 @@ virVMXParseConfig(virVMXContext *ctx, virCapsPtr caps, const char *vmx) } /* def:nets */ - if (VIR_ALLOC_N(def->nets, 4) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(def->nets, 4) < 0) goto cleanup; - } def->nnets = 0; @@ -1730,10 +1710,8 @@ virVMXParseConfig(virVMXContext *ctx, virCapsPtr caps, const char *vmx) /* 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; @@ -1750,10 +1728,8 @@ virVMXParseConfig(virVMXContext *ctx, virCapsPtr caps, const char *vmx) /* 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; @@ -1769,10 +1745,8 @@ virVMXParseConfig(virVMXContext *ctx, virCapsPtr caps, const char *vmx) } /* def:parallels */ - if (VIR_ALLOC_N(def->parallels, 3) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(def->parallels, 3) < 0) goto cleanup; - } def->nparallels = 0; @@ -1827,10 +1801,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; @@ -2001,10 +1973,8 @@ virVMXParseDisk(virVMXContext *ctx, virCapsPtr caps, virConfPtr conf, return -1; } - if (VIR_ALLOC(*def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(*def) < 0) return -1; - } (*def)->device = device; (*def)->bus = busType; @@ -2027,10 +1997,8 @@ virVMXParseDisk(virVMXContext *ctx, virCapsPtr caps, virConfPtr conf, 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 @@ -2053,10 +2021,8 @@ virVMXParseDisk(virVMXContext *ctx, virCapsPtr caps, virConfPtr conf, 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"); @@ -2086,10 +2052,8 @@ virVMXParseDisk(virVMXContext *ctx, virCapsPtr caps, virConfPtr conf, goto cleanup; } - if (virAsprintf(&prefix, "floppy%d", unit) < 0) { - virReportOOMError(); + if (virAsprintf(&prefix, "floppy%d", unit) < 0) goto cleanup; - } (*def)->dst = virIndexToDiskName(unit, "fd"); @@ -2342,10 +2306,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; @@ -2467,10 +2429,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); @@ -2566,10 +2526,8 @@ virVMXParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def) virtualDev = VIR_STRDUP("vmxnet2"); - if (virtualDev == NULL) { - virReportOOMError(); + if (virtualDev == NULL) goto cleanup; - } } } @@ -2583,10 +2541,8 @@ virVMXParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def) if (networkName == NULL) { networkName = VIR_STRDUP(""); - if (networkName == NULL) { - virReportOOMError(); + if (networkName == NULL) goto cleanup; - } } } @@ -2695,10 +2651,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; @@ -2784,16 +2738,12 @@ virVMXParseSerial(virVMXContext *ctx, virConfPtr conf, int port, (*def)->source.data.tcp.host = VIR_STRDUP(parsedUri->server); - if ((*def)->source.data.tcp.host == NULL) { - virReportOOMError(); + if ((*def)->source.data.tcp.host == NULL) 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 || @@ -2892,10 +2842,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; @@ -2990,10 +2938,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; diff --git a/src/xen/block_stats.c b/src/xen/block_stats.c index df9785e..abfd72a 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); @@ -297,10 +295,8 @@ xenLinuxDomainDeviceID(int domid, const char *path) else retval = virAsprintf(&mod_path, "/dev/%s", path); - if (retval < 0) { - virReportOOMError(); + if (retval < 0) return -1; - } retval = -1; diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c index 40a2804..e190e4c 100644 --- a/src/xen/xen_driver.c +++ b/src/xen/xen_driver.c @@ -158,14 +158,10 @@ 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) { @@ -327,10 +323,8 @@ xenUnifiedOpen(virConnectPtr conn, virConnectAuthPtr auth, unsigned int flags) * here, don't return DECLINED, always use 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")); @@ -414,10 +408,8 @@ xenUnifiedOpen(virConnectPtr conn, virConnectAuthPtr auth, unsigned int flags) } #endif - if (virAsprintf(&priv->saveDir, "%s", XEN_SAVE_DIR) == -1) { - virReportOOMError(); + if (virAsprintf(&priv->saveDir, "%s", XEN_SAVE_DIR) == -1) goto fail; - } if (virFileMakePath(priv->saveDir) < 0) { VIR_ERROR(_("Failed to create save dir '%s': %s"), priv->saveDir, @@ -810,10 +802,8 @@ xenUnifiedDomainIsPersistent(virDomainPtr dom) * 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 done; - } if (access(path, R_OK) == 0) ret = 1; else if (errno == ENOENT) @@ -1107,10 +1097,8 @@ xenUnifiedDomainManagedSavePath(xenUnifiedPrivatePtr priv, virDomainPtr dom) { char *ret; - if (virAsprintf(&ret, "%s/%s.save", priv->saveDir, dom->name) < 0) { - virReportOOMError(); + if (virAsprintf(&ret, "%s/%s.save", priv->saveDir, dom->name) < 0) return NULL; - } VIR_DEBUG("managed save image: %s", ret); return ret; @@ -1444,10 +1432,8 @@ xenUnifiedDomainXMLToNative(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); @@ -2144,10 +2130,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 = xenUnifiedListDomains(conn, &ids[0], numdomains)) < 0) { goto out; } @@ -2158,10 +2142,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 */ @@ -2472,7 +2454,6 @@ xenUnifiedAddDomainInfo(xenUnifiedDomainInfoListPtr list, list->count++; return 0; memory_error: - virReportOOMError(); if (info) VIR_FREE(info->name); VIR_FREE(info); diff --git a/src/xen/xen_hypervisor.c b/src/xen/xen_hypervisor.c index 6480d2a..57f3aab 100644 --- a/src/xen/xen_hypervisor.c +++ b/src/xen/xen_hypervisor.c @@ -1201,15 +1201,11 @@ xenHypervisorGetSchedulerType(virDomainPtr domain, int *nparams) switch (op.u.getschedulerid.sched_id){ case XEN_SCHEDULER_SEDF: schedulertype = VIR_STRDUP("sedf"); - if (schedulertype == NULL) - virReportOOMError(); if (nparams) *nparams = XEN_SCHED_SEDF_NPARAM; break; case XEN_SCHEDULER_CREDIT: schedulertype = VIR_STRDUP("credit"); - if (schedulertype == NULL) - virReportOOMError(); if (nparams) *nparams = XEN_SCHED_CRED_NPARAM; break; @@ -1746,10 +1742,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; @@ -2066,10 +2060,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) { @@ -2481,7 +2473,6 @@ xenHypervisorMakeCapabilitiesSunOS(virConnectPtr conn) { struct guest_arch guest_arches[32]; int i = 0; - virCapsPtr caps = NULL; int pae, longmode; const char *hvm; @@ -2522,13 +2513,10 @@ xenHypervisorMakeCapabilitiesSunOS(virConnectPtr conn) } } - if ((caps = xenHypervisorBuildCapabilities(conn, - virArchFromHost(), - pae, hvm, - guest_arches, i)) == NULL) - virReportOOMError(); - - return caps; + return xenHypervisorBuildCapabilities(conn, + virArchFromHost(), + pae, hvm, + guest_arches, i); } #endif /* __sun */ @@ -2787,10 +2775,8 @@ xenHypervisorNumOfDomains(virConnectPtr conn) return -1; retry: - if (!(XEN_GETDOMAININFOLIST_ALLOC(dominfos, maxids))) { - virReportOOMError(); + if (!(XEN_GETDOMAININFOLIST_ALLOC(dominfos, maxids))) return -1; - } XEN_GETDOMAININFOLIST_CLEAR(dominfos, maxids); @@ -2843,10 +2829,8 @@ xenHypervisorListDomains(virConnectPtr conn, int *ids, int maxids) if (maxids == 0) return 0; - if (!(XEN_GETDOMAININFOLIST_ALLOC(dominfos, maxids))) { - virReportOOMError(); + if (!(XEN_GETDOMAININFOLIST_ALLOC(dominfos, maxids))) return -1; - } XEN_GETDOMAININFOLIST_CLEAR(dominfos, maxids); memset(ids, 0, maxids * sizeof(int)); @@ -2913,9 +2897,6 @@ xenHypervisorDomainGetOSType(virDomainPtr dom) else ostype = VIR_STRDUP("linux"); - if (ostype == NULL) - virReportOOMError(); - return ostype; } @@ -2985,10 +2966,8 @@ xenHypervisorLookupDomainByUUID(virConnectPtr conn, const unsigned char *uuid) return NULL; retry: - if (!(XEN_GETDOMAININFOLIST_ALLOC(dominfos, maxids))) { - virReportOOMError(); + if (!(XEN_GETDOMAININFOLIST_ALLOC(dominfos, maxids))) return NULL; - } XEN_GETDOMAININFOLIST_CLEAR(dominfos, maxids); diff --git a/src/xen/xen_inotify.c b/src/xen/xen_inotify.c index cdad9ee..34fc020 100644 --- a/src/xen/xen_inotify.c +++ b/src/xen/xen_inotify.c @@ -68,7 +68,6 @@ xenInotifyXenCacheLookup(virConnectPtr conn, if (!*name) { VIR_DEBUG("Error getting dom from def"); - virReportOOMError(); return -1; } return 0; @@ -109,10 +108,8 @@ xenInotifyXendDomainsDirLookup(virConnectPtr conn, for (i = 0 ; i < priv->configInfoList->count ; i++) { if (!memcmp(rawuuid, priv->configInfoList->doms[i]->uuid, VIR_UUID_BUFLEN)) { *name = VIR_STRDUP(priv->configInfoList->doms[i]->name); - if (!*name) { - virReportOOMError(); + if (!*name) return -1; - } memcpy(uuid, priv->configInfoList->doms[i]->uuid, VIR_UUID_BUFLEN); VIR_DEBUG("Found dom on list"); return 0; @@ -124,7 +121,6 @@ xenInotifyXendDomainsDirLookup(virConnectPtr conn, } if (!(*name = VIR_STRDUP(dom->name))) { - virReportOOMError(); virDomainFree(dom); return -1; } @@ -369,10 +365,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 b0a98fd..fa2ff55 100644 --- a/src/xen/xend_internal.c +++ b/src/xen/xend_internal.c @@ -272,10 +272,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")) @@ -304,10 +302,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) @@ -751,10 +747,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; @@ -889,10 +883,8 @@ xenDaemonDomainLookupByID(virConnectPtr xend, } if (domname) { *domname = VIR_STRDUP(name); - if (*domname == NULL) { - virReportOOMError(); + if (*domname == NULL) goto error; - } } if (sexpr_uuid(uuid, root, "domain/uuid") < 0) { @@ -1120,7 +1112,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) @@ -1129,7 +1121,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++) { @@ -1142,7 +1134,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; } @@ -1154,10 +1146,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; } @@ -1270,10 +1258,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", @@ -1460,9 +1446,6 @@ xenDaemonDomainGetOSType(virDomainPtr domain) type = VIR_STRDUP("linux"); } - if (type == NULL) - virReportOOMError(); - sexpr_free(root); return type; @@ -2146,10 +2129,8 @@ xenDaemonDomainPinVcpu(virDomainPtr domain, 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, @@ -2363,13 +2344,9 @@ xenDaemonLookupByUUID(virConnectPtr conn, const unsigned char *uuid) else id = -1; - if (domname) { + if (domname) name = VIR_STRDUP(domname); - if (name == NULL) - virReportOOMError(); - } - sexpr_free(root); } @@ -2533,10 +2510,8 @@ xenDaemonAttachDeviceFlags(virDomainPtr domain, goto cleanup; if (dev->data.disk->device != VIR_DOMAIN_DISK_DEVICE_CDROM) { - if (!(target = VIR_STRDUP(dev->data.disk->dst))) { - virReportOOMError(); + if (!(target = VIR_STRDUP(dev->data.disk->dst))) goto cleanup; - } } break; @@ -2551,10 +2526,8 @@ xenDaemonAttachDeviceFlags(virDomainPtr domain, char macStr[VIR_MAC_STRING_BUFLEN]; virMacAddrFormat(&dev->data.net->mac, macStr); - if (!(target = VIR_STRDUP(macStr))) { - virReportOOMError(); + if (!(target = VIR_STRDUP(macStr))) goto cleanup; - } break; case VIR_DOMAIN_DEVICE_HOSTDEV: @@ -2567,10 +2540,8 @@ xenDaemonAttachDeviceFlags(virDomainPtr domain, PCIAddr = dev->data.hostdev->source.subsys.u.pci; 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")); @@ -2888,10 +2859,8 @@ xenDaemonDomainSetAutostart(virDomainPtr domain, int autostart) VIR_FREE(autonode->u.s.car->u.value); autonode->u.s.car->u.value = (autostart ? VIR_STRDUP("start") : VIR_STRDUP("ignore")); - if (!(autonode->u.s.car->u.value)) { - virReportOOMError(); + if (!(autonode->u.s.car->u.value)) goto error; - } if (sexpr2string(root, &buffer) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -3052,7 +3021,6 @@ xenDaemonDomainMigratePerform(virDomainPtr domain, } hostname = VIR_STRDUP(uriptr->server); if (!hostname) { - virReportOOMError(); virURIFree(uriptr); return -1; } @@ -3073,18 +3041,14 @@ xenDaemonDomainMigratePerform(virDomainPtr domain, /* Get the hostname. */ n = p - uri; /* n = Length of hostname in bytes. */ hostname = VIR_STRDUP(uri); - if (!hostname) { - virReportOOMError(); + if (!hostname) return -1; - } hostname[n] = '\0'; } else { /* "hostname" (or IP address) */ hostname = VIR_STRDUP(uri); - if (!hostname) { - virReportOOMError(); + if (!hostname) return -1; - } } VIR_DEBUG("hostname = %s, port = %s", hostname, port); @@ -3263,10 +3227,8 @@ xenDaemonListDefinedDomains(virConnectPtr conn, if (node->kind != SEXPR_VALUE) continue; - if ((names[ret++] = VIR_STRDUP(node->u.value)) == NULL) { - virReportOOMError(); + if ((names[ret++] = VIR_STRDUP(node->u.value)) == NULL) goto error; - } if (ret >= maxnames) break; @@ -3323,18 +3285,14 @@ xenDaemonGetSchedulerType(virDomainPtr domain, int *nparams) } if (STREQ(ret, "credit")) { schedulertype = VIR_STRDUP("credit"); - if (schedulertype == NULL){ - virReportOOMError(); + if (schedulertype == NULL) goto error; - } if (nparams) *nparams = XEN_SCHED_CRED_NPARAM; } else if (STREQ(ret, "sedf")) { schedulertype = VIR_STRDUP("sedf"); - if (schedulertype == NULL){ - virReportOOMError(); + if (schedulertype == NULL) goto error; - } if (nparams) *nparams = XEN_SCHED_SEDF_NPARAM; } else { @@ -3759,10 +3717,8 @@ virDomainXMLDevID(virDomainPtr domain, def->source.subsys.u.pci.domain, def->source.subsys.u.pci.bus, def->source.subsys.u.pci.slot, - def->source.subsys.u.pci.function) < 0) { - virReportOOMError(); + def->source.subsys.u.pci.function) < 0) return -1; - } strcpy(class, "pci"); diff --git a/src/xen/xm_internal.c b/src/xen/xm_internal.c index d537f99..6a995c6 100644 --- a/src/xen/xm_internal.c +++ b/src/xen/xm_internal.c @@ -256,12 +256,9 @@ 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 ((entry->filename = VIR_STRDUP(filename)) == NULL) { - virReportOOMError(); VIR_FREE(entry); return -1; } @@ -1081,10 +1078,8 @@ xenXMDomainDefineXML(virConnectPtr conn, const char *xml) 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, @@ -1092,10 +1087,8 @@ xenXMDomainDefineXML(virConnectPtr conn, const char *xml) goto error; } - if ((entry->filename = VIR_STRDUP(filename)) == NULL) { - virReportOOMError(); + if ((entry->filename = VIR_STRDUP(filename)) == NULL) goto error; - } entry->def = def; if (virHashAddEntry(priv->configCache, filename, entry) < 0) { @@ -1231,7 +1224,6 @@ xenXMListDefinedDomains(virConnectPtr conn, char **const names, int maxnames) for (i = 0; i < ctx.count; i++) VIR_FREE(ctx.names[i]); - virReportOOMError(); goto cleanup; } @@ -1318,20 +1310,16 @@ xenXMDomainAttachDeviceFlags(virDomainPtr domain, 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; @@ -1503,10 +1491,8 @@ xenXMDomainGetAutostart(virDomainPtr dom, int *autostart) char *config = xenXMDomainConfigName(dom); int ret = -1; - if (!linkname || !config) { - virReportOOMError(); + if (!linkname || !config) goto cleanup; - } *autostart = virFileLinkPointsTo(linkname, config); if (*autostart < 0) { @@ -1532,10 +1518,8 @@ xenXMDomainSetAutostart(virDomainPtr dom, int autostart) char *config = xenXMDomainConfigName(dom); 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 8264d7e..da48e19 100644 --- a/src/xen/xs_internal.c +++ b/src/xen/xs_internal.c @@ -247,18 +247,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", @@ -853,10 +849,6 @@ xenStoreDomainGetNetworkID(virConnectPtr conn, int id, const char *mac) if (match) { ret = VIR_STRDUP(list[i]); - - if (ret == NULL) - virReportOOMError(); - break; } } @@ -906,10 +898,6 @@ xenStoreDomainGetDiskID(virConnectPtr conn, int id, const char *dev) VIR_FREE(val); } else { ret = VIR_STRDUP(list[i]); - - if (ret == NULL) - virReportOOMError(); - VIR_FREE(val); VIR_FREE(list); return ret; @@ -929,10 +917,6 @@ xenStoreDomainGetDiskID(virConnectPtr conn, int id, const char *dev) VIR_FREE(val); } else { ret = VIR_STRDUP(list[i]); - - if (ret == NULL) - virReportOOMError(); - VIR_FREE(val); VIR_FREE(list); return ret; @@ -1118,9 +1102,6 @@ xenStoreAddWatch(virConnectPtr conn, VIR_FREE(watch->token); VIR_FREE(watch); } - - virReportOOMError(); - return -1; } @@ -1253,10 +1234,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 */ @@ -1337,10 +1316,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 */ diff --git a/src/xenapi/xenapi_driver.c b/src/xenapi/xenapi_driver.c index 02b0bc4..5e0d101 100644 --- a/src/xenapi/xenapi_driver.c +++ b/src/xenapi/xenapi_driver.c @@ -66,10 +66,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; @@ -128,10 +126,8 @@ xenapiOpen(virConnectPtr conn, virConnectAuthPtr auth, if (conn->uri->user != NULL) { username = VIR_STRDUP(conn->uri->user); - if (username == NULL) { - virReportOOMError(); + if (username == NULL) goto error; - } } else { username = virAuthGetUsername(conn, auth, "xen", NULL, conn->uri->server); @@ -150,15 +146,11 @@ xenapiOpen(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; @@ -312,7 +304,6 @@ xenapiGetVersion(virConnectPtr conn, unsigned long *hvVer) if (STREQ(result->contents[i].key, "xen")) { if (!(version = VIR_STRDUP(result->contents[i].val))) { xen_string_string_map_free(result); - virReportOOMError(); return -1; } break; @@ -942,8 +933,7 @@ xenapiDomainGetOSType(virDomainPtr dom) xenapiSessionErrorHandler(dom->conn, VIR_ERR_INTERNAL_ERROR, NULL); goto cleanup; } - if (!(ostype = (STREQ(boot_policy,"BIOS order") ? VIR_STRDUP("hvm") : VIR_STRDUP("xen")))) - virReportOOMError(); + ostype = STREQ(boot_policy,"BIOS order") ? VIR_STRDUP("hvm") : VIR_STRDUP("xen"); VIR_FREE(boot_policy); } else xenapiSessionErrorHandler(dom->conn, VIR_ERR_NO_DOMAIN, NULL); @@ -1261,7 +1251,6 @@ xenapiDomainGetVcpus(virDomainPtr dom, if (!(mask = VIR_STRDUP(vcpu_params->contents[i].val))){ xen_vm_set_free(vms); xen_string_string_map_free(vcpu_params); - virReportOOMError(); return -1; } break; @@ -1368,7 +1357,6 @@ xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) return NULL; } if (VIR_ALLOC(defPtr) < 0) { - virReportOOMError(); xen_vm_set_free(vms); return NULL; } @@ -1531,7 +1519,6 @@ xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) return xml; error_cleanup: - virReportOOMError(); xen_vm_set_free(vms); virDomainDefFree(defPtr); return NULL; @@ -1560,7 +1547,6 @@ xenapiListDefinedDomains(virConnectPtr conn, char **const names, if (record->is_a_template == 0) { char *usenames = NULL; if (!(usenames = VIR_STRDUP(record->name_label))) { - virReportOOMError(); xen_vm_record_free(record); xen_vm_set_free(result); while (--j >= 0) VIR_FREE(names[j]); @@ -1848,13 +1834,9 @@ xenapiDomainSetAutostart(virDomainPtr dom, int autostart) static char * xenapiDomainGetSchedulerType(virDomainPtr dom ATTRIBUTE_UNUSED, int *nparams) { - char *result = NULL; - if (nparams) *nparams = 0; - if (!(result = VIR_STRDUP("credit"))) - virReportOOMError(); - return result; + return VIR_STRDUP("credit"); } /* diff --git a/src/xenapi/xenapi_utils.c b/src/xenapi/xenapi_utils.c index 58d08ed..53c6730 100644 --- a/src/xenapi/xenapi_utils.c +++ b/src/xenapi/xenapi_utils.c @@ -347,17 +347,14 @@ 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 (!((*strings)->contents[sz-1].key = VIR_STRDUP(key))) goto error; if (!((*strings)->contents[sz-1].val = VIR_STRDUP(val))) goto error; return 0; - error: +error: xen_string_string_map_free(*strings); - virReportOOMError(); return -1; } @@ -560,7 +557,6 @@ createVMRecordFromXml(virConnectPtr conn, virDomainDefPtr def, return 0; error_cleanup: - virReportOOMError(); xen_vm_record_free(*record); return -1; } diff --git a/src/xenxs/xen_sxpr.c b/src/xenxs/xen_sxpr.c index 472da26..984aef7 100644 --- a/src/xenxs/xen_sxpr.c +++ b/src/xenxs/xen_sxpr.c @@ -163,7 +163,6 @@ xenParseSxprOS(const struct sexpr *node, return 0; no_memory: - virReportOOMError(); return -1; } @@ -194,7 +193,7 @@ xenParseSxprChar(const char *value, def->source.type = VIR_DOMAIN_CHR_TYPE_DEV; def->source.data.file.path = VIR_STRDUP(value); if (!def->source.data.file.path) - goto no_memory; + goto error; } else { if ((tmp = strchr(value, ':')) != NULL) { *tmp = '\0'; @@ -217,13 +216,13 @@ xenParseSxprChar(const char *value, case VIR_DOMAIN_CHR_TYPE_PTY: if (tty != NULL && !(def->source.data.file.path = VIR_STRDUP(tty))) - goto no_memory; + goto error; break; case VIR_DOMAIN_CHR_TYPE_FILE: case VIR_DOMAIN_CHR_TYPE_PIPE: if (!(def->source.data.file.path = VIR_STRDUP(value))) - goto no_memory; + goto error; break; case VIR_DOMAIN_CHR_TYPE_TCP: @@ -292,11 +291,11 @@ xenParseSxprChar(const char *value, if ((def->source.data.udp.bindService = VIR_STRDUP(offset3 + 1)) == NULL) - goto no_memory; + goto error; } else { if ((def->source.data.udp.connectService = VIR_STRDUP(offset + 1)) == NULL) - goto no_memory; + goto error; } } break; @@ -309,7 +308,7 @@ xenParseSxprChar(const char *value, else def->source.data.nix.path = VIR_STRDUP(value); if (def->source.data.nix.path == NULL) - goto no_memory; + goto error; if (offset != NULL && strstr(offset, ",server") != NULL) @@ -381,7 +380,7 @@ xenParseSxprDisks(virDomainDefPtr def, } if (VIR_ALLOC(disk) < 0) - goto no_memory; + goto error; if (dst == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -412,10 +411,10 @@ xenParseSxprDisks(virDomainDefPtr def, if (sexpr_lookup(node, "device/tap2") && STRPREFIX(src, "tap:")) { if (!(disk->driverName = VIR_STRDUP("tap2"))) - goto no_memory; + 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, @@ -491,10 +490,10 @@ xenParseSxprDisks(virDomainDefPtr def, } if (!(disk->dst = VIR_STRDUP(dst))) - goto no_memory; + goto error; if (src && !(disk->src = VIR_STRDUP(src))) - goto no_memory; + goto error; if (STRPREFIX(disk->dst, "xvd")) disk->bus = VIR_DOMAIN_DISK_BUS_XEN; @@ -513,7 +512,7 @@ xenParseSxprDisks(virDomainDefPtr def, disk->shared = 1; 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")) { @@ -565,7 +564,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))) { @@ -574,24 +573,24 @@ xenParseSxprNets(virDomainDefPtr def, if (tmp && !(net->data.bridge.brname = VIR_STRDUP(tmp))) - goto no_memory; + goto cleanup; if (tmp2 && net->type == VIR_DOMAIN_NET_TYPE_BRIDGE && !(net->script = VIR_STRDUP(tmp2))) - goto no_memory; + goto cleanup; tmp = sexpr_node(node, "device/vif/ip"); if (tmp && !(net->data.bridge.ipaddr = VIR_STRDUP(tmp))) - goto no_memory; + goto cleanup; } else { net->type = VIR_DOMAIN_NET_TYPE_ETHERNET; if (tmp2 && !(net->script = VIR_STRDUP(tmp2))) - goto no_memory; + goto cleanup; tmp = sexpr_node(node, "device/vif/ip"); if (tmp && !(net->data.ethernet.ipaddr = VIR_STRDUP(tmp))) - goto no_memory; + goto cleanup; } tmp = sexpr_node(node, "device/vif/vifname"); @@ -600,10 +599,10 @@ xenParseSxprNets(virDomainDefPtr def, * specified, only generate one if domain is active (id != -1). */ if (tmp) { if (!(net->ifname = VIR_STRDUP(tmp))) - goto no_memory; + 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"); @@ -617,15 +616,15 @@ xenParseSxprNets(virDomainDefPtr def, if (model && !(net->model = VIR_STRDUP(model))) - goto no_memory; + goto cleanup; if (!model && type && STREQ(type, "netfront") && !(net->model = VIR_STRDUP("netfront"))) - goto no_memory; + goto cleanup; if (VIR_REALLOC_N(def->nets, def->nnets + 1) < 0) - goto no_memory; + goto cleanup; def->nets[def->nnets++] = net; vif_index++; @@ -633,9 +632,6 @@ xenParseSxprNets(virDomainDefPtr def, } return 0; - -no_memory: - virReportOOMError(); cleanup: virDomainNetDefFree(net); return -1; @@ -673,13 +669,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; } @@ -703,7 +699,7 @@ xenParseSxprSound(virDomainDefPtr def, } if (VIR_ALLOC(sound) < 0) - goto no_memory; + goto error; if ((sound->model = virDomainSoundModelTypeFromString(model)) < 0) { VIR_FREE(sound); @@ -712,7 +708,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; @@ -722,8 +718,6 @@ xenParseSxprSound(virDomainDefPtr def, return 0; -no_memory: - virReportOOMError(); error: return -1; } @@ -775,7 +769,6 @@ xenParseSxprUSB(virDomainDefPtr def, return 0; no_memory: - virReportOOMError(); return -1; } @@ -813,7 +806,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 @@ -835,14 +828,14 @@ xenParseSxprGraphicsOld(virDomainDefPtr def, if (vncPasswd && !(graphics->data.vnc.auth.passwd = VIR_STRDUP(vncPasswd))) - goto no_memory; + goto error; if (keymap && !(graphics->data.vnc.keymap = VIR_STRDUP(keymap))) - goto no_memory; + goto error; if (VIR_ALLOC_N(def->graphics, 1) < 0) - goto no_memory; + goto error; def->graphics[0] = graphics; def->ngraphics = 1; graphics = NULL; @@ -853,18 +846,18 @@ 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 (display && !(graphics->data.sdl.display = VIR_STRDUP(display))) - goto no_memory; + goto error; if (xauth && !(graphics->data.sdl.xauth = VIR_STRDUP(xauth))) - goto no_memory; + goto error; if (VIR_ALLOC_N(def->graphics, 1) < 0) - goto no_memory; + goto error; def->graphics[0] = graphics; def->ngraphics = 1; graphics = NULL; @@ -872,8 +865,6 @@ xenParseSxprGraphicsOld(virDomainDefPtr def, return 0; -no_memory: - virReportOOMError(); error: virDomainGraphicsDefFree(graphics); return -1; @@ -915,7 +906,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, @@ -928,10 +919,10 @@ xenParseSxprGraphicsNew(virDomainDefPtr def, const char *xauth = sexpr_node(node, "device/vfb/xauthority"); if (display && !(graphics->data.sdl.display = VIR_STRDUP(display))) - goto no_memory; + goto error; if (xauth && !(graphics->data.sdl.xauth = VIR_STRDUP(xauth))) - goto no_memory; + goto error; } else { int port; const char *listenAddr = sexpr_node(node, "device/vfb/vnclisten"); @@ -962,15 +953,15 @@ xenParseSxprGraphicsNew(virDomainDefPtr def, if (vncPasswd && !(graphics->data.vnc.auth.passwd = VIR_STRDUP(vncPasswd))) - goto no_memory; + goto error; if (keymap && !(graphics->data.vnc.keymap = VIR_STRDUP(keymap))) - goto no_memory; + goto error; } if (VIR_ALLOC_N(def->graphics, 1) < 0) - goto no_memory; + goto error; def->graphics[0] = graphics; def->ngraphics = 1; graphics = NULL; @@ -979,9 +970,6 @@ xenParseSxprGraphicsNew(virDomainDefPtr def, } return 0; - -no_memory: - virReportOOMError(); error: virDomainGraphicsDefFree(graphics); return -1; @@ -1097,7 +1085,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; @@ -1105,9 +1093,6 @@ xenParseSxprPCI(virDomainDefPtr def, return 0; -no_memory: - virReportOOMError(); - error: virDomainHostdevDefFree(dev); return -1; @@ -1138,7 +1123,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 */ @@ -1153,7 +1138,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")); @@ -1170,27 +1155,27 @@ 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") && (def->os.bootloader = VIR_STRDUP("")) == NULL) - goto no_memory; + goto error; if (def->os.bootloader && sexpr_node_copy(root, "domain/bootloader_args", &def->os.bootloaderArgs) < 0) - goto no_memory; + goto error; } if (!(def->os.type = VIR_STRDUP(hvm ? "hvm" : "linux"))) - goto no_memory; + goto error; if (def->id != 0) { if (sexpr_lookup(root, "domain/image")) { @@ -1293,10 +1278,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"); @@ -1326,7 +1309,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) @@ -1356,27 +1339,27 @@ xenParseSxpr(const struct sexpr *root, if ((tmp != NULL) && (tmp[0] != 0)) { virDomainDiskDefPtr disk; if (VIR_ALLOC(disk) < 0) - goto no_memory; + goto error; if (!(disk->src = VIR_STRDUP(tmp))) { virDomainDiskDefFree(disk); - goto no_memory; + goto error; } disk->type = VIR_DOMAIN_DISK_TYPE_FILE; disk->device = VIR_DOMAIN_DISK_DEVICE_CDROM; if (!(disk->dst = VIR_STRDUP("hdc"))) { virDomainDiskDefFree(disk); - goto no_memory; + goto error; } if (!(disk->driverName = VIR_STRDUP("file"))) { virDomainDiskDefFree(disk); - goto no_memory; + goto error; } disk->bus = VIR_DOMAIN_DISK_BUS_IDE; disk->readonly = 1; if (VIR_REALLOC_N(def->disks, def->ndisks+1) < 0) { virDomainDiskDefFree(disk); - goto no_memory; + goto error; } def->disks[def->ndisks++] = disk; } @@ -1392,26 +1375,26 @@ xenParseSxpr(const struct sexpr *root, if ((tmp != NULL) && (tmp[0] != 0)) { virDomainDiskDefPtr disk; if (VIR_ALLOC(disk) < 0) - goto no_memory; + goto error; if (!(disk->src = VIR_STRDUP(tmp))) { VIR_FREE(disk); - goto no_memory; + goto error; } disk->type = VIR_DOMAIN_DISK_TYPE_FILE; disk->device = VIR_DOMAIN_DISK_DEVICE_FLOPPY; if (!(disk->dst = VIR_STRDUP(fds[i]))) { virDomainDiskDefFree(disk); - goto no_memory; + goto error; } if (!(disk->driverName = VIR_STRDUP("file"))) { virDomainDiskDefFree(disk); - goto no_memory; + goto error; } disk->bus = VIR_DOMAIN_DISK_BUS_FDC; if (VIR_REALLOC_N(def->disks, def->ndisks+1) < 0) { virDomainDiskDefFree(disk); - goto no_memory; + goto error; } def->disks[def->ndisks++] = disk; } @@ -1445,7 +1428,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; @@ -1467,7 +1450,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; @@ -1483,7 +1466,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; @@ -1492,7 +1475,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; @@ -1513,8 +1496,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 88024c0..91333d5 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -183,10 +183,8 @@ static int xenXMConfigCopyStringInternal(virConfPtr conf, return -1; } - if (!(*value = VIR_STRDUP(val->str))) { - virReportOOMError(); + if (!(*value = VIR_STRDUP(val->str))) return -1; - } return 0; } @@ -270,10 +268,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; @@ -289,7 +285,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, hvm = 1; if (!(def->os.type = VIR_STRDUP(hvm ? "hvm" : "xen"))) - goto no_memory; + goto cleanup; def->os.arch = virCapabilitiesDefaultGuestArch(caps, @@ -308,7 +304,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, virDomainVirtTypeToString(def->virtType)); if (defaultMachine != NULL) { if (!(def->os.machine = VIR_STRDUP(defaultMachine))) - goto no_memory; + goto cleanup; } if (hvm) { @@ -429,10 +425,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; @@ -487,7 +481,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 @@ -505,7 +499,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, @@ -524,7 +518,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, @@ -539,7 +533,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) { @@ -586,7 +580,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, /* No source, or driver name, so fix to phy: */ if (!disk->driverName && !(disk->driverName = VIR_STRDUP("phy"))) - goto no_memory; + goto cleanup; /* phy: type indicates a block device */ @@ -618,7 +612,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; @@ -633,21 +627,21 @@ 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; if (!(disk->driverName = VIR_STRDUP("file"))) - goto no_memory; + goto cleanup; if (!(disk->src = VIR_STRDUP(str))) - goto no_memory; + goto cleanup; if (!(disk->dst = VIR_STRDUP("hdc"))) - goto no_memory; + goto cleanup; disk->bus = VIR_DOMAIN_DISK_BUS_IDE; disk->readonly = 1; if (VIR_REALLOC_N(def->disks, def->ndisks+1) < 0) - goto no_memory; + goto cleanup; def->disks[def->ndisks++] = disk; disk = NULL; } @@ -745,7 +739,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) { @@ -765,35 +759,35 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE) { if (bridge[0] && !(net->data.bridge.brname = VIR_STRDUP(bridge))) - goto no_memory; + goto cleanup; if (ip[0] && !(net->data.bridge.ipaddr = VIR_STRDUP(ip))) - goto no_memory; + goto cleanup; } else { if (ip[0] && !(net->data.ethernet.ipaddr = VIR_STRDUP(ip))) - goto no_memory; + goto cleanup; } if (script && script[0] && !(net->script = VIR_STRDUP(script))) - goto no_memory; + goto cleanup; if (model[0] && !(net->model = VIR_STRDUP(model))) - goto no_memory; + goto cleanup; if (!model[0] && type[0] && STREQ(type, "netfront") && !(net->model = VIR_STRDUP("netfront"))) - goto no_memory; + goto cleanup; if (vifname[0] && !(net->ifname = VIR_STRDUP(vifname))) - goto no_memory; + goto cleanup; if (VIR_REALLOC_N(def->nets, def->nnets+1) < 0) - goto no_memory; + goto cleanup; def->nets[def->nnets++] = net; net = NULL; @@ -885,7 +879,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; @@ -903,14 +897,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; @@ -924,7 +918,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; @@ -952,7 +946,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; @@ -961,14 +955,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; @@ -992,7 +986,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; @@ -1020,20 +1014,20 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, goto cleanup; } else if (STRPREFIX(key, "vncpasswd=")) { if (!(graphics->data.vnc.auth.passwd = VIR_STRDUP(key + 10))) - goto no_memory; + goto cleanup; } else if (STRPREFIX(key, "keymap=")) { if (!(graphics->data.vnc.keymap = VIR_STRDUP(key + 7))) - goto no_memory; + goto cleanup; } else if (STRPREFIX(key, "vncdisplay=")) { graphics->data.vnc.port = strtol(key+11, NULL, 10) + 5900; } } else { if (STRPREFIX(key, "display=")) { if (!(graphics->data.sdl.display = VIR_STRDUP(key + 8))) - goto no_memory; + goto cleanup; } else if (STRPREFIX(key, "xauthority=")) { if (!(graphics->data.sdl.xauth = VIR_STRDUP(key + 11))) - goto no_memory; + goto cleanup; } } @@ -1044,7 +1038,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; @@ -1063,7 +1057,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; @@ -1095,7 +1089,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; @@ -1115,7 +1109,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; @@ -1126,7 +1120,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; @@ -1169,10 +1163,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; @@ -1186,16 +1178,13 @@ 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; if (!(value->str = VIR_STRDUP(str))) { VIR_FREE(value); - virReportOOMError(); return -1; } @@ -1264,10 +1253,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); @@ -1307,10 +1294,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); @@ -1417,10 +1402,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); @@ -1458,10 +1441,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; @@ -1476,14 +1457,11 @@ xenFormatXMPCI(virConfPtr conf, def->hostdevs[i]->source.subsys.u.pci.domain, def->hostdevs[i]->source.subsys.u.pci.bus, def->hostdevs[i]->source.subsys.u.pci.slot, - def->hostdevs[i]->source.subsys.u.pci.function) < 0) { - virReportOOMError(); + def->hostdevs[i]->source.subsys.u.pci.function) < 0) goto error; - } if (VIR_ALLOC(val) < 0) { VIR_FREE(buf); - virReportOOMError(); goto error; } val->type = VIR_CONF_STRING; @@ -1534,27 +1512,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)) { @@ -1563,7 +1541,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; @@ -1571,11 +1549,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]) { @@ -1602,33 +1580,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++) { @@ -1646,7 +1624,7 @@ virConfPtr xenFormatXM(virConnectPtr conn, def->disks[i]->src) { if (xenXMConfigSetString(conf, "cdrom", def->disks[i]->src) < 0) - goto no_memory; + goto cleanup; break; } } @@ -1656,19 +1634,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 */ @@ -1721,7 +1699,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) { @@ -1740,7 +1718,7 @@ virConfPtr xenFormatXM(virConnectPtr conn, } /* !hvm */ } if (xenXMConfigSetInt(conf, "localtime", vmlocaltime) < 0) - goto no_memory; + goto cleanup; if (!(lifecycle = virDomainLifecycleTypeToString(def->onPoweroff))) { @@ -1749,7 +1727,7 @@ virConfPtr xenFormatXM(virConnectPtr conn, goto cleanup; } if (xenXMConfigSetString(conf, "on_poweroff", lifecycle) < 0) - goto no_memory; + goto cleanup; if (!(lifecycle = virDomainLifecycleTypeToString(def->onReboot))) { @@ -1758,7 +1736,7 @@ virConfPtr xenFormatXM(virConnectPtr conn, goto cleanup; } if (xenXMConfigSetString(conf, "on_reboot", lifecycle) < 0) - goto no_memory; + goto cleanup; if (!(lifecycle = virDomainLifecycleCrashTypeToString(def->onCrash))) { @@ -1767,23 +1745,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; } } @@ -1793,43 +1771,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; @@ -1871,13 +1849,13 @@ virConfPtr xenFormatXM(virConnectPtr conn, 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; @@ -1886,13 +1864,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; @@ -1914,12 +1892,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; @@ -1932,7 +1910,7 @@ virConfPtr xenFormatXM(virConnectPtr conn, int ret = virConfSetValue(conf, "vif", netVal); netVal = NULL; if (ret < 0) - goto no_memory; + goto cleanup; } VIR_FREE(netVal); @@ -1951,10 +1929,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) { @@ -1969,14 +1947,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; @@ -2000,13 +1978,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; } @@ -2020,7 +1998,7 @@ virConfPtr xenFormatXM(virConnectPtr conn, VIR_FREE(str); if (ret < 0) - goto no_memory; + goto cleanup; } } diff --git a/tests/commandtest.c b/tests/commandtest.c index 5ad4289..19daca6 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 a25d6ee..e4686e0 100644 --- a/tests/libvirtdconftest.c +++ b/tests/libvirtdconftest.c @@ -77,10 +77,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 437e66b..9bcbece 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; @@ -423,7 +421,6 @@ qemuMonitorTestAddItem(qemuMonitorTestPtr test, return 0; no_memory: - virReportOOMError(); qemuMonitorTestItemFree(item); return -1; } -- 1.8.1.5 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list