[libvirt] [PATCH v2 00/37] Change OOM reporting

Previously, the first version dropped virReportOOMError from almost everywhere. This series don't set such high goal yet. It just prepares ground for doing so. The worst case scenario is the OOM error is reported twice. Once in VIR_ALLOC, VIR_STRDUP, virAsprintf (or similar), then in virReportOOMError itself. However, once this is pushed, it's easy to get rid of the latter one. Patches available at: git://gitorious.org/~zippy2/libvirt/michal-staging.git branch oom3 Remember, this will not be pushed until we are after the freeze. But the freeze creates a nice steady HEAD which is needed in such a giant change like this one. Michal Privoznik (37): virutil: Move string related functions to virstring.c virstring: Introduce VIR_STRUP and VIR_STRNDUP Adapt to VIR_STRDUP in daemon/* Adapt to VIR_STRDUP in src/conf/* Adapt to VIR_STRDUP in src/cpu/* Adapt to VIR_STRDUP in src/esx/* Adapt to VIR_STRDUP in src/hyperv/* Adapt to VIR_STRDUP in src/libxl/* Adapt to VIR_STRDUP in src/locking/* Adapt to VIR_STRDUP in src/lxc/* Adapt to VIR_STRDUP in src/network/* Adapt to VIR_STRDUP in src/node_device/* Adapt to VIR_STRDUP in src/interface/ Adapt to VIR_STRDUP in src/nwfilter/* Adapt to VIR_STRDUP in src/openvz/* Adapt to VIR_STRDUP in src/parallels/* Adapt to VIR_STRDUP in src/phyp/* Adapt to VIR_STRDUP in src/qemu/* Adapt to VIR_STRDUP in src/remote/* Adapt to VIR_STRDUP in src/rpc/* Adapt to VIR_STRDUP in src/secret/* Adapt to VIR_STRDUP in src/security/* Adapt to VIR_STRDUP in src/storage/* Adapt to VIR_STRDUP in src/test/* Adapt to VIR_STRDUP in src/uml/* Adapt to VIR_STRDUP in src/util/* Adapt to VIR_STRDUP in src/vbox/* Adapt to VIR_STRDUP in src/vmware/* Adapt to VIR_STRDUP in src/vmx/* Adapt to VIR_STRDUP in src/xen/* Adapt to VIR_STRDUP in src/xenapi/* Adapt to VIR_STRDUP in src/xenxs/* Adapt to VIR_STRDUP in tests/* Adapt to VIR_STRDUP in src/* Introduce syntax-check rule to prefer VIR_STRDUP over strdup virstring: Introduce virAsprintfQuiet and virVasprintfQuiet viralloc.c: Do report OOM error in VIR_ALLOC and friends HACKING | 19 ++ cfg.mk | 12 +- daemon/libvirtd-config.c | 39 +-- daemon/libvirtd.c | 19 +- daemon/remote.c | 97 +++---- docs/hacking.html.in | 26 ++ include/libvirt/libvirt.h.in | 10 +- po/POTFILES.in | 1 + python/libvirt-override.c | 103 +++---- src/conf/capabilities.c | 27 +- src/conf/cpu_conf.c | 14 +- src/conf/device_conf.c | 2 +- src/conf/domain_audit.c | 1 + src/conf/domain_conf.c | 66 ++--- src/conf/domain_conf.h | 1 - src/conf/domain_event.c | 31 +- src/conf/interface_conf.c | 1 - src/conf/netdev_bandwidth_conf.c | 2 +- src/conf/netdev_vport_profile_conf.c | 1 + src/conf/network_conf.c | 2 +- src/conf/node_device_conf.c | 29 +- src/conf/nwfilter_conf.c | 20 +- src/conf/nwfilter_conf.h | 1 - src/conf/nwfilter_params.c | 23 +- src/conf/secret_conf.c | 1 - src/conf/snapshot_conf.c | 8 +- src/conf/storage_conf.c | 11 +- src/conf/storage_conf.h | 1 - src/conf/storage_encryption_conf.c | 1 - src/conf/virchrdev.c | 7 +- src/cpu/cpu_generic.c | 6 +- src/cpu/cpu_map.c | 3 +- src/cpu/cpu_powerpc.c | 11 +- src/cpu/cpu_x86.c | 9 +- src/datatypes.c | 26 +- src/driver.c | 2 +- src/esx/esx_device_monitor.c | 1 - src/esx/esx_driver.c | 35 +-- src/esx/esx_interface_driver.c | 6 +- src/esx/esx_network_driver.c | 21 +- src/esx/esx_nwfilter_driver.c | 1 - src/esx/esx_secret_driver.c | 1 - src/esx/esx_storage_backend_iscsi.c | 15 +- src/esx/esx_storage_backend_vmfs.c | 10 +- src/esx/esx_util.c | 39 +-- src/esx/esx_vi.c | 54 +--- src/esx/esx_vi_types.c | 24 +- src/fdstream.c | 1 + src/hyperv/hyperv_device_monitor.c | 1 - src/hyperv/hyperv_driver.c | 37 +-- src/hyperv/hyperv_interface_driver.c | 1 - src/hyperv/hyperv_network_driver.c | 1 - src/hyperv/hyperv_nwfilter_driver.c | 1 - src/hyperv/hyperv_secret_driver.c | 1 - src/hyperv/hyperv_storage_driver.c | 1 - src/hyperv/hyperv_util.c | 16 +- src/hyperv/hyperv_wmi.c | 2 +- src/interface/interface_backend_udev.c | 25 +- src/libvirt.c | 10 +- src/libvirt_private.syms | 36 +-- src/libxl/libxl_conf.c | 59 ++-- src/libxl/libxl_driver.c | 14 +- src/locking/lock_daemon.c | 13 +- src/locking/lock_daemon_config.c | 10 +- src/locking/lock_daemon_dispatch.c | 4 +- src/locking/lock_driver_lockd.c | 24 +- src/locking/lock_driver_sanlock.c | 9 +- src/locking/lock_manager.c | 4 +- src/lxc/lxc_cgroup.c | 3 +- src/lxc/lxc_conf.c | 18 +- src/lxc/lxc_container.c | 10 +- src/lxc/lxc_controller.c | 8 +- src/lxc/lxc_driver.c | 9 +- src/lxc/lxc_fuse.c | 1 + src/lxc/lxc_fuse.h | 1 - src/lxc/lxc_monitor.c | 1 + src/lxc/lxc_process.c | 5 +- src/network/bridge_driver.c | 30 +- src/node_device/node_device_driver.c | 29 +- src/node_device/node_device_hal.c | 13 +- src/node_device/node_device_linux_sysfs.c | 1 + src/node_device/node_device_udev.c | 104 +++---- src/nodeinfo.c | 6 +- src/nwfilter/nwfilter_dhcpsnoop.c | 16 +- src/nwfilter/nwfilter_driver.c | 5 +- src/nwfilter/nwfilter_ebiptables_driver.c | 12 +- src/nwfilter/nwfilter_gentech_driver.c | 4 +- src/nwfilter/nwfilter_learnipaddr.c | 4 +- src/openvz/openvz_conf.c | 33 ++- src/openvz/openvz_driver.c | 32 +-- src/parallels/parallels_driver.c | 36 +-- src/parallels/parallels_network.c | 14 +- src/parallels/parallels_storage.c | 40 ++- src/parallels/parallels_utils.c | 2 +- src/phyp/phyp_driver.c | 37 +-- src/qemu/qemu_agent.c | 1 + src/qemu/qemu_bridge_filter.c | 1 - src/qemu/qemu_capabilities.c | 38 +-- src/qemu/qemu_cgroup.c | 4 +- src/qemu/qemu_command.c | 282 ++++++++----------- src/qemu/qemu_conf.c | 33 +-- src/qemu/qemu_domain.c | 17 +- src/qemu/qemu_driver.c | 93 +++--- src/qemu/qemu_hotplug.c | 9 +- src/qemu/qemu_migration.c | 17 +- src/qemu/qemu_monitor.c | 1 + src/qemu/qemu_monitor_json.c | 40 ++- src/qemu/qemu_monitor_text.c | 10 +- src/qemu/qemu_process.c | 58 ++-- src/remote/remote_driver.c | 83 +++--- src/rpc/gendispatch.pl | 13 +- src/rpc/virkeepalive.c | 1 - src/rpc/virnetclient.c | 8 +- src/rpc/virnetmessage.c | 11 +- src/rpc/virnetsaslcontext.c | 3 +- src/rpc/virnetserver.c | 4 +- src/rpc/virnetserverclient.c | 8 +- src/rpc/virnetservermdns.c | 4 +- src/rpc/virnetsocket.c | 8 +- src/rpc/virnetsshsession.c | 23 +- src/rpc/virnettlscontext.c | 14 +- src/secret/secret_driver.c | 5 +- src/security/security_apparmor.c | 13 +- src/security/security_dac.c | 8 +- src/security/security_nop.c | 4 +- src/security/security_selinux.c | 51 ++-- src/security/virt-aa-helper.c | 6 +- src/storage/parthelper.c | 7 +- src/storage/storage_backend.c | 18 +- src/storage/storage_backend_disk.c | 16 +- src/storage/storage_backend_fs.c | 18 +- src/storage/storage_backend_iscsi.c | 16 +- src/storage/storage_backend_logical.c | 25 +- src/storage/storage_backend_mpath.c | 4 +- src/storage/storage_backend_rbd.c | 4 +- src/storage/storage_backend_scsi.c | 17 +- src/storage/storage_backend_sheepdog.c | 1 - src/storage/storage_driver.c | 13 +- src/test/test_driver.c | 84 +++--- src/uml/uml_conf.c | 7 +- src/uml/uml_driver.c | 8 +- src/util/iohelper.c | 1 + src/util/viralloc.c | 95 ++++++- src/util/viralloc.h | 54 +++- src/util/viraudit.c | 6 +- src/util/virauth.c | 9 +- src/util/virauthconfig.c | 7 +- src/util/virbitmap.c | 10 +- src/util/virbuffer.c | 8 +- src/util/vircgroup.c | 31 +- src/util/vircommand.c | 34 ++- src/util/vircommand.h | 1 - src/util/virconf.c | 21 +- src/util/virdnsmasq.c | 5 +- src/util/virebtables.c | 36 +-- src/util/virerror.c | 25 +- src/util/virfile.c | 1 + src/util/virhash.c | 5 +- src/util/virhook.h | 1 - src/util/viridentity.c | 9 +- src/util/virinitctl.c | 3 +- src/util/viriptables.c | 6 +- src/util/virjson.c | 18 +- src/util/virkeyfile.c | 7 +- src/util/virlockspace.c | 14 +- src/util/virlog.c | 21 +- src/util/virnetdev.c | 2 + src/util/virnetdevbandwidth.c | 1 + src/util/virnetdevbridge.c | 1 + src/util/virnetdevmacvlan.c | 10 +- src/util/virnetdevopenvswitch.c | 1 + src/util/virnetdevopenvswitch.h | 1 - src/util/virnetdevtap.c | 7 +- src/util/virnetdevveth.c | 2 + src/util/virnetdevvportprofile.c | 4 +- src/util/virobject.c | 5 +- src/util/virpci.c | 7 +- src/util/virpidfile.c | 1 + src/util/virprocess.c | 1 + src/util/virrandom.c | 1 + src/util/virsexpr.c | 27 +- src/util/virsocketaddr.c | 6 +- src/util/virstatslinux.c | 1 - src/util/virstoragefile.c | 13 +- src/util/virstring.c | 451 +++++++++++++++++++++++++++++- src/util/virstring.h | 74 +++++ src/util/virsysinfo.c | 170 +++++------ src/util/virthreadpthread.c | 2 +- src/util/virtime.c | 1 - src/util/virtpm.c | 2 +- src/util/virtypedparam.c | 9 +- src/util/viruri.c | 20 +- src/util/virusb.c | 1 + src/util/virutil.c | 393 ++------------------------ src/util/virutil.h | 49 ---- src/util/virxml.c | 7 +- src/vbox/vbox_MSCOMGlue.c | 1 - src/vbox/vbox_XPCOMCGlue.c | 5 +- src/vbox/vbox_driver.c | 1 - src/vbox/vbox_tmpl.c | 191 +++++++------ src/vmware/vmware_conf.c | 15 +- src/vmware/vmware_driver.c | 13 +- src/vmx/vmx.c | 26 +- src/xen/block_stats.c | 2 +- src/xen/xen_driver.c | 4 +- src/xen/xen_hypervisor.c | 17 +- src/xen/xen_inotify.c | 11 +- src/xen/xend_internal.c | 55 ++-- src/xen/xm_internal.c | 8 +- src/xen/xs_internal.c | 22 +- src/xenapi/xenapi_driver.c | 34 ++- src/xenapi/xenapi_utils.c | 22 +- src/xenxs/xen_sxpr.c | 108 +++---- src/xenxs/xen_xm.c | 44 +-- tests/commandhelper.c | 14 +- tests/commandtest.c | 4 +- tests/cputest.c | 1 + tests/domainsnapshotxml2xmltest.c | 1 + tests/esxutilstest.c | 1 - tests/interfacexml2xmltest.c | 2 +- tests/libvirtdconftest.c | 1 + tests/lxcxml2xmltest.c | 1 + tests/networkxml2conftest.c | 3 + tests/networkxml2xmltest.c | 1 + tests/nodedevxml2xmltest.c | 1 + tests/nodeinfotest.c | 2 +- tests/nwfilterxml2xmltest.c | 1 + tests/openvzutilstest.c | 8 +- tests/qemuargv2xmltest.c | 2 +- tests/qemuhelptest.c | 1 + tests/qemumonitortest.c | 1 - tests/qemumonitortestutils.c | 10 +- tests/qemuxml2argvtest.c | 28 +- tests/qemuxml2xmltest.c | 1 + tests/qemuxmlnstest.c | 6 +- tests/securityselinuxhelper.c | 7 +- tests/securityselinuxlabeltest.c | 5 +- tests/securityselinuxtest.c | 9 +- tests/sexpr2xmltest.c | 1 + tests/storagebackendsheepdogtest.c | 6 +- tests/storagepoolxml2xmltest.c | 1 + tests/storagevolxml2argvtest.c | 1 + tests/storagevolxml2xmltest.c | 1 + tests/sysinfotest.c | 2 +- tests/test_conf.c | 2 +- tests/testutils.c | 5 +- tests/testutilsqemu.c | 5 +- tests/virauthconfigtest.c | 1 - tests/virbuftest.c | 2 +- tests/vircgrouptest.c | 4 +- tests/virdrivermoduletest.c | 1 - tests/virhashtest.c | 3 +- tests/viridentitytest.c | 1 - tests/virkeyfiletest.c | 1 - tests/virnetmessagetest.c | 22 +- tests/virnetsockettest.c | 1 + tests/virportallocatortest.c | 2 +- tests/virshtest.c | 2 +- tests/virstoragetest.c | 1 + tests/virstringtest.c | 1 - tests/virtimetest.c | 1 - tests/viruritest.c | 1 - tests/vmx2xmltest.c | 11 +- tests/xencapstest.c | 1 + tests/xmconfigtest.c | 3 + tests/xml2sexprtest.c | 1 + tests/xml2vmxtest.c | 11 +- tools/console.c | 1 - tools/virsh-domain-monitor.c | 1 + tools/virsh-domain.c | 1 - tools/virsh-host.c | 2 +- tools/virsh-interface.c | 1 + tools/virsh-network.c | 1 - tools/virsh-nodedev.c | 1 - tools/virsh-pool.c | 2 +- tools/virsh-snapshot.c | 1 - tools/virsh-volume.c | 1 + tools/virsh.c | 8 +- tools/virt-host-validate-common.c | 1 + 279 files changed, 2544 insertions(+), 2653 deletions(-) -- 1.8.1.5

The source code base needs to be adapted as well. Some files include virutil.h just for the string related functions (here, the include is substituted to match the new file), some include virutil.h without any need (here, the include is removed), and some require both. --- cfg.mk | 4 +- daemon/libvirtd-config.c | 2 + daemon/libvirtd.c | 2 +- daemon/remote.c | 3 +- python/libvirt-override.c | 1 + src/conf/capabilities.c | 1 - src/conf/cpu_conf.c | 2 +- src/conf/device_conf.c | 2 +- src/conf/domain_audit.c | 1 + src/conf/domain_conf.c | 2 +- src/conf/domain_conf.h | 1 - src/conf/interface_conf.c | 1 - src/conf/netdev_bandwidth_conf.c | 2 +- src/conf/netdev_vport_profile_conf.c | 1 + src/conf/network_conf.c | 2 +- src/conf/node_device_conf.c | 1 - src/conf/nwfilter_conf.c | 2 +- src/conf/nwfilter_conf.h | 1 - src/conf/nwfilter_params.c | 1 + src/conf/secret_conf.c | 1 - src/conf/snapshot_conf.c | 2 +- src/conf/storage_conf.c | 2 +- src/conf/storage_conf.h | 1 - src/conf/storage_encryption_conf.c | 1 - src/conf/virchrdev.c | 1 + src/cpu/cpu_powerpc.c | 1 - src/cpu/cpu_x86.c | 3 +- src/datatypes.c | 1 - src/driver.c | 2 +- src/esx/esx_device_monitor.c | 1 - src/esx/esx_driver.c | 2 +- src/esx/esx_interface_driver.c | 1 - src/esx/esx_network_driver.c | 1 - src/esx/esx_nwfilter_driver.c | 1 - src/esx/esx_secret_driver.c | 1 - src/esx/esx_storage_backend_iscsi.c | 1 - src/esx/esx_storage_backend_vmfs.c | 2 +- src/esx/esx_util.c | 2 +- src/esx/esx_vi.c | 2 +- src/esx/esx_vi_types.c | 2 +- src/fdstream.c | 1 + src/hyperv/hyperv_device_monitor.c | 1 - src/hyperv/hyperv_driver.c | 2 +- src/hyperv/hyperv_interface_driver.c | 1 - src/hyperv/hyperv_network_driver.c | 1 - src/hyperv/hyperv_nwfilter_driver.c | 1 - src/hyperv/hyperv_secret_driver.c | 1 - src/hyperv/hyperv_storage_driver.c | 1 - src/hyperv/hyperv_util.c | 1 - src/hyperv/hyperv_wmi.c | 2 +- src/interface/interface_backend_udev.c | 1 + src/libvirt.c | 1 + src/libvirt_private.syms | 32 +-- src/libxl/libxl_driver.c | 1 + src/locking/lock_daemon.c | 1 + src/locking/lock_daemon_config.c | 2 + src/locking/lock_daemon_dispatch.c | 1 - src/locking/lock_driver_lockd.c | 2 +- src/locking/lock_driver_sanlock.c | 1 - src/locking/lock_manager.c | 2 +- src/lxc/lxc_cgroup.c | 1 + src/lxc/lxc_container.c | 2 +- src/lxc/lxc_controller.c | 2 +- src/lxc/lxc_driver.c | 2 +- src/lxc/lxc_fuse.c | 1 + src/lxc/lxc_fuse.h | 1 - src/lxc/lxc_monitor.c | 1 + src/lxc/lxc_process.c | 1 + src/network/bridge_driver.c | 2 +- src/node_device/node_device_driver.c | 1 - src/node_device/node_device_linux_sysfs.c | 1 + src/node_device/node_device_udev.c | 2 +- src/nodeinfo.c | 3 +- src/nwfilter/nwfilter_dhcpsnoop.c | 1 + src/nwfilter/nwfilter_driver.c | 1 + src/nwfilter/nwfilter_ebiptables_driver.c | 2 +- src/nwfilter/nwfilter_learnipaddr.c | 1 + src/openvz/openvz_conf.c | 2 +- src/openvz/openvz_driver.c | 2 +- src/parallels/parallels_driver.c | 2 +- src/parallels/parallels_network.c | 2 +- src/parallels/parallels_storage.c | 2 +- src/parallels/parallels_utils.c | 2 +- src/phyp/phyp_driver.c | 3 +- src/qemu/qemu_agent.c | 1 + src/qemu/qemu_bridge_filter.c | 1 - src/qemu/qemu_capabilities.c | 1 - src/qemu/qemu_cgroup.c | 1 - src/qemu/qemu_command.c | 1 - src/qemu/qemu_conf.c | 1 - src/qemu/qemu_domain.c | 1 + src/qemu/qemu_driver.c | 2 +- src/qemu/qemu_hotplug.c | 1 + src/qemu/qemu_migration.c | 3 +- src/qemu/qemu_monitor.c | 1 + src/qemu/qemu_monitor_text.c | 1 + src/qemu/qemu_process.c | 2 +- src/remote/remote_driver.c | 2 +- src/rpc/virkeepalive.c | 1 - src/rpc/virnetserverclient.c | 2 + src/rpc/virnetsocket.c | 2 +- src/rpc/virnetsshsession.c | 1 + src/rpc/virnettlscontext.c | 1 + src/secret/secret_driver.c | 2 +- src/security/security_apparmor.c | 2 +- src/security/security_dac.c | 2 +- src/security/security_selinux.c | 2 +- src/security/virt-aa-helper.c | 2 +- src/storage/storage_backend.c | 2 +- src/storage/storage_backend_disk.c | 2 +- src/storage/storage_backend_fs.c | 1 + src/storage/storage_backend_iscsi.c | 2 +- src/storage/storage_backend_logical.c | 1 + src/storage/storage_backend_mpath.c | 1 + src/storage/storage_backend_rbd.c | 1 - src/storage/storage_backend_scsi.c | 1 + src/storage/storage_backend_sheepdog.c | 1 - src/storage/storage_driver.c | 2 +- src/test/test_driver.c | 2 +- src/uml/uml_conf.c | 3 +- src/uml/uml_driver.c | 2 +- src/util/iohelper.c | 1 + src/util/viraudit.c | 2 +- src/util/virauth.c | 1 + src/util/virauthconfig.c | 3 +- src/util/virbitmap.c | 3 +- src/util/vircommand.c | 1 + src/util/vircommand.h | 1 - src/util/virdnsmasq.c | 1 + src/util/virebtables.c | 2 + src/util/virerror.c | 1 + src/util/virfile.c | 1 + src/util/virhook.h | 1 - src/util/virinitctl.c | 1 + src/util/viriptables.c | 2 + src/util/virjson.c | 1 + src/util/virlockspace.c | 1 + src/util/virlog.c | 1 + src/util/virnetdev.c | 2 + src/util/virnetdevbandwidth.c | 1 + src/util/virnetdevbridge.c | 1 + src/util/virnetdevmacvlan.c | 1 - src/util/virnetdevopenvswitch.c | 1 + src/util/virnetdevopenvswitch.h | 1 - src/util/virnetdevtap.c | 2 +- src/util/virnetdevveth.c | 2 + src/util/virnetdevvportprofile.c | 1 + src/util/virpci.c | 2 + src/util/virpidfile.c | 1 + src/util/virprocess.c | 1 + src/util/virrandom.c | 1 + src/util/virsexpr.c | 2 +- src/util/virsocketaddr.c | 2 +- src/util/virstatslinux.c | 1 - src/util/virstoragefile.c | 2 + src/util/virstring.c | 335 ++++++++++++++++++++++++++++++ src/util/virstring.h | 50 +++++ src/util/virsysinfo.c | 2 +- src/util/virtime.c | 1 - src/util/virtpm.c | 2 +- src/util/virtypedparam.c | 1 + src/util/viruri.c | 2 +- src/util/virusb.c | 1 + src/util/virutil.c | 334 +---------------------------- src/util/virutil.h | 49 ----- src/util/virxml.c | 1 + src/vbox/vbox_MSCOMGlue.c | 1 - src/vbox/vbox_XPCOMCGlue.c | 1 + src/vbox/vbox_driver.c | 1 - src/vbox/vbox_tmpl.c | 1 + src/vmware/vmware_conf.c | 2 +- src/vmware/vmware_driver.c | 1 - src/vmx/vmx.c | 1 + src/xen/block_stats.c | 2 +- src/xen/xen_driver.c | 2 +- src/xen/xen_hypervisor.c | 2 +- src/xen/xend_internal.c | 2 +- src/xen/xm_internal.c | 2 +- src/xenapi/xenapi_driver.c | 2 +- src/xenapi/xenapi_utils.c | 2 +- src/xenxs/xen_sxpr.c | 1 + src/xenxs/xen_xm.c | 1 + tests/commandtest.c | 2 +- tests/cputest.c | 1 + tests/domainsnapshotxml2xmltest.c | 1 + tests/esxutilstest.c | 1 - tests/interfacexml2xmltest.c | 2 +- tests/libvirtdconftest.c | 1 + tests/lxcxml2xmltest.c | 1 + tests/networkxml2conftest.c | 1 + tests/networkxml2xmltest.c | 1 + tests/nodedevxml2xmltest.c | 1 + tests/nodeinfotest.c | 2 +- tests/nwfilterxml2xmltest.c | 1 + tests/openvzutilstest.c | 2 +- tests/qemuargv2xmltest.c | 2 +- tests/qemuhelptest.c | 1 + tests/qemumonitortest.c | 1 - tests/qemumonitortestutils.c | 2 +- tests/qemuxml2argvtest.c | 1 + tests/qemuxml2xmltest.c | 1 + tests/qemuxmlnstest.c | 2 +- tests/securityselinuxlabeltest.c | 3 +- tests/securityselinuxtest.c | 3 +- tests/sexpr2xmltest.c | 1 + tests/storagepoolxml2xmltest.c | 1 + tests/storagevolxml2argvtest.c | 1 + tests/storagevolxml2xmltest.c | 1 + tests/sysinfotest.c | 2 +- tests/testutils.c | 1 + tests/virauthconfigtest.c | 1 - tests/virbuftest.c | 2 +- tests/vircgrouptest.c | 2 +- tests/virdrivermoduletest.c | 1 - tests/virhashtest.c | 3 +- tests/viridentitytest.c | 1 - tests/virkeyfiletest.c | 1 - tests/virnetmessagetest.c | 1 - tests/virnetsockettest.c | 1 + tests/virportallocatortest.c | 2 +- tests/virshtest.c | 2 +- tests/virstoragetest.c | 1 + tests/virstringtest.c | 1 - tests/virtimetest.c | 1 - tests/viruritest.c | 1 - tests/vmx2xmltest.c | 1 + tests/xencapstest.c | 1 + tests/xmconfigtest.c | 1 + tests/xml2sexprtest.c | 1 + tests/xml2vmxtest.c | 1 + tools/console.c | 1 - tools/virsh-domain-monitor.c | 1 + tools/virsh-domain.c | 1 - tools/virsh-host.c | 2 +- tools/virsh-interface.c | 1 + tools/virsh-network.c | 1 - tools/virsh-nodedev.c | 1 - tools/virsh-pool.c | 2 +- tools/virsh-snapshot.c | 1 - tools/virsh-volume.c | 1 + tools/virsh.c | 2 +- tools/virt-host-validate-common.c | 1 + 242 files changed, 590 insertions(+), 557 deletions(-) diff --git a/cfg.mk b/cfg.mk index f0f78f5..d499ded 100644 --- a/cfg.mk +++ b/cfg.mk @@ -858,7 +858,7 @@ exclude_file_name_regexp--sc_prohibit_always_true_header_tests = \ ^python/(libvirt-(lxc-|qemu-)?override|typewrappers)\.c$$ exclude_file_name_regexp--sc_prohibit_asprintf = \ - ^(bootstrap.conf$$|src/util/virutil\.c$$|examples/domain-events/events-c/event-test\.c$$|tests/vircgroupmock\.c$$) + ^(bootstrap.conf$$|src/util/virstring\.c$$|examples/domain-events/events-c/event-test\.c$$|tests/vircgroupmock\.c$$) exclude_file_name_regexp--sc_prohibit_close = \ (\.p[yl]$$|^docs/|^(src/util/virfile\.c|src/libvirt\.c|tests/vircgroupmock\.c)$$) @@ -892,7 +892,7 @@ exclude_file_name_regexp--sc_prohibit_setuid = ^src/util/virutil\.c$$ exclude_file_name_regexp--sc_prohibit_sprintf = \ ^(docs/hacking\.html\.in)|(examples/systemtap/.*stp)|(src/dtrace2systemtap\.pl)|(src/rpc/gensystemtap\.pl)$$ -exclude_file_name_regexp--sc_prohibit_strncpy = ^src/util/virutil\.c$$ +exclude_file_name_regexp--sc_prohibit_strncpy = ^src/util/virstring\.c$$ exclude_file_name_regexp--sc_prohibit_strtol = \ ^src/(util/virsexpr|(vbox|xen|xenxs)/.*)\.c$$ diff --git a/daemon/libvirtd-config.c b/daemon/libvirtd-config.c index 5e3ae21..efb564e 100644 --- a/daemon/libvirtd-config.c +++ b/daemon/libvirtd-config.c @@ -32,6 +32,8 @@ #include "configmake.h" #include "remote/remote_protocol.h" #include "remote/remote_driver.h" +#include "virstring.h" +#include "virutil.h" #define VIR_FROM_THIS VIR_FROM_CONF diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c index 38b7346..9f81a0f 100644 --- a/daemon/libvirtd.c +++ b/daemon/libvirtd.c @@ -43,7 +43,6 @@ #include "libvirtd.h" #include "libvirtd-config.h" -#include "virutil.h" #include "viruuid.h" #include "remote_driver.h" #include "viralloc.h" @@ -54,6 +53,7 @@ #include "virhook.h" #include "viraudit.h" #include "locking/lock_manager.h" +#include "virstring.h" #ifdef WITH_DRIVER_MODULES # include "driver.h" diff --git a/daemon/remote.c b/daemon/remote.c index e5e3f2c..8c79680 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -35,7 +35,6 @@ #include "datatypes.h" #include "viralloc.h" #include "virlog.h" -#include "virutil.h" #include "stream.h" #include "viruuid.h" #include "vircommand.h" @@ -49,7 +48,7 @@ #include "remote_protocol.h" #include "qemu_protocol.h" #include "lxc_protocol.h" - +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_RPC diff --git a/python/libvirt-override.c b/python/libvirt-override.c index 244b7ec..856789a 100644 --- a/python/libvirt-override.c +++ b/python/libvirt-override.c @@ -28,6 +28,7 @@ #include "virtypedparam.h" #include "ignore-value.h" #include "virutil.h" +#include "virstring.h" #ifndef __CYGWIN__ extern void initlibvirtmod(void); diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index c7ec92f..5340b63 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -28,7 +28,6 @@ #include "capabilities.h" #include "virbuffer.h" #include "viralloc.h" -#include "virutil.h" #include "viruuid.h" #include "cpu_conf.h" #include "virerror.h" diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c index bdc5f1d..6aaee75 100644 --- a/src/conf/cpu_conf.c +++ b/src/conf/cpu_conf.c @@ -25,10 +25,10 @@ #include "virerror.h" #include "viralloc.h" -#include "virutil.h" #include "virbuffer.h" #include "cpu_conf.h" #include "domain_conf.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_CPU diff --git a/src/conf/device_conf.c b/src/conf/device_conf.c index 099b1cb..f49dc21 100644 --- a/src/conf/device_conf.c +++ b/src/conf/device_conf.c @@ -26,9 +26,9 @@ #include "viralloc.h" #include "virxml.h" #include "viruuid.h" -#include "virutil.h" #include "virbuffer.h" #include "device_conf.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_DEVICE diff --git a/src/conf/domain_audit.c b/src/conf/domain_audit.c index d81744c..40910d6 100644 --- a/src/conf/domain_audit.c +++ b/src/conf/domain_audit.c @@ -31,6 +31,7 @@ #include "viruuid.h" #include "virlog.h" #include "viralloc.h" +#include "virstring.h" /* Return nn:mm in hex for block and character devices, and NULL * for other file types, stat failure, or allocation failure. */ diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index a8b5dfd..51cb1fa 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -38,7 +38,6 @@ #include "verify.h" #include "virxml.h" #include "viruuid.h" -#include "virutil.h" #include "virbuffer.h" #include "virlog.h" #include "nwfilter_conf.h" @@ -52,6 +51,7 @@ #include "netdev_vlan_conf.h" #include "device_conf.h" #include "virtpm.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_DOMAIN diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 3a0f23a..21f7ce2 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -32,7 +32,6 @@ # include "capabilities.h" # include "storage_encryption_conf.h" # include "cpu_conf.h" -# include "virutil.h" # include "virthread.h" # include "virhash.h" # include "virsocketaddr.h" diff --git a/src/conf/interface_conf.c b/src/conf/interface_conf.c index 7ca9c86..fd3c292 100644 --- a/src/conf/interface_conf.c +++ b/src/conf/interface_conf.c @@ -30,7 +30,6 @@ #include "viralloc.h" #include "virxml.h" #include "viruuid.h" -#include "virutil.h" #include "virbuffer.h" #define VIR_FROM_THIS VIR_FROM_INTERFACE diff --git a/src/conf/netdev_bandwidth_conf.c b/src/conf/netdev_bandwidth_conf.c index b830cd0..87249cb 100644 --- a/src/conf/netdev_bandwidth_conf.c +++ b/src/conf/netdev_bandwidth_conf.c @@ -24,9 +24,9 @@ #include "netdev_bandwidth_conf.h" #include "virerror.h" -#include "virutil.h" #include "viralloc.h" #include "domain_conf.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_NONE diff --git a/src/conf/netdev_vport_profile_conf.c b/src/conf/netdev_vport_profile_conf.c index 47f51f9..c275339 100644 --- a/src/conf/netdev_vport_profile_conf.c +++ b/src/conf/netdev_vport_profile_conf.c @@ -25,6 +25,7 @@ #include "netdev_vport_profile_conf.h" #include "virerror.h" #include "viralloc.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_NONE diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index d910a27..8abfa53 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -40,10 +40,10 @@ #include "viralloc.h" #include "virxml.h" #include "viruuid.h" -#include "virutil.h" #include "virbuffer.h" #include "c-ctype.h" #include "virfile.h" +#include "virstring.h" #define MAX_BRIDGE_ID 256 #define VIR_FROM_THIS VIR_FROM_NETWORK diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 8fe4e03..f9303c1 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -32,7 +32,6 @@ #include "node_device_conf.h" #include "virxml.h" -#include "virutil.h" #include "virbuffer.h" #include "viruuid.h" #include "virrandom.h" diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c index b61010d..08222de 100644 --- a/src/conf/nwfilter_conf.c +++ b/src/conf/nwfilter_conf.c @@ -47,7 +47,7 @@ #include "domain_conf.h" #include "c-ctype.h" #include "virfile.h" - +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_NWFILTER diff --git a/src/conf/nwfilter_conf.h b/src/conf/nwfilter_conf.h index 48998ec..5d04cff 100644 --- a/src/conf/nwfilter_conf.h +++ b/src/conf/nwfilter_conf.h @@ -28,7 +28,6 @@ # include "internal.h" -# include "virutil.h" # include "virhash.h" # include "virxml.h" # include "virbuffer.h" diff --git a/src/conf/nwfilter_params.c b/src/conf/nwfilter_params.c index 7aebc8d..2509c0d 100644 --- a/src/conf/nwfilter_params.c +++ b/src/conf/nwfilter_params.c @@ -31,6 +31,7 @@ #include "nwfilter_params.h" #include "domain_conf.h" #include "virlog.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_NWFILTER diff --git a/src/conf/secret_conf.c b/src/conf/secret_conf.c index a81a91b..5bcfe12 100644 --- a/src/conf/secret_conf.c +++ b/src/conf/secret_conf.c @@ -29,7 +29,6 @@ #include "viralloc.h" #include "secret_conf.h" #include "virerror.h" -#include "virutil.h" #include "virxml.h" #include "viruuid.h" diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index bd5684d..5b54a28 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -42,11 +42,11 @@ #include "secret_conf.h" #include "snapshot_conf.h" #include "virstoragefile.h" -#include "virutil.h" #include "viruuid.h" #include "virfile.h" #include "virerror.h" #include "virxml.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_DOMAIN_SNAPSHOT diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index b58385d..9f2012e 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -41,9 +41,9 @@ #include "virxml.h" #include "viruuid.h" #include "virbuffer.h" -#include "virutil.h" #include "viralloc.h" #include "virfile.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_STORAGE diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h index 60b8034..567a4ac 100644 --- a/src/conf/storage_conf.h +++ b/src/conf/storage_conf.h @@ -25,7 +25,6 @@ # define __VIR_STORAGE_CONF_H__ # include "internal.h" -# include "virutil.h" # include "storage_encryption_conf.h" # include "virthread.h" diff --git a/src/conf/storage_encryption_conf.c b/src/conf/storage_encryption_conf.c index 88dff1b..c710bbd 100644 --- a/src/conf/storage_encryption_conf.c +++ b/src/conf/storage_encryption_conf.c @@ -31,7 +31,6 @@ #include "viralloc.h" #include "storage_conf.h" #include "storage_encryption_conf.h" -#include "virutil.h" #include "virxml.h" #include "virerror.h" #include "viruuid.h" diff --git a/src/conf/virchrdev.c b/src/conf/virchrdev.c index 1802324..025d4a8 100644 --- a/src/conf/virchrdev.c +++ b/src/conf/virchrdev.c @@ -37,6 +37,7 @@ #include "virlog.h" #include "virerror.h" #include "virfile.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_NONE diff --git a/src/cpu/cpu_powerpc.c b/src/cpu/cpu_powerpc.c index 5f392ee..b253db2 100644 --- a/src/cpu/cpu_powerpc.c +++ b/src/cpu/cpu_powerpc.c @@ -28,7 +28,6 @@ #include "virlog.h" #include "viralloc.h" -#include "virutil.h" #include "cpu.h" #include "cpu_map.h" diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c index 4940c23..14d525e 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -27,13 +27,12 @@ #include "virlog.h" #include "viralloc.h" -#include "virutil.h" #include "cpu.h" #include "cpu_map.h" #include "cpu_x86.h" #include "virbuffer.h" #include "virendian.h" - +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_CPU diff --git a/src/datatypes.c b/src/datatypes.c index 0e1dbb1..d3cf5f2 100644 --- a/src/datatypes.c +++ b/src/datatypes.c @@ -27,7 +27,6 @@ #include "virlog.h" #include "viralloc.h" #include "viruuid.h" -#include "virutil.h" #define VIR_FROM_THIS VIR_FROM_NONE diff --git a/src/driver.c b/src/driver.c index 0a5fe05..c35fcd2 100644 --- a/src/driver.c +++ b/src/driver.c @@ -27,8 +27,8 @@ #include "driver.h" #include "viralloc.h" #include "virlog.h" -#include "virutil.h" #include "configmake.h" +#include "virstring.h" #define DEFAULT_DRIVER_DIR LIBDIR "/libvirt/connection-driver" diff --git a/src/esx/esx_device_monitor.c b/src/esx/esx_device_monitor.c index 0f3421c..7dc0618 100644 --- a/src/esx/esx_device_monitor.c +++ b/src/esx/esx_device_monitor.c @@ -25,7 +25,6 @@ #include <config.h> #include "internal.h" -#include "virutil.h" #include "viralloc.h" #include "virlog.h" #include "viruuid.h" diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index 50ff723..dcf64b8 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -28,7 +28,6 @@ #include "domain_conf.h" #include "snapshot_conf.h" #include "virauth.h" -#include "virutil.h" #include "viralloc.h" #include "virlog.h" #include "viruuid.h" @@ -46,6 +45,7 @@ #include "esx_vi_methods.h" #include "esx_util.h" #include "viruri.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_ESX diff --git a/src/esx/esx_interface_driver.c b/src/esx/esx_interface_driver.c index 44055a1..fe5194c 100644 --- a/src/esx/esx_interface_driver.c +++ b/src/esx/esx_interface_driver.c @@ -25,7 +25,6 @@ #include <config.h> #include "internal.h" -#include "virutil.h" #include "viralloc.h" #include "virlog.h" #include "viruuid.h" diff --git a/src/esx/esx_network_driver.c b/src/esx/esx_network_driver.c index c5be208..fd57b61 100644 --- a/src/esx/esx_network_driver.c +++ b/src/esx/esx_network_driver.c @@ -26,7 +26,6 @@ #include "md5.h" #include "internal.h" -#include "virutil.h" #include "viralloc.h" #include "virlog.h" #include "viruuid.h" diff --git a/src/esx/esx_nwfilter_driver.c b/src/esx/esx_nwfilter_driver.c index 03b7417..3b932de 100644 --- a/src/esx/esx_nwfilter_driver.c +++ b/src/esx/esx_nwfilter_driver.c @@ -25,7 +25,6 @@ #include <config.h> #include "internal.h" -#include "virutil.h" #include "viralloc.h" #include "virlog.h" #include "viruuid.h" diff --git a/src/esx/esx_secret_driver.c b/src/esx/esx_secret_driver.c index 2e36e15..5607a2e 100644 --- a/src/esx/esx_secret_driver.c +++ b/src/esx/esx_secret_driver.c @@ -24,7 +24,6 @@ #include <config.h> #include "internal.h" -#include "virutil.h" #include "viralloc.h" #include "virlog.h" #include "viruuid.h" diff --git a/src/esx/esx_storage_backend_iscsi.c b/src/esx/esx_storage_backend_iscsi.c index a3336a2..941e800 100644 --- a/src/esx/esx_storage_backend_iscsi.c +++ b/src/esx/esx_storage_backend_iscsi.c @@ -28,7 +28,6 @@ #include "internal.h" #include "md5.h" -#include "virutil.h" #include "viralloc.h" #include "virlog.h" #include "viruuid.h" diff --git a/src/esx/esx_storage_backend_vmfs.c b/src/esx/esx_storage_backend_vmfs.c index 329022e..dea6716 100644 --- a/src/esx/esx_storage_backend_vmfs.c +++ b/src/esx/esx_storage_backend_vmfs.c @@ -31,7 +31,6 @@ #include "internal.h" #include "md5.h" -#include "virutil.h" #include "viralloc.h" #include "virlog.h" #include "viruuid.h" @@ -42,6 +41,7 @@ #include "esx_vi.h" #include "esx_vi_methods.h" #include "esx_util.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_ESX diff --git a/src/esx/esx_util.c b/src/esx/esx_util.c index 4d2019b..4566fec 100644 --- a/src/esx/esx_util.c +++ b/src/esx/esx_util.c @@ -28,13 +28,13 @@ #include "internal.h" #include "datatypes.h" -#include "virutil.h" #include "viralloc.h" #include "virlog.h" #include "viruuid.h" #include "vmx.h" #include "esx_private.h" #include "esx_util.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_ESX diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c index d84ce19..ee48159 100644 --- a/src/esx/esx_vi.c +++ b/src/esx/esx_vi.c @@ -29,13 +29,13 @@ #include "virbuffer.h" #include "viralloc.h" #include "virlog.h" -#include "virutil.h" #include "viruuid.h" #include "vmx.h" #include "virxml.h" #include "esx_vi.h" #include "esx_vi_methods.h" #include "esx_util.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_ESX diff --git a/src/esx/esx_vi_types.c b/src/esx/esx_vi_types.c index d1f91ff..7f40308 100644 --- a/src/esx/esx_vi_types.c +++ b/src/esx/esx_vi_types.c @@ -31,9 +31,9 @@ #include "datatypes.h" #include "viralloc.h" #include "virlog.h" -#include "virutil.h" #include "esx_vi.h" #include "esx_vi_types.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_ESX diff --git a/src/fdstream.c b/src/fdstream.c index 53dde97..6f8ce53 100644 --- a/src/fdstream.c +++ b/src/fdstream.c @@ -40,6 +40,7 @@ #include "virutil.h" #include "virfile.h" #include "configmake.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_STREAMS diff --git a/src/hyperv/hyperv_device_monitor.c b/src/hyperv/hyperv_device_monitor.c index c362a12..83ea72a 100644 --- a/src/hyperv/hyperv_device_monitor.c +++ b/src/hyperv/hyperv_device_monitor.c @@ -26,7 +26,6 @@ #include "internal.h" #include "virerror.h" #include "datatypes.h" -#include "virutil.h" #include "viralloc.h" #include "virlog.h" #include "viruuid.h" diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c index 3b381de..7031fdb 100644 --- a/src/hyperv/hyperv_driver.c +++ b/src/hyperv/hyperv_driver.c @@ -27,7 +27,6 @@ #include "datatypes.h" #include "domain_conf.h" #include "virauth.h" -#include "virutil.h" #include "viralloc.h" #include "virlog.h" #include "viruuid.h" @@ -42,6 +41,7 @@ #include "hyperv_util.h" #include "hyperv_wmi.h" #include "openwsman.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_HYPERV diff --git a/src/hyperv/hyperv_interface_driver.c b/src/hyperv/hyperv_interface_driver.c index 477b661..62123a4 100644 --- a/src/hyperv/hyperv_interface_driver.c +++ b/src/hyperv/hyperv_interface_driver.c @@ -26,7 +26,6 @@ #include "internal.h" #include "virerror.h" #include "datatypes.h" -#include "virutil.h" #include "viralloc.h" #include "virlog.h" #include "viruuid.h" diff --git a/src/hyperv/hyperv_network_driver.c b/src/hyperv/hyperv_network_driver.c index 336d722..e23f53a 100644 --- a/src/hyperv/hyperv_network_driver.c +++ b/src/hyperv/hyperv_network_driver.c @@ -26,7 +26,6 @@ #include "internal.h" #include "virerror.h" #include "datatypes.h" -#include "virutil.h" #include "viralloc.h" #include "virlog.h" #include "viruuid.h" diff --git a/src/hyperv/hyperv_nwfilter_driver.c b/src/hyperv/hyperv_nwfilter_driver.c index e748971..0343238 100644 --- a/src/hyperv/hyperv_nwfilter_driver.c +++ b/src/hyperv/hyperv_nwfilter_driver.c @@ -26,7 +26,6 @@ #include "internal.h" #include "virerror.h" #include "datatypes.h" -#include "virutil.h" #include "viralloc.h" #include "virlog.h" #include "viruuid.h" diff --git a/src/hyperv/hyperv_secret_driver.c b/src/hyperv/hyperv_secret_driver.c index 09d9b9e..3f9f8f5 100644 --- a/src/hyperv/hyperv_secret_driver.c +++ b/src/hyperv/hyperv_secret_driver.c @@ -26,7 +26,6 @@ #include "internal.h" #include "virerror.h" #include "datatypes.h" -#include "virutil.h" #include "viralloc.h" #include "virlog.h" #include "viruuid.h" diff --git a/src/hyperv/hyperv_storage_driver.c b/src/hyperv/hyperv_storage_driver.c index b701dc6..5acc4d8 100644 --- a/src/hyperv/hyperv_storage_driver.c +++ b/src/hyperv/hyperv_storage_driver.c @@ -26,7 +26,6 @@ #include "internal.h" #include "virerror.h" #include "datatypes.h" -#include "virutil.h" #include "viralloc.h" #include "virlog.h" #include "viruuid.h" diff --git a/src/hyperv/hyperv_util.c b/src/hyperv/hyperv_util.c index 9bc5b81..a55b939 100644 --- a/src/hyperv/hyperv_util.c +++ b/src/hyperv/hyperv_util.c @@ -24,7 +24,6 @@ #include "internal.h" #include "datatypes.h" -#include "virutil.h" #include "viralloc.h" #include "virlog.h" #include "viruuid.h" diff --git a/src/hyperv/hyperv_wmi.c b/src/hyperv/hyperv_wmi.c index 33ba21f..65fc83d 100644 --- a/src/hyperv/hyperv_wmi.c +++ b/src/hyperv/hyperv_wmi.c @@ -29,11 +29,11 @@ #include "datatypes.h" #include "virlog.h" #include "viralloc.h" -#include "virutil.h" #include "viruuid.h" #include "virbuffer.h" #include "hyperv_private.h" #include "hyperv_wmi.h" +#include "virstring.h" #define WS_SERIALIZER_FREE_MEM_WORKS 0 diff --git a/src/interface/interface_backend_udev.c b/src/interface/interface_backend_udev.c index 79c57ee..7daad16 100644 --- a/src/interface/interface_backend_udev.c +++ b/src/interface/interface_backend_udev.c @@ -30,6 +30,7 @@ #include "interface_driver.h" #include "interface_conf.h" #include "viralloc.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_INTERFACE diff --git a/src/libvirt.c b/src/libvirt.c index 2daa0b4..15b37a3 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -62,6 +62,7 @@ #include "virrandom.h" #include "viruri.h" #include "virthread.h" +#include "virstring.h" #ifdef WITH_TEST # include "test/test_driver.h" diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index a7e1eeb..98660dc 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1745,10 +1745,26 @@ virStorageFileResize; # util/virstring.h +virArgvToString; +virAsprintf; +virSkipSpaces; +virSkipSpacesAndBackslash; +virSkipSpacesBackwards; +virStrcpy; virStringArrayHasString; virStringFreeList; virStringJoin; virStringSplit; +virStrncpy; +virStrToDouble; +virStrToLong_i; +virStrToLong_l; +virStrToLong_ll; +virStrToLong_ui; +virStrToLong_ul; +virStrToLong_ull; +virTrimSpaces; +virVasprintf; # util/virsysinfo.h @@ -1845,8 +1861,6 @@ virUSBDeviceSetUsedBy; saferead; safewrite; safezero; -virArgvToString; -virAsprintf; virBuildPathInternal; virCompareLimitUlong; virDirCreate; @@ -1914,22 +1928,8 @@ virSetInherit; virSetNonBlock; virSetUIDGID; virSetUIDGIDWithCaps; -virSkipSpaces; -virSkipSpacesAndBackslash; -virSkipSpacesBackwards; -virStrcpy; virStrIsPrint; -virStrncpy; -virStrToDouble; -virStrToLong_i; -virStrToLong_l; -virStrToLong_ll; -virStrToLong_ui; -virStrToLong_ul; -virStrToLong_ull; -virTrimSpaces; virValidateWWN; -virVasprintf; # util/viruuid.h diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 212d0fc..7361743 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -44,6 +44,7 @@ #include "xen_xm.h" #include "virtypedparam.h" #include "viruri.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_LIBXL diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c index 97e5d74..0d8ef39 100644 --- a/src/locking/lock_daemon.c +++ b/src/locking/lock_daemon.c @@ -45,6 +45,7 @@ #include "virrandom.h" #include "virhash.h" #include "viruuid.h" +#include "virstring.h" #include "locking/lock_daemon_dispatch.h" #include "locking/lock_protocol.h" diff --git a/src/locking/lock_daemon_config.c b/src/locking/lock_daemon_config.c index 12b06e2..c3d59bd 100644 --- a/src/locking/lock_daemon_config.c +++ b/src/locking/lock_daemon_config.c @@ -30,6 +30,8 @@ #include "virlog.h" #include "rpc/virnetserver.h" #include "configmake.h" +#include "virstring.h" +#include "virutil.h" #define VIR_FROM_THIS VIR_FROM_CONF diff --git a/src/locking/lock_daemon_dispatch.c b/src/locking/lock_daemon_dispatch.c index 4c99088..8a92802 100644 --- a/src/locking/lock_daemon_dispatch.c +++ b/src/locking/lock_daemon_dispatch.c @@ -24,7 +24,6 @@ #include "rpc/virnetserver.h" #include "rpc/virnetserverclient.h" -#include "virutil.h" #include "virlog.h" #include "lock_daemon.h" diff --git a/src/locking/lock_driver_lockd.c b/src/locking/lock_driver_lockd.c index 4b72a05..28a4f15 100644 --- a/src/locking/lock_driver_lockd.c +++ b/src/locking/lock_driver_lockd.c @@ -26,13 +26,13 @@ #include "viralloc.h" #include "virlog.h" #include "viruuid.h" -#include "virutil.h" #include "virfile.h" #include "virerror.h" #include "rpc/virnetclient.h" #include "lock_protocol.h" #include "configmake.h" #include "sha256.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_LOCKING diff --git a/src/locking/lock_driver_sanlock.c b/src/locking/lock_driver_sanlock.c index 95f7d61..48c6d56 100644 --- a/src/locking/lock_driver_sanlock.c +++ b/src/locking/lock_driver_sanlock.c @@ -40,7 +40,6 @@ #include "virlog.h" #include "virerror.h" #include "viralloc.h" -#include "virutil.h" #include "virfile.h" #include "md5.h" #include "virconf.h" diff --git a/src/locking/lock_manager.c b/src/locking/lock_manager.c index ae60caf..82bbe6b 100644 --- a/src/locking/lock_manager.c +++ b/src/locking/lock_manager.c @@ -25,9 +25,9 @@ #include "lock_driver_nop.h" #include "virerror.h" #include "virlog.h" -#include "virutil.h" #include "viralloc.h" #include "viruuid.h" +#include "virstring.h" #if HAVE_DLFCN_H # include <dlfcn.h> diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c index 4a661da..bc3b0d1 100644 --- a/src/lxc/lxc_cgroup.c +++ b/src/lxc/lxc_cgroup.c @@ -28,6 +28,7 @@ #include "virlog.h" #include "viralloc.h" #include "vircgroup.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_LXC diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c index ac0f69c..ff4069a 100644 --- a/src/lxc/lxc_container.c +++ b/src/lxc/lxc_container.c @@ -55,7 +55,6 @@ #include "virerror.h" #include "virlog.h" #include "lxc_container.h" -#include "virutil.h" #include "viralloc.h" #include "virnetdevveth.h" #include "viruuid.h" @@ -64,6 +63,7 @@ #include "vircommand.h" #include "virnetdev.h" #include "virprocess.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_LXC diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c index 740b872..f1800eb 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c @@ -48,7 +48,6 @@ #include "virerror.h" #include "virlog.h" -#include "virutil.h" #include "lxc_conf.h" #include "lxc_container.h" @@ -66,6 +65,7 @@ #include "virprocess.h" #include "virnuma.h" #include "rpc/virnetserver.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_LXC diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 0becdc7..84a97de 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -46,7 +46,6 @@ #include "lxc_driver.h" #include "lxc_process.h" #include "viralloc.h" -#include "virutil.h" #include "virnetdevbridge.h" #include "virnetdevveth.h" #include "nodeinfo.h" @@ -68,6 +67,7 @@ #include "virtime.h" #include "virtypedparam.h" #include "viruri.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_LXC diff --git a/src/lxc/lxc_fuse.c b/src/lxc/lxc_fuse.c index fbd0d56..b6df99c 100644 --- a/src/lxc/lxc_fuse.c +++ b/src/lxc/lxc_fuse.c @@ -35,6 +35,7 @@ #include "virlog.h" #include "virfile.h" #include "virbuffer.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_LXC diff --git a/src/lxc/lxc_fuse.h b/src/lxc/lxc_fuse.h index ccc9b92..a42c39a 100644 --- a/src/lxc/lxc_fuse.h +++ b/src/lxc/lxc_fuse.h @@ -32,7 +32,6 @@ # endif # include "lxc_conf.h" -# include "virutil.h" # include "viralloc.h" struct virLXCMeminfo { diff --git a/src/lxc/lxc_monitor.c b/src/lxc/lxc_monitor.c index 6d11eda..a205d69 100644 --- a/src/lxc/lxc_monitor.c +++ b/src/lxc/lxc_monitor.c @@ -30,6 +30,7 @@ #include "virlog.h" #include "virthread.h" #include "rpc/virnetclient.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_LXC diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index ab07a1e..b10e81c 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -47,6 +47,7 @@ #include "vircommand.h" #include "lxc_hostdev.h" #include "virhook.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_LXC diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 1a81ae3..b561e85 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -51,7 +51,6 @@ #include "driver.h" #include "virbuffer.h" #include "virpidfile.h" -#include "virutil.h" #include "vircommand.h" #include "viralloc.h" #include "viruuid.h" @@ -66,6 +65,7 @@ #include "virnetdevvportprofile.h" #include "virdbus.h" #include "virfile.h" +#include "virstring.h" #define NETWORK_PID_DIR LOCALSTATEDIR "/run/libvirt/network" #define NETWORK_STATE_DIR LOCALSTATEDIR "/lib/libvirt/network" diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c index c9bd68b..95df2e5 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -36,7 +36,6 @@ #include "node_device_conf.h" #include "node_device_hal.h" #include "node_device_driver.h" -#include "virutil.h" #define VIR_FROM_THIS VIR_FROM_NODEDEV diff --git a/src/node_device/node_device_linux_sysfs.c b/src/node_device/node_device_linux_sysfs.c index fd91430..71c7172 100644 --- a/src/node_device/node_device_linux_sysfs.c +++ b/src/node_device/node_device_linux_sysfs.c @@ -32,6 +32,7 @@ #include "viralloc.h" #include "virlog.h" #include "virfile.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_NODEDEV diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c index f98841e..c3c97d7 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -36,9 +36,9 @@ #include "virlog.h" #include "viralloc.h" #include "viruuid.h" -#include "virutil.h" #include "virbuffer.h" #include "virpci.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_NODEDEV diff --git a/src/nodeinfo.c b/src/nodeinfo.c index a5b5608..95c2f33 100644 --- a/src/nodeinfo.c +++ b/src/nodeinfo.c @@ -47,7 +47,6 @@ #include "viralloc.h" #include "nodeinfo.h" #include "physmem.h" -#include "virutil.h" #include "virlog.h" #include "virerror.h" #include "count-one-bits.h" @@ -55,7 +54,7 @@ #include "virarch.h" #include "virfile.h" #include "virtypedparam.h" - +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_NONE diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c b/src/nwfilter/nwfilter_dhcpsnoop.c index 5012b14..df11e89 100644 --- a/src/nwfilter/nwfilter_dhcpsnoop.c +++ b/src/nwfilter/nwfilter_dhcpsnoop.c @@ -68,6 +68,7 @@ #include "virthreadpool.h" #include "configmake.h" #include "virtime.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_NWFILTER diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c index 7892807..7eec3de 100644 --- a/src/nwfilter/nwfilter_driver.c +++ b/src/nwfilter/nwfilter_driver.c @@ -41,6 +41,7 @@ #include "nwfilter_driver.h" #include "nwfilter_gentech_driver.h" #include "configmake.h" +#include "virstring.h" #include "nwfilter_ipaddrmap.h" #include "nwfilter_dhcpsnoop.h" diff --git a/src/nwfilter/nwfilter_ebiptables_driver.c b/src/nwfilter/nwfilter_ebiptables_driver.c index 0e39574..ac94355 100644 --- a/src/nwfilter/nwfilter_ebiptables_driver.c +++ b/src/nwfilter/nwfilter_ebiptables_driver.c @@ -43,7 +43,7 @@ #include "vircommand.h" #include "configmake.h" #include "intprops.h" - +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_NWFILTER diff --git a/src/nwfilter/nwfilter_learnipaddr.c b/src/nwfilter/nwfilter_learnipaddr.c index b399092..14fd32c 100644 --- a/src/nwfilter/nwfilter_learnipaddr.c +++ b/src/nwfilter/nwfilter_learnipaddr.c @@ -54,6 +54,7 @@ #include "nwfilter_ebiptables_driver.h" #include "nwfilter_ipaddrmap.h" #include "nwfilter_learnipaddr.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_NWFILTER diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c index a6f96c7..49fae28 100644 --- a/src/openvz/openvz_conf.c +++ b/src/openvz/openvz_conf.c @@ -47,10 +47,10 @@ #include "viruuid.h" #include "virbuffer.h" #include "viralloc.h" -#include "virutil.h" #include "nodeinfo.h" #include "virfile.h" #include "vircommand.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_OPENVZ diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index f8bec62..e6d7146 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -48,7 +48,6 @@ #include "openvz_driver.h" #include "openvz_util.h" #include "virbuffer.h" -#include "virutil.h" #include "openvz_conf.h" #include "nodeinfo.h" #include "viralloc.h" @@ -58,6 +57,7 @@ #include "vircommand.h" #include "viruri.h" #include "virstatslinux.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_OPENVZ diff --git a/src/parallels/parallels_driver.c b/src/parallels/parallels_driver.c index e126967..c29a5ba 100644 --- a/src/parallels/parallels_driver.c +++ b/src/parallels/parallels_driver.c @@ -42,13 +42,13 @@ #include "datatypes.h" #include "virerror.h" #include "viralloc.h" -#include "virutil.h" #include "virlog.h" #include "vircommand.h" #include "configmake.h" #include "virstoragefile.h" #include "nodeinfo.h" #include "c-ctype.h" +#include "virstring.h" #include "parallels_driver.h" #include "parallels_utils.h" diff --git a/src/parallels/parallels_network.c b/src/parallels/parallels_network.c index 7a9436f..23109d3 100644 --- a/src/parallels/parallels_network.c +++ b/src/parallels/parallels_network.c @@ -28,8 +28,8 @@ #include "viralloc.h" #include "virerror.h" #include "md5.h" - #include "parallels_utils.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_PARALLELS #define PARALLELS_ROUTED_NETWORK_UUID "eb593dd1-6846-45b0-84a0-de0729286982" diff --git a/src/parallels/parallels_storage.c b/src/parallels/parallels_storage.c index 271f370..4c98e43 100644 --- a/src/parallels/parallels_storage.c +++ b/src/parallels/parallels_storage.c @@ -36,8 +36,8 @@ #include "configmake.h" #include "virstoragefile.h" #include "virerror.h" - #include "parallels_utils.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_PARALLELS diff --git a/src/parallels/parallels_utils.c b/src/parallels/parallels_utils.c index 0b589ab..4236ed5 100644 --- a/src/parallels/parallels_utils.c +++ b/src/parallels/parallels_utils.c @@ -28,8 +28,8 @@ #include "virerror.h" #include "viralloc.h" #include "virjson.h" - #include "parallels_utils.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_PARALLELS diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index f5c66ba..85eb650 100644 --- a/src/phyp/phyp_driver.c +++ b/src/phyp/phyp_driver.c @@ -43,7 +43,6 @@ #include "internal.h" #include "virauth.h" -#include "virutil.h" #include "datatypes.h" #include "virbuffer.h" #include "viralloc.h" @@ -56,8 +55,8 @@ #include "nodeinfo.h" #include "virfile.h" #include "interface_conf.h" - #include "phyp_driver.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_PHYP diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index 8c8c38b..d116b23 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -41,6 +41,7 @@ #include "virprocess.h" #include "virtime.h" #include "virobject.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_QEMU diff --git a/src/qemu/qemu_bridge_filter.c b/src/qemu/qemu_bridge_filter.c index 3bc1141..ab4db9a 100644 --- a/src/qemu/qemu_bridge_filter.c +++ b/src/qemu/qemu_bridge_filter.c @@ -25,7 +25,6 @@ #include "virebtables.h" #include "qemu_conf.h" #include "qemu_driver.h" -#include "virutil.h" #include "virerror.h" #include "virlog.h" diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 2acf535..a3a8d1f 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -27,7 +27,6 @@ #include "viralloc.h" #include "virlog.h" #include "virerror.h" -#include "virutil.h" #include "virfile.h" #include "virpidfile.h" #include "virprocess.h" diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index 891984a..386751b 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -30,7 +30,6 @@ #include "virlog.h" #include "viralloc.h" #include "virerror.h" -#include "virutil.h" #include "domain_audit.h" #define VIR_FROM_THIS VIR_FROM_QEMU diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index d23bdfc..e2201ec 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -33,7 +33,6 @@ #include "virlog.h" #include "virarch.h" #include "virerror.h" -#include "virutil.h" #include "virfile.h" #include "virnetdev.h" #include "virstring.h" diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 7c3f317..c16b90d 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -42,7 +42,6 @@ #include "viruuid.h" #include "virbuffer.h" #include "virconf.h" -#include "virutil.h" #include "viralloc.h" #include "datatypes.h" #include "virxml.h" diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index d927716..e31141a 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -37,6 +37,7 @@ #include "domain_event.h" #include "virtime.h" #include "virstoragefile.h" +#include "virstring.h" #include <sys/time.h> #include <fcntl.h> diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 2d3b24a..1e184dd 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -61,7 +61,6 @@ #include "virlog.h" #include "datatypes.h" #include "virbuffer.h" -#include "virutil.h" #include "nodeinfo.h" #include "virstatslinux.h" #include "capabilities.h" @@ -92,6 +91,7 @@ #include "virtime.h" #include "virtypedparam.h" #include "virbitmap.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_QEMU diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index f5fa1c4..24ff142 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -47,6 +47,7 @@ #include "virnetdevtap.h" #include "device_conf.h" #include "virstoragefile.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_QEMU #define CHANGE_MEDIA_RETRIES 10 diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 6ad1c30..0732614 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -44,7 +44,6 @@ #include "virlog.h" #include "virerror.h" #include "viralloc.h" -#include "virutil.h" #include "virfile.h" #include "datatypes.h" #include "fdstream.h" @@ -55,7 +54,7 @@ #include "virstoragefile.h" #include "viruri.h" #include "virhook.h" - +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_QEMU diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 1b1d4a1..4deb2d6 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -37,6 +37,7 @@ #include "virfile.h" #include "virprocess.h" #include "virobject.h" +#include "virstring.h" #ifdef WITH_DTRACE_PROBES # include "libvirt_qemu_probes.h" diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c index daade3d..696961b 100644 --- a/src/qemu/qemu_monitor_text.c +++ b/src/qemu/qemu_monitor_text.c @@ -40,6 +40,7 @@ #include "datatypes.h" #include "virerror.h" #include "virbuffer.h" +#include "virstring.h" #ifdef WITH_DTRACE_PROBES # include "libvirt_qemu_probes.h" diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index f12d7d5..54a55b9 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -50,7 +50,6 @@ #include "virhook.h" #include "virfile.h" #include "virpidfile.h" -#include "virutil.h" #include "c-ctype.h" #include "nodeinfo.h" #include "domain_audit.h" @@ -64,6 +63,7 @@ #include "virbitmap.h" #include "viratomic.h" #include "virnuma.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_QEMU diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index f66304c..13212d0 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -40,7 +40,6 @@ #include "lxc_protocol.h" #include "qemu_protocol.h" #include "viralloc.h" -#include "virutil.h" #include "virfile.h" #include "vircommand.h" #include "intprops.h" @@ -48,6 +47,7 @@ #include "viruri.h" #include "virauth.h" #include "virauthconfig.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_REMOTE diff --git a/src/rpc/virkeepalive.c b/src/rpc/virkeepalive.c index d49082c..8ae5c6c 100644 --- a/src/rpc/virkeepalive.c +++ b/src/rpc/virkeepalive.c @@ -26,7 +26,6 @@ #include "virthread.h" #include "virfile.h" #include "virlog.h" -#include "virutil.h" #include "virerror.h" #include "virnetsocket.h" #include "virkeepaliveprotocol.h" diff --git a/src/rpc/virnetserverclient.c b/src/rpc/virnetserverclient.c index 58fb0b4..2bde5c7 100644 --- a/src/rpc/virnetserverclient.c +++ b/src/rpc/virnetserverclient.c @@ -34,6 +34,8 @@ #include "viralloc.h" #include "virthread.h" #include "virkeepalive.h" +#include "virstring.h" +#include "virutil.h" #define VIR_FROM_THIS VIR_FROM_RPC diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c index c4fd9ee..e950d7f 100644 --- a/src/rpc/virnetsocket.c +++ b/src/rpc/virnetsocket.c @@ -52,7 +52,7 @@ #include "virfile.h" #include "virthread.h" #include "virprocess.h" - +#include "virstring.h" #include "passfd.h" #if WITH_SSH2 diff --git a/src/rpc/virnetsshsession.c b/src/rpc/virnetsshsession.c index 9ce99f8..27750fc 100644 --- a/src/rpc/virnetsshsession.c +++ b/src/rpc/virnetsshsession.c @@ -34,6 +34,7 @@ #include "virutil.h" #include "virerror.h" #include "virobject.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_SSH diff --git a/src/rpc/virnettlscontext.c b/src/rpc/virnettlscontext.c index eed0439..7f5975d 100644 --- a/src/rpc/virnettlscontext.c +++ b/src/rpc/virnettlscontext.c @@ -29,6 +29,7 @@ #include "gnutls_1_0_compat.h" #include "virnettlscontext.h" +#include "virstring.h" #include "viralloc.h" #include "virerror.h" diff --git a/src/secret/secret_driver.c b/src/secret/secret_driver.c index 646c8ff..377b9f4 100644 --- a/src/secret/secret_driver.c +++ b/src/secret/secret_driver.c @@ -37,11 +37,11 @@ #include "secret_conf.h" #include "secret_driver.h" #include "virthread.h" -#include "virutil.h" #include "viruuid.h" #include "virerror.h" #include "virfile.h" #include "configmake.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_SECRET diff --git a/src/security/security_apparmor.c b/src/security/security_apparmor.c index 4fa0384..a2deafb 100644 --- a/src/security/security_apparmor.c +++ b/src/security/security_apparmor.c @@ -38,7 +38,6 @@ #include "internal.h" #include "security_apparmor.h" -#include "virutil.h" #include "viralloc.h" #include "virerror.h" #include "datatypes.h" @@ -49,6 +48,7 @@ #include "configmake.h" #include "vircommand.h" #include "virlog.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_SECURITY #define SECURITY_APPARMOR_VOID_DOI "0" diff --git a/src/security/security_dac.c b/src/security/security_dac.c index 0366c17..4143495 100644 --- a/src/security/security_dac.c +++ b/src/security/security_dac.c @@ -25,12 +25,12 @@ #include "security_dac.h" #include "virerror.h" -#include "virutil.h" #include "viralloc.h" #include "virlog.h" #include "virpci.h" #include "virusb.h" #include "virstoragefile.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_SECURITY #define SECURITY_DAC_NAME "dac" diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c index 87a09c7..201fff6 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -34,7 +34,6 @@ #include "security_driver.h" #include "security_selinux.h" #include "virerror.h" -#include "virutil.h" #include "viralloc.h" #include "virlog.h" #include "virpci.h" @@ -45,6 +44,7 @@ #include "virrandom.h" #include "virconf.h" #include "virtpm.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_SECURITY diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index 3c9515f..b526919 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -41,7 +41,6 @@ #include "internal.h" #include "virbuffer.h" -#include "virutil.h" #include "viralloc.h" #include "vircommand.h" @@ -55,6 +54,7 @@ #include "virfile.h" #include "configmake.h" #include "virrandom.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_SECURITY diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c index d4aabb6..b85a5a9 100644 --- a/src/storage/storage_backend.c +++ b/src/storage/storage_backend.c @@ -45,7 +45,6 @@ #include "datatypes.h" #include "virerror.h" -#include "virutil.h" #include "viralloc.h" #include "internal.h" #include "secret_conf.h" @@ -55,6 +54,7 @@ #include "virlog.h" #include "virfile.h" #include "stat-time.h" +#include "virstring.h" #if WITH_STORAGE_LVM # include "storage_backend_logical.h" diff --git a/src/storage/storage_backend_disk.c b/src/storage/storage_backend_disk.c index 1faf1ae..6da2d12 100644 --- a/src/storage/storage_backend_disk.c +++ b/src/storage/storage_backend_disk.c @@ -30,10 +30,10 @@ #include "virerror.h" #include "virlog.h" #include "storage_backend_disk.h" -#include "virutil.h" #include "viralloc.h" #include "vircommand.h" #include "configmake.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_STORAGE diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c index c1684f7..8288b1e 100644 --- a/src/storage/storage_backend_fs.c +++ b/src/storage/storage_backend_fs.c @@ -50,6 +50,7 @@ #include "virxml.h" #include "virfile.h" #include "virlog.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_STORAGE diff --git a/src/storage/storage_backend_iscsi.c b/src/storage/storage_backend_iscsi.c index f6b76ed..cf25919 100644 --- a/src/storage/storage_backend_iscsi.c +++ b/src/storage/storage_backend_iscsi.c @@ -38,12 +38,12 @@ #include "virerror.h" #include "storage_backend_scsi.h" #include "storage_backend_iscsi.h" -#include "virutil.h" #include "viralloc.h" #include "virlog.h" #include "virfile.h" #include "vircommand.h" #include "virrandom.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_STORAGE diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c index 4cf6647..316043f 100644 --- a/src/storage/storage_backend_logical.c +++ b/src/storage/storage_backend_logical.c @@ -38,6 +38,7 @@ #include "viralloc.h" #include "virlog.h" #include "virfile.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_STORAGE diff --git a/src/storage/storage_backend_mpath.c b/src/storage/storage_backend_mpath.c index 6049063..6e742f7 100644 --- a/src/storage/storage_backend_mpath.c +++ b/src/storage/storage_backend_mpath.c @@ -35,6 +35,7 @@ #include "viralloc.h" #include "virlog.h" #include "virfile.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_STORAGE diff --git a/src/storage/storage_backend_rbd.c b/src/storage/storage_backend_rbd.c index e815192..ca23d4b 100644 --- a/src/storage/storage_backend_rbd.c +++ b/src/storage/storage_backend_rbd.c @@ -26,7 +26,6 @@ #include "virerror.h" #include "storage_backend_rbd.h" #include "storage_conf.h" -#include "virutil.h" #include "viralloc.h" #include "virlog.h" #include "base64.h" diff --git a/src/storage/storage_backend_scsi.c b/src/storage/storage_backend_scsi.c index 987d218..154a56a 100644 --- a/src/storage/storage_backend_scsi.c +++ b/src/storage/storage_backend_scsi.c @@ -34,6 +34,7 @@ #include "virlog.h" #include "virfile.h" #include "vircommand.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_STORAGE diff --git a/src/storage/storage_backend_sheepdog.c b/src/storage/storage_backend_sheepdog.c index 15fa29c..dfa5673 100644 --- a/src/storage/storage_backend_sheepdog.c +++ b/src/storage/storage_backend_sheepdog.c @@ -30,7 +30,6 @@ #include "storage_backend_sheepdog.h" #include "storage_conf.h" #include "vircommand.h" -#include "virutil.h" #include "viralloc.h" #include "virlog.h" diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index f190eb7..990f0b1 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -39,7 +39,6 @@ #include "virerror.h" #include "datatypes.h" #include "driver.h" -#include "virutil.h" #include "storage_driver.h" #include "storage_conf.h" #include "viralloc.h" @@ -48,6 +47,7 @@ #include "virfile.h" #include "fdstream.h" #include "configmake.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_STORAGE diff --git a/src/test/test_driver.c b/src/test/test_driver.c index d964fb2..f60f106 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -36,7 +36,6 @@ #include "datatypes.h" #include "test_driver.h" #include "virbuffer.h" -#include "virutil.h" #include "viruuid.h" #include "capabilities.h" #include "configmake.h" @@ -54,6 +53,7 @@ #include "virfile.h" #include "virtypedparam.h" #include "virrandom.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_TEST diff --git a/src/uml/uml_conf.c b/src/uml/uml_conf.c index 4fa7927..a55b5b1 100644 --- a/src/uml/uml_conf.c +++ b/src/uml/uml_conf.c @@ -38,7 +38,6 @@ #include "viruuid.h" #include "virbuffer.h" #include "virconf.h" -#include "virutil.h" #include "viralloc.h" #include "nodeinfo.h" #include "virlog.h" @@ -47,7 +46,7 @@ #include "vircommand.h" #include "virnetdevtap.h" #include "virnodesuspend.h" - +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_UML diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c index 9b0aba6..66c00b2 100644 --- a/src/uml/uml_driver.c +++ b/src/uml/uml_driver.c @@ -46,7 +46,6 @@ #include "uml_driver.h" #include "uml_conf.h" #include "virbuffer.h" -#include "virutil.h" #include "nodeinfo.h" #include "virstatslinux.h" #include "capabilities.h" @@ -65,6 +64,7 @@ #include "virnodesuspend.h" #include "virprocess.h" #include "viruri.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_UML diff --git a/src/util/iohelper.c b/src/util/iohelper.c index 2230bcb..33ba852 100644 --- a/src/util/iohelper.c +++ b/src/util/iohelper.c @@ -40,6 +40,7 @@ #include "virerror.h" #include "configmake.h" #include "virrandom.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_STORAGE diff --git a/src/util/viraudit.c b/src/util/viraudit.c index 0f4bb4f..5dd4e1f 100644 --- a/src/util/viraudit.c +++ b/src/util/viraudit.c @@ -30,9 +30,9 @@ #include "virerror.h" #include "virlog.h" #include "viraudit.h" -#include "virutil.h" #include "virfile.h" #include "viralloc.h" +#include "virstring.h" /* Provide the macros in case the header file is old. FIXME: should be removed. */ diff --git a/src/util/virauth.c b/src/util/virauth.c index c26e340..fdcefe1 100644 --- a/src/util/virauth.c +++ b/src/util/virauth.c @@ -32,6 +32,7 @@ #include "virerror.h" #include "configmake.h" #include "virauthconfig.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_AUTH diff --git a/src/util/virauthconfig.c b/src/util/virauthconfig.c index 1d1f084..4259cb3 100644 --- a/src/util/virauthconfig.c +++ b/src/util/virauthconfig.c @@ -26,10 +26,9 @@ #include "virkeyfile.h" #include "viralloc.h" -#include "virutil.h" #include "virlog.h" #include "virerror.h" - +#include "virstring.h" struct _virAuthConfig { virKeyFilePtr keyfile; diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c index 998c302..c81555a 100644 --- a/src/util/virbitmap.c +++ b/src/util/virbitmap.c @@ -33,10 +33,9 @@ #include "virbitmap.h" #include "viralloc.h" #include "virbuffer.h" -#include "virutil.h" #include "c-ctype.h" #include "count-one-bits.h" - +#include "virstring.h" struct _virBitmap { size_t max_bit; diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 98521ec..f6f27d9 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -50,6 +50,7 @@ #include "virprocess.h" #include "virbuffer.h" #include "virthread.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_NONE diff --git a/src/util/vircommand.h b/src/util/vircommand.h index 18568fe..a402139 100644 --- a/src/util/vircommand.h +++ b/src/util/vircommand.h @@ -23,7 +23,6 @@ # define __VIR_COMMAND_H__ # include "internal.h" -# include "virutil.h" # include "virbuffer.h" typedef struct _virCommand virCommand; diff --git a/src/util/virdnsmasq.c b/src/util/virdnsmasq.c index 2e63d83..4f05633 100644 --- a/src/util/virdnsmasq.c +++ b/src/util/virdnsmasq.c @@ -49,6 +49,7 @@ #include "virerror.h" #include "virlog.h" #include "virfile.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_NETWORK #define DNSMASQ_HOSTSFILE_SUFFIX "hostsfile" diff --git a/src/util/virebtables.c b/src/util/virebtables.c index 65c0ac3..6bc6fed 100644 --- a/src/util/virebtables.c +++ b/src/util/virebtables.c @@ -48,6 +48,8 @@ #include "virerror.h" #include "virlog.h" #include "virthread.h" +#include "virstring.h" +#include "virutil.h" #if HAVE_FIREWALLD static char *firewall_cmd_path = NULL; diff --git a/src/util/virerror.c b/src/util/virerror.c index 8a329a9..af4da8c 100644 --- a/src/util/virerror.c +++ b/src/util/virerror.c @@ -33,6 +33,7 @@ #include "viralloc.h" #include "virthread.h" #include "virutil.h" +#include "virstring.h" virThreadLocal virLastErr; diff --git a/src/util/virfile.c b/src/util/virfile.c index fbaeedd..25a0501 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -42,6 +42,7 @@ #include "viralloc.h" #include "virerror.h" #include "virlog.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_NONE diff --git a/src/util/virhook.h b/src/util/virhook.h index a63a125..96bf4cf 100644 --- a/src/util/virhook.h +++ b/src/util/virhook.h @@ -25,7 +25,6 @@ # define __VIR_HOOKS_H__ # include "internal.h" -# include "virutil.h" enum virHookDriverType { VIR_HOOK_DRIVER_DAEMON = 0, /* Daemon related events */ diff --git a/src/util/virinitctl.c b/src/util/virinitctl.c index 1618ffa..3322454 100644 --- a/src/util/virinitctl.c +++ b/src/util/virinitctl.c @@ -32,6 +32,7 @@ #include "virutil.h" #include "viralloc.h" #include "virfile.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_INITCTL diff --git a/src/util/viriptables.c b/src/util/viriptables.c index 19d6161..06a1356 100644 --- a/src/util/viriptables.c +++ b/src/util/viriptables.c @@ -46,6 +46,8 @@ #include "virerror.h" #include "virlog.h" #include "virthread.h" +#include "virstring.h" +#include "virutil.h" #if HAVE_FIREWALLD static char *firewall_cmd_path = NULL; diff --git a/src/util/virjson.c b/src/util/virjson.c index e6a3b1b..92138d3 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -27,6 +27,7 @@ #include "viralloc.h" #include "virerror.h" #include "virlog.h" +#include "virstring.h" #include "virutil.h" #if WITH_YAJL diff --git a/src/util/virlockspace.c b/src/util/virlockspace.c index 4ff0f3a..620a460 100644 --- a/src/util/virlockspace.c +++ b/src/util/virlockspace.c @@ -29,6 +29,7 @@ #include "virfile.h" #include "virhash.h" #include "virthread.h" +#include "virstring.h" #include <fcntl.h> #include <unistd.h> diff --git a/src/util/virlog.c b/src/util/virlog.c index e31abb0..bd47b38 100644 --- a/src/util/virlog.c +++ b/src/util/virlog.c @@ -50,6 +50,7 @@ #include "virfile.h" #include "virtime.h" #include "intprops.h" +#include "virstring.h" /* Journald output is only supported on Linux new enough to expose * htole64. */ diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index 7ffaac1..bb06dcc 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -30,6 +30,8 @@ #include "viralloc.h" #include "virpci.h" #include "virlog.h" +#include "virstring.h" +#include "virutil.h" #include <sys/ioctl.h> #include <net/if.h> diff --git a/src/util/virnetdevbandwidth.c b/src/util/virnetdevbandwidth.c index 2c5b63a..ccc1449 100644 --- a/src/util/virnetdevbandwidth.c +++ b/src/util/virnetdevbandwidth.c @@ -26,6 +26,7 @@ #include "vircommand.h" #include "viralloc.h" #include "virerror.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_NONE diff --git a/src/util/virnetdevbridge.c b/src/util/virnetdevbridge.c index 9d46cc4..130829c 100644 --- a/src/util/virnetdevbridge.c +++ b/src/util/virnetdevbridge.c @@ -28,6 +28,7 @@ #include "virfile.h" #include "viralloc.h" #include "intprops.h" +#include "virstring.h" #include <sys/ioctl.h> #include <sys/socket.h> diff --git a/src/util/virnetdevmacvlan.c b/src/util/virnetdevmacvlan.c index e76e94c..0c4fcbd 100644 --- a/src/util/virnetdevmacvlan.c +++ b/src/util/virnetdevmacvlan.c @@ -29,7 +29,6 @@ #include "virnetdevmacvlan.h" #include "virmacaddr.h" -#include "virutil.h" #include "virerror.h" #include "virthread.h" diff --git a/src/util/virnetdevopenvswitch.c b/src/util/virnetdevopenvswitch.c index 4fe077a..2aee445 100644 --- a/src/util/virnetdevopenvswitch.c +++ b/src/util/virnetdevopenvswitch.c @@ -28,6 +28,7 @@ #include "viralloc.h" #include "virerror.h" #include "virmacaddr.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_NONE diff --git a/src/util/virnetdevopenvswitch.h b/src/util/virnetdevopenvswitch.h index 3216ea0..0852e4d 100644 --- a/src/util/virnetdevopenvswitch.h +++ b/src/util/virnetdevopenvswitch.h @@ -25,7 +25,6 @@ # define __VIR_NETDEV_OPENVSWITCH_H__ # include "internal.h" -# include "virutil.h" # include "virnetdevvportprofile.h" # include "virnetdevvlan.h" diff --git a/src/util/virnetdevtap.c b/src/util/virnetdevtap.c index fac95ec..0cd2e31 100644 --- a/src/util/virnetdevtap.c +++ b/src/util/virnetdevtap.c @@ -31,7 +31,7 @@ #include "virfile.h" #include "viralloc.h" #include "virlog.h" -#include "virutil.h" +#include "virstring.h" #include <sys/ioctl.h> #include <net/if.h> diff --git a/src/util/virnetdevveth.c b/src/util/virnetdevveth.c index 3f81655..5daf21e 100644 --- a/src/util/virnetdevveth.c +++ b/src/util/virnetdevveth.c @@ -30,6 +30,8 @@ #include "virlog.h" #include "vircommand.h" #include "virerror.h" +#include "virstring.h" +#include "virutil.h" #define VIR_FROM_THIS VIR_FROM_NONE diff --git a/src/util/virnetdevvportprofile.c b/src/util/virnetdevvportprofile.c index 13ccbab..883aa46 100644 --- a/src/util/virnetdevvportprofile.c +++ b/src/util/virnetdevvportprofile.c @@ -25,6 +25,7 @@ #include "virnetdevvportprofile.h" #include "virerror.h" #include "viralloc.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_NET diff --git a/src/util/virpci.c b/src/util/virpci.c index 97bba74..6ed6a90 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -42,6 +42,8 @@ #include "vircommand.h" #include "virerror.h" #include "virfile.h" +#include "virstring.h" +#include "virutil.h" #define PCI_SYSFS "/sys/bus/pci/" #define PCI_ID_LEN 10 /* "XXXX XXXX" */ diff --git a/src/util/virpidfile.c b/src/util/virpidfile.c index 14c9f9f..298d57c 100644 --- a/src/util/virpidfile.c +++ b/src/util/virpidfile.c @@ -36,6 +36,7 @@ #include "virerror.h" #include "c-ctype.h" #include "areadlink.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_NONE diff --git a/src/util/virprocess.c b/src/util/virprocess.c index fb81805..73f5123 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -39,6 +39,7 @@ #include "virfile.h" #include "virlog.h" #include "virutil.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_NONE diff --git a/src/util/virrandom.c b/src/util/virrandom.c index 6c5bc91..f46d702 100644 --- a/src/util/virrandom.c +++ b/src/util/virrandom.c @@ -32,6 +32,7 @@ #include "virutil.h" #include "virerror.h" #include "virlog.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_NONE diff --git a/src/util/virsexpr.c b/src/util/virsexpr.c index 81dfbe6..23b6781 100644 --- a/src/util/virsexpr.c +++ b/src/util/virsexpr.c @@ -30,8 +30,8 @@ #include "virerror.h" #include "virsexpr.h" -#include "virutil.h" #include "viralloc.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_SEXPR diff --git a/src/util/virsocketaddr.c b/src/util/virsocketaddr.c index 7ee450b..d6a0d93 100644 --- a/src/util/virsocketaddr.c +++ b/src/util/virsocketaddr.c @@ -25,7 +25,7 @@ #include "virsocketaddr.h" #include "virerror.h" -#include "virutil.h" +#include "virstring.h" #include <netdb.h> diff --git a/src/util/virstatslinux.c b/src/util/virstatslinux.c index d3e1a02..60b72dc 100644 --- a/src/util/virstatslinux.c +++ b/src/util/virstatslinux.c @@ -34,7 +34,6 @@ # include "virerror.h" # include "datatypes.h" -# include "virutil.h" # include "virstatslinux.h" # include "viralloc.h" # include "virfile.h" diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index aabb5c8..c7bb85a 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -43,6 +43,8 @@ #include "vircommand.h" #include "virhash.h" #include "virendian.h" +#include "virstring.h" +#include "virutil.h" #define VIR_FROM_THIS VIR_FROM_STORAGE diff --git a/src/util/virstring.c b/src/util/virstring.c index 122ebb8..9b4cb01 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -21,6 +21,10 @@ #include <config.h> +#include <stdlib.h> +#include <stdio.h> + +#include "c-ctype.h" #include "virstring.h" #include "viralloc.h" #include "virbuffer.h" @@ -180,3 +184,334 @@ virStringArrayHasString(char **strings, const char *needle) return false; } + +/* Like strtol, but produce an "int" result, and check more carefully. + Return 0 upon success; return -1 to indicate failure. + When END_PTR is NULL, the byte after the final valid digit must be NUL. + Otherwise, it's like strtol and lets the caller check any suffix for + validity. This function is careful to return -1 when the string S + represents a number that is not representable as an "int". */ +int +virStrToLong_i(char const *s, char **end_ptr, int base, int *result) +{ + long int val; + char *p; + int err; + + errno = 0; + val = strtol(s, &p, base); /* exempt from syntax-check */ + err = (errno || (!end_ptr && *p) || p == s || (int) val != val); + if (end_ptr) + *end_ptr = p; + if (err) + return -1; + *result = val; + return 0; +} + +/* Just like virStrToLong_i, above, but produce an "unsigned int" value. */ +int +virStrToLong_ui(char const *s, char **end_ptr, int base, unsigned int *result) +{ + unsigned long int val; + char *p; + int err; + + errno = 0; + val = strtoul(s, &p, base); /* exempt from syntax-check */ + err = (errno || (!end_ptr && *p) || p == s || (unsigned int) val != val); + if (end_ptr) + *end_ptr = p; + if (err) + return -1; + *result = val; + return 0; +} + +/* Just like virStrToLong_i, above, but produce a "long" value. */ +int +virStrToLong_l(char const *s, char **end_ptr, int base, long *result) +{ + long int val; + char *p; + int err; + + errno = 0; + val = strtol(s, &p, base); /* exempt from syntax-check */ + err = (errno || (!end_ptr && *p) || p == s); + if (end_ptr) + *end_ptr = p; + if (err) + return -1; + *result = val; + return 0; +} + +/* Just like virStrToLong_i, above, but produce an "unsigned long" value. */ +int +virStrToLong_ul(char const *s, char **end_ptr, int base, unsigned long *result) +{ + unsigned long int val; + char *p; + int err; + + errno = 0; + val = strtoul(s, &p, base); /* exempt from syntax-check */ + err = (errno || (!end_ptr && *p) || p == s); + if (end_ptr) + *end_ptr = p; + if (err) + return -1; + *result = val; + return 0; +} + +/* Just like virStrToLong_i, above, but produce a "long long" value. */ +int +virStrToLong_ll(char const *s, char **end_ptr, int base, long long *result) +{ + long long val; + char *p; + int err; + + errno = 0; + val = strtoll(s, &p, base); /* exempt from syntax-check */ + err = (errno || (!end_ptr && *p) || p == s); + if (end_ptr) + *end_ptr = p; + if (err) + return -1; + *result = val; + return 0; +} + +/* Just like virStrToLong_i, above, but produce an "unsigned long long" value. */ +int +virStrToLong_ull(char const *s, char **end_ptr, int base, unsigned long long *result) +{ + unsigned long long val; + char *p; + int err; + + errno = 0; + val = strtoull(s, &p, base); /* exempt from syntax-check */ + err = (errno || (!end_ptr && *p) || p == s); + if (end_ptr) + *end_ptr = p; + if (err) + return -1; + *result = val; + return 0; +} + +int +virStrToDouble(char const *s, + char **end_ptr, + double *result) +{ + double val; + char *p; + int err; + + errno = 0; + val = strtod(s, &p); /* exempt from syntax-check */ + err = (errno || (!end_ptr && *p) || p == s); + if (end_ptr) + *end_ptr = p; + if (err) + return -1; + *result = val; + return 0; +} + +/** + * virVasprintf + * + * like glibc's vasprintf but makes sure *strp == NULL on failure + */ +int +virVasprintf(char **strp, const char *fmt, va_list list) +{ + int ret; + + if ((ret = vasprintf(strp, fmt, list)) == -1) + *strp = NULL; + + return ret; +} + +/** + * virAsprintf + * + * like glibc's_asprintf but makes sure *strp == NULL on failure + */ +int +virAsprintf(char **strp, const char *fmt, ...) +{ + va_list ap; + int ret; + + va_start(ap, fmt); + ret = virVasprintf(strp, fmt, ap); + va_end(ap); + return ret; +} + +/** + * virStrncpy + * + * A safe version of strncpy. The last parameter is the number of bytes + * available in the destination string, *not* the number of bytes you want + * to copy. If the destination is not large enough to hold all n of the + * src string bytes plus a \0, NULL is returned and no data is copied. + * If the destination is large enough to hold the n bytes plus \0, then the + * string is copied and a pointer to the destination string is returned. + */ +char * +virStrncpy(char *dest, const char *src, size_t n, size_t destbytes) +{ + char *ret; + + if (n > (destbytes - 1)) + return NULL; + + ret = strncpy(dest, src, n); + /* strncpy NULL terminates iff the last character is \0. Therefore + * force the last byte to be \0 + */ + dest[n] = '\0'; + + return ret; +} + +/** + * virStrcpy + * + * A safe version of strcpy. The last parameter is the number of bytes + * available in the destination string, *not* the number of bytes you want + * to copy. If the destination is not large enough to hold all n of the + * src string bytes plus a \0, NULL is returned and no data is copied. + * If the destination is large enough to hold the source plus \0, then the + * string is copied and a pointer to the destination string is returned. + */ +char * +virStrcpy(char *dest, const char *src, size_t destbytes) +{ + return virStrncpy(dest, src, strlen(src), destbytes); +} + +/** + * virSkipSpaces: + * @str: pointer to the char pointer used + * + * Skip potential blanks, this includes space tabs, line feed, + * carriage returns. + */ +void +virSkipSpaces(const char **str) +{ + const char *cur = *str; + + while (c_isspace(*cur)) + cur++; + *str = cur; +} + +/** + * virSkipSpacesAndBackslash: + * @str: pointer to the char pointer used + * + * Like virSkipSpaces, but also skip backslashes erroneously emitted + * by xend + */ +void +virSkipSpacesAndBackslash(const char **str) +{ + const char *cur = *str; + + while (c_isspace(*cur) || *cur == '\\') + cur++; + *str = cur; +} + +/** + * virTrimSpaces: + * @str: string to modify to remove all trailing spaces + * @endp: track the end of the string + * + * If @endp is NULL on entry, then all spaces prior to the trailing + * NUL in @str are removed, by writing NUL into the appropriate + * location. If @endp is non-NULL but points to a NULL pointer, + * then all spaces prior to the trailing NUL in @str are removed, + * NUL is written to the new string end, and endp is set to the + * location of the (new) string end. If @endp is non-NULL and + * points to a non-NULL pointer, then that pointer is used as + * the end of the string, endp is set to the (new) location, but + * no NUL pointer is written into the string. + */ +void +virTrimSpaces(char *str, char **endp) +{ + char *end; + + if (!endp || !*endp) + end = str + strlen(str); + else + end = *endp; + while (end > str && c_isspace(end[-1])) + end--; + if (endp) { + if (!*endp) + *end = '\0'; + *endp = end; + } else { + *end = '\0'; + } +} + +/** + * virSkipSpacesBackwards: + * @str: start of string + * @endp: on entry, *endp must be NULL or a location within @str, on exit, + * will be adjusted to skip trailing spaces, or to NULL if @str had nothing + * but spaces. + */ +void +virSkipSpacesBackwards(const char *str, char **endp) +{ + /* Casting away const is safe, since virTrimSpaces does not + * modify string with this particular usage. */ + char *s = (char*) str; + + if (!*endp) + *endp = s + strlen(s); + virTrimSpaces(s, endp); + if (s == *endp) + *endp = NULL; +} + +char * +virArgvToString(const char *const *argv) +{ + int len, i; + char *ret, *p; + + for (len = 1, i = 0; argv[i]; i++) + len += strlen(argv[i]) + 1; + + if (VIR_ALLOC_N(ret, len) < 0) + return NULL; + p = ret; + + for (i = 0; argv[i]; i++) { + if (i != 0) + *(p++) = ' '; + + strcpy(p, argv[i]); + p += strlen(argv[i]); + } + + *p = '\0'; + + return ret; +} diff --git a/src/util/virstring.h b/src/util/virstring.h index 2ceadc6..457caa2 100644 --- a/src/util/virstring.h +++ b/src/util/virstring.h @@ -22,6 +22,8 @@ #ifndef __VIR_STRING_H__ # define __VIR_STRING_H__ +# include <stdarg.h> + # include "internal.h" char **virStringSplit(const char *string, @@ -37,4 +39,52 @@ void virStringFreeList(char **strings); bool virStringArrayHasString(char **strings, const char *needle); +char *virArgvToString(const char *const *argv); + +int virStrToLong_i(char const *s, + char **end_ptr, + int base, + int *result); + +int virStrToLong_ui(char const *s, + char **end_ptr, + int base, + unsigned int *result); +int virStrToLong_l(char const *s, + char **end_ptr, + int base, + long *result); +int virStrToLong_ul(char const *s, + char **end_ptr, + int base, + unsigned long *result); +int virStrToLong_ll(char const *s, + char **end_ptr, + int base, + long long *result); +int virStrToLong_ull(char const *s, + char **end_ptr, + int base, + unsigned long long *result); +int virStrToDouble(char const *s, + char **end_ptr, + double *result); + +void virSkipSpaces(const char **str) ATTRIBUTE_NONNULL(1); +void virSkipSpacesAndBackslash(const char **str) ATTRIBUTE_NONNULL(1); +void virTrimSpaces(char *str, char **endp) ATTRIBUTE_NONNULL(1); +void virSkipSpacesBackwards(const char *str, char **endp) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); + +int virAsprintf(char **strp, const char *fmt, ...) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_FMT_PRINTF(2, 3) + ATTRIBUTE_RETURN_CHECK; +int virVasprintf(char **strp, const char *fmt, va_list list) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_FMT_PRINTF(2, 0) + ATTRIBUTE_RETURN_CHECK; +char *virStrncpy(char *dest, const char *src, size_t n, size_t destbytes) + ATTRIBUTE_RETURN_CHECK; +char *virStrcpy(char *dest, const char *src, size_t destbytes) + ATTRIBUTE_RETURN_CHECK; +# define virStrcpyStatic(dest, src) virStrcpy((dest), (src), sizeof(dest)) #endif /* __VIR_STRING_H__ */ diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c index ba0c245..2efe634 100644 --- a/src/util/virsysinfo.c +++ b/src/util/virsysinfo.c @@ -32,10 +32,10 @@ #include "virerror.h" #include "virsysinfo.h" -#include "virutil.h" #include "virlog.h" #include "viralloc.h" #include "vircommand.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_SYSINFO diff --git a/src/util/virtime.c b/src/util/virtime.c index b54a4e8..37c639c 100644 --- a/src/util/virtime.c +++ b/src/util/virtime.c @@ -37,7 +37,6 @@ #include <sys/time.h> #include "virtime.h" -#include "virutil.h" #include "viralloc.h" #include "virerror.h" diff --git a/src/util/virtpm.c b/src/util/virtpm.c index fbe5e9d..b5504b5 100644 --- a/src/util/virtpm.c +++ b/src/util/virtpm.c @@ -24,7 +24,7 @@ #include <sys/stat.h> -#include "virutil.h" +#include "virstring.h" #include "virerror.h" #include "virtpm.h" diff --git a/src/util/virtypedparam.c b/src/util/virtypedparam.c index c196321..a9f8a33 100644 --- a/src/util/virtypedparam.c +++ b/src/util/virtypedparam.c @@ -27,6 +27,7 @@ #include "viralloc.h" #include "virutil.h" #include "virerror.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_NONE diff --git a/src/util/viruri.c b/src/util/viruri.c index 2888cb0..2a75425 100644 --- a/src/util/viruri.c +++ b/src/util/viruri.c @@ -23,9 +23,9 @@ #include "viruri.h" #include "viralloc.h" -#include "virutil.h" #include "virerror.h" #include "virbuffer.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_URI diff --git a/src/util/virusb.c b/src/util/virusb.c index 6e43f8e..3192634 100644 --- a/src/util/virusb.c +++ b/src/util/virusb.c @@ -38,6 +38,7 @@ #include "viralloc.h" #include "virutil.h" #include "virerror.h" +#include "virstring.h" #define USB_SYSFS "/sys/bus/usb" #define USB_ID_LEN 10 /* "1234 5678" */ diff --git a/src/util/virutil.c b/src/util/virutil.c index b9de33c..dc14c15 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -29,7 +29,6 @@ #include <dirent.h> #include <stdio.h> #include <stdarg.h> -#include <stdlib.h> #include <unistd.h> #include <fcntl.h> #include <errno.h> @@ -80,7 +79,6 @@ #include "virerror.h" #include "virlog.h" #include "virbuffer.h" -#include "virutil.h" #include "virstoragefile.h" #include "viralloc.h" #include "virthread.h" @@ -90,6 +88,7 @@ #include "nonblocking.h" #include "passfd.h" #include "virprocess.h" +#include "virstring.h" #ifndef NSIG # define NSIG 32 @@ -240,32 +239,6 @@ int virFileStripSuffix(char *str, return 1; } -char * -virArgvToString(const char *const *argv) -{ - int len, i; - char *ret, *p; - - for (len = 1, i = 0; argv[i]; i++) - len += strlen(argv[i]) + 1; - - if (VIR_ALLOC_N(ret, len) < 0) - return NULL; - p = ret; - - for (i = 0; argv[i]; i++) { - if (i != 0) - *(p++) = ' '; - - strcpy(p, argv[i]); - p += strlen(argv[i]); - } - - *p = '\0'; - - return ret; -} - #ifndef WIN32 int virSetInherit(int fd, bool inherit) { @@ -1595,145 +1568,6 @@ virFileSanitizePath(const char *path) return cleanpath; } -/* Like strtol, but produce an "int" result, and check more carefully. - Return 0 upon success; return -1 to indicate failure. - When END_PTR is NULL, the byte after the final valid digit must be NUL. - Otherwise, it's like strtol and lets the caller check any suffix for - validity. This function is careful to return -1 when the string S - represents a number that is not representable as an "int". */ -int -virStrToLong_i(char const *s, char **end_ptr, int base, int *result) -{ - long int val; - char *p; - int err; - - errno = 0; - val = strtol(s, &p, base); /* exempt from syntax-check */ - err = (errno || (!end_ptr && *p) || p == s || (int) val != val); - if (end_ptr) - *end_ptr = p; - if (err) - return -1; - *result = val; - return 0; -} - -/* Just like virStrToLong_i, above, but produce an "unsigned int" value. */ -int -virStrToLong_ui(char const *s, char **end_ptr, int base, unsigned int *result) -{ - unsigned long int val; - char *p; - int err; - - errno = 0; - val = strtoul(s, &p, base); /* exempt from syntax-check */ - err = (errno || (!end_ptr && *p) || p == s || (unsigned int) val != val); - if (end_ptr) - *end_ptr = p; - if (err) - return -1; - *result = val; - return 0; -} - -/* Just like virStrToLong_i, above, but produce a "long" value. */ -int -virStrToLong_l(char const *s, char **end_ptr, int base, long *result) -{ - long int val; - char *p; - int err; - - errno = 0; - val = strtol(s, &p, base); /* exempt from syntax-check */ - err = (errno || (!end_ptr && *p) || p == s); - if (end_ptr) - *end_ptr = p; - if (err) - return -1; - *result = val; - return 0; -} - -/* Just like virStrToLong_i, above, but produce an "unsigned long" value. */ -int -virStrToLong_ul(char const *s, char **end_ptr, int base, unsigned long *result) -{ - unsigned long int val; - char *p; - int err; - - errno = 0; - val = strtoul(s, &p, base); /* exempt from syntax-check */ - err = (errno || (!end_ptr && *p) || p == s); - if (end_ptr) - *end_ptr = p; - if (err) - return -1; - *result = val; - return 0; -} - -/* Just like virStrToLong_i, above, but produce a "long long" value. */ -int -virStrToLong_ll(char const *s, char **end_ptr, int base, long long *result) -{ - long long val; - char *p; - int err; - - errno = 0; - val = strtoll(s, &p, base); /* exempt from syntax-check */ - err = (errno || (!end_ptr && *p) || p == s); - if (end_ptr) - *end_ptr = p; - if (err) - return -1; - *result = val; - return 0; -} - -/* Just like virStrToLong_i, above, but produce an "unsigned long long" value. */ -int -virStrToLong_ull(char const *s, char **end_ptr, int base, unsigned long long *result) -{ - unsigned long long val; - char *p; - int err; - - errno = 0; - val = strtoull(s, &p, base); /* exempt from syntax-check */ - err = (errno || (!end_ptr && *p) || p == s); - if (end_ptr) - *end_ptr = p; - if (err) - return -1; - *result = val; - return 0; -} - -int -virStrToDouble(char const *s, - char **end_ptr, - double *result) -{ - double val; - char *p; - int err; - - errno = 0; - val = strtod(s, &p); /* exempt from syntax-check */ - err = (errno || (!end_ptr && *p) || p == s); - if (end_ptr) - *end_ptr = p; - if (err) - return -1; - *result = val; - return 0; -} - /* Convert C from hexadecimal character to integer. */ int virHexToBin(unsigned char c) @@ -1819,95 +1653,6 @@ virScaleInteger(unsigned long long *value, const char *suffix, return 0; } -/** - * virSkipSpaces: - * @str: pointer to the char pointer used - * - * Skip potential blanks, this includes space tabs, line feed, - * carriage returns. - */ -void -virSkipSpaces(const char **str) -{ - const char *cur = *str; - - while (c_isspace(*cur)) - cur++; - *str = cur; -} - -/** - * virSkipSpacesAndBackslash: - * @str: pointer to the char pointer used - * - * Like virSkipSpaces, but also skip backslashes erroneously emitted - * by xend - */ -void -virSkipSpacesAndBackslash(const char **str) -{ - const char *cur = *str; - - while (c_isspace(*cur) || *cur == '\\') - cur++; - *str = cur; -} - -/** - * virTrimSpaces: - * @str: string to modify to remove all trailing spaces - * @endp: track the end of the string - * - * If @endp is NULL on entry, then all spaces prior to the trailing - * NUL in @str are removed, by writing NUL into the appropriate - * location. If @endp is non-NULL but points to a NULL pointer, - * then all spaces prior to the trailing NUL in @str are removed, - * NUL is written to the new string end, and endp is set to the - * location of the (new) string end. If @endp is non-NULL and - * points to a non-NULL pointer, then that pointer is used as - * the end of the string, endp is set to the (new) location, but - * no NUL pointer is written into the string. - */ -void -virTrimSpaces(char *str, char **endp) -{ - char *end; - - if (!endp || !*endp) - end = str + strlen(str); - else - end = *endp; - while (end > str && c_isspace(end[-1])) - end--; - if (endp) { - if (!*endp) - *end = '\0'; - *endp = end; - } else { - *end = '\0'; - } -} - -/** - * virSkipSpacesBackwards: - * @str: start of string - * @endp: on entry, *endp must be NULL or a location within @str, on exit, - * will be adjusted to skip trailing spaces, or to NULL if @str had nothing - * but spaces. - */ -void -virSkipSpacesBackwards(const char *str, char **endp) -{ - /* Casting away const is safe, since virTrimSpaces does not - * modify string with this particular usage. */ - char *s = (char*) str; - - if (!*endp) - *endp = s + strlen(s); - virTrimSpaces(s, endp); - if (s == *endp) - *endp = NULL; -} /** * virParseNumber: @@ -1940,7 +1685,6 @@ virParseNumber(const char **str) return ret; } - /** * virParseVersionString: * @str: const char pointer to the version string @@ -1987,82 +1731,6 @@ virParseVersionString(const char *str, unsigned long *version, return 0; } -/** - * virVasprintf - * - * like glibc's vasprintf but makes sure *strp == NULL on failure - */ -int -virVasprintf(char **strp, const char *fmt, va_list list) -{ - int ret; - - if ((ret = vasprintf(strp, fmt, list)) == -1) - *strp = NULL; - - return ret; -} - -/** - * virAsprintf - * - * like glibc's_asprintf but makes sure *strp == NULL on failure - */ -int -virAsprintf(char **strp, const char *fmt, ...) -{ - va_list ap; - int ret; - - va_start(ap, fmt); - ret = virVasprintf(strp, fmt, ap); - va_end(ap); - return ret; -} - -/** - * virStrncpy - * - * A safe version of strncpy. The last parameter is the number of bytes - * available in the destination string, *not* the number of bytes you want - * to copy. If the destination is not large enough to hold all n of the - * src string bytes plus a \0, NULL is returned and no data is copied. - * If the destination is large enough to hold the n bytes plus \0, then the - * string is copied and a pointer to the destination string is returned. - */ -char * -virStrncpy(char *dest, const char *src, size_t n, size_t destbytes) -{ - char *ret; - - if (n > (destbytes - 1)) - return NULL; - - ret = strncpy(dest, src, n); - /* strncpy NULL terminates iff the last character is \0. Therefore - * force the last byte to be \0 - */ - dest[n] = '\0'; - - return ret; -} - -/** - * virStrcpy - * - * A safe version of strcpy. The last parameter is the number of bytes - * available in the destination string, *not* the number of bytes you want - * to copy. If the destination is not large enough to hold all n of the - * src string bytes plus a \0, NULL is returned and no data is copied. - * If the destination is large enough to hold the source plus \0, then the - * string is copied and a pointer to the destination string is returned. - */ -char * -virStrcpy(char *dest, const char *src, size_t destbytes) -{ - return virStrncpy(dest, src, strlen(src), destbytes); -} - int virEnumFromString(const char *const*types, unsigned int ntypes, const char *type) diff --git a/src/util/virutil.h b/src/util/virutil.h index 39033db..8a2d25c 100644 --- a/src/util/virutil.h +++ b/src/util/virutil.h @@ -30,7 +30,6 @@ # include <unistd.h> # include <sys/select.h> # include <sys/types.h> -# include <stdarg.h> # ifndef MIN # define MIN(a, b) ((a) < (b) ? (a) : (b)) @@ -155,63 +154,15 @@ int virFileOpenTty(int *ttymaster, char **ttyName, int rawmode); -char *virArgvToString(const char *const *argv); - -int virStrToLong_i(char const *s, - char **end_ptr, - int base, - int *result); - -int virStrToLong_ui(char const *s, - char **end_ptr, - int base, - unsigned int *result); -int virStrToLong_l(char const *s, - char **end_ptr, - int base, - long *result); -int virStrToLong_ul(char const *s, - char **end_ptr, - int base, - unsigned long *result); -int virStrToLong_ll(char const *s, - char **end_ptr, - int base, - long long *result); -int virStrToLong_ull(char const *s, - char **end_ptr, - int base, - unsigned long long *result); -int virStrToDouble(char const *s, - char **end_ptr, - double *result); - int virScaleInteger(unsigned long long *value, const char *suffix, unsigned long long scale, unsigned long long limit) ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK; int virHexToBin(unsigned char c); -void virSkipSpaces(const char **str) ATTRIBUTE_NONNULL(1); -void virSkipSpacesAndBackslash(const char **str) ATTRIBUTE_NONNULL(1); -void virTrimSpaces(char *str, char **endp) ATTRIBUTE_NONNULL(1); -void virSkipSpacesBackwards(const char *str, char **endp) - ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); - int virParseNumber(const char **str); int virParseVersionString(const char *str, unsigned long *version, bool allowMissing); -int virAsprintf(char **strp, const char *fmt, ...) - ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_FMT_PRINTF(2, 3) - ATTRIBUTE_RETURN_CHECK; -int virVasprintf(char **strp, const char *fmt, va_list list) - ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_FMT_PRINTF(2, 0) - ATTRIBUTE_RETURN_CHECK; -char *virStrncpy(char *dest, const char *src, size_t n, size_t destbytes) - ATTRIBUTE_RETURN_CHECK; -char *virStrcpy(char *dest, const char *src, size_t destbytes) - ATTRIBUTE_RETURN_CHECK; -# define virStrcpyStatic(dest, src) virStrcpy((dest), (src), sizeof(dest)) int virDoubleToStr(char **strp, double number) ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK; diff --git a/src/util/virxml.c b/src/util/virxml.c index aa55a33..26120b6 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -36,6 +36,7 @@ #include "virutil.h" #include "viralloc.h" #include "virfile.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_XML diff --git a/src/vbox/vbox_MSCOMGlue.c b/src/vbox/vbox_MSCOMGlue.c index b5fb821..6cebfaf 100644 --- a/src/vbox/vbox_MSCOMGlue.c +++ b/src/vbox/vbox_MSCOMGlue.c @@ -31,7 +31,6 @@ #include "internal.h" #include "viralloc.h" -#include "virutil.h" #include "virlog.h" #include "virerror.h" #include "vbox_MSCOMGlue.h" diff --git a/src/vbox/vbox_XPCOMCGlue.c b/src/vbox/vbox_XPCOMCGlue.c index 2b568e2..e0b606f 100644 --- a/src/vbox/vbox_XPCOMCGlue.c +++ b/src/vbox/vbox_XPCOMCGlue.c @@ -41,6 +41,7 @@ #include "virutil.h" #include "virlog.h" #include "virerror.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_VBOX diff --git a/src/vbox/vbox_driver.c b/src/vbox/vbox_driver.c index dc1e8c3..30721fd 100644 --- a/src/vbox/vbox_driver.c +++ b/src/vbox/vbox_driver.c @@ -38,7 +38,6 @@ #include "vbox_driver.h" #include "vbox_glue.h" #include "virerror.h" -#include "virutil.h" #define VIR_FROM_THIS VIR_FROM_VBOX diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 315ba9c..43ddac8 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -57,6 +57,7 @@ #include "virfile.h" #include "fdstream.h" #include "viruri.h" +#include "virstring.h" /* This one changes from version to version. */ #if VBOX_API_VERSION == 2002 diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c index 573fb33..4fb61a8 100644 --- a/src/vmware/vmware_conf.c +++ b/src/vmware/vmware_conf.c @@ -32,8 +32,8 @@ #include "viruuid.h" #include "virerror.h" #include "vmx.h" - #include "vmware_conf.h" +#include "virstring.h" /* Free all memory associated with a vmware_driver structure */ void diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c index 00852be..1e2634e 100644 --- a/src/vmware/vmware_driver.c +++ b/src/vmware/vmware_driver.c @@ -28,7 +28,6 @@ #include "datatypes.h" #include "virfile.h" #include "viralloc.h" -#include "virutil.h" #include "viruuid.h" #include "vircommand.h" #include "vmx.h" diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index f520a85..c6c2f0d 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -33,6 +33,7 @@ #include "viruuid.h" #include "vmx.h" #include "viruri.h" +#include "virstring.h" /* diff --git a/src/xen/block_stats.c b/src/xen/block_stats.c index 9f5823c..8c18ed5 100644 --- a/src/xen/block_stats.c +++ b/src/xen/block_stats.c @@ -40,10 +40,10 @@ # include "virerror.h" # include "datatypes.h" -# include "virutil.h" # include "block_stats.h" # include "viralloc.h" # include "virfile.h" +# include "virstring.h" # define VIR_FROM_THIS VIR_FROM_STATS_LINUX diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c index 8971d4c..526786b 100644 --- a/src/xen/xen_driver.c +++ b/src/xen/xen_driver.c @@ -54,7 +54,6 @@ # include "xen_inotify.h" #endif #include "virxml.h" -#include "virutil.h" #include "viralloc.h" #include "node_device_conf.h" #include "virpci.h" @@ -66,6 +65,7 @@ #include "virnodesuspend.h" #include "nodeinfo.h" #include "configmake.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_XEN #define XEN_SAVE_DIR LOCALSTATEDIR "/lib/libvirt/xen/save" diff --git a/src/xen/xen_hypervisor.c b/src/xen/xen_hypervisor.c index 9dbbe07..e15f7f2 100644 --- a/src/xen/xen_hypervisor.c +++ b/src/xen/xen_hypervisor.c @@ -65,7 +65,6 @@ #include "virlog.h" #include "datatypes.h" #include "driver.h" -#include "virutil.h" #include "xen_driver.h" #include "xen_hypervisor.h" #include "xs_internal.h" @@ -80,6 +79,7 @@ #include "virnodesuspend.h" #include "virtypedparam.h" #include "virendian.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_XEN diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c index 860bf11..97f44ab 100644 --- a/src/xen/xend_internal.c +++ b/src/xen/xend_internal.c @@ -34,7 +34,6 @@ #include "datatypes.h" #include "xend_internal.h" #include "driver.h" -#include "virutil.h" #include "virsexpr.h" #include "xen_sxpr.h" #include "virbuffer.h" @@ -47,6 +46,7 @@ #include "virfile.h" #include "viruri.h" #include "device_conf.h" +#include "virstring.h" /* required for cpumap_t */ #include <xen/dom0_ops.h> diff --git a/src/xen/xm_internal.c b/src/xen/xm_internal.c index 8ac7cb0..921c66a 100644 --- a/src/xen/xm_internal.c +++ b/src/xen/xm_internal.c @@ -45,10 +45,10 @@ #include "virhash.h" #include "virbuffer.h" #include "viruuid.h" -#include "virutil.h" #include "viralloc.h" #include "virlog.h" #include "count-one-bits.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_XENXM diff --git a/src/xenapi/xenapi_driver.c b/src/xenapi/xenapi_driver.c index 1135c4e..7e64df6 100644 --- a/src/xenapi/xenapi_driver.c +++ b/src/xenapi/xenapi_driver.c @@ -31,7 +31,6 @@ #include "virerror.h" #include "datatypes.h" #include "virauth.h" -#include "virutil.h" #include "viruuid.h" #include "viralloc.h" #include "virbuffer.h" @@ -39,6 +38,7 @@ #include "xenapi_driver.h" #include "xenapi_driver_private.h" #include "xenapi_utils.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_XENAPI diff --git a/src/xenapi/xenapi_utils.c b/src/xenapi/xenapi_utils.c index 3b8384e..55fbb24 100644 --- a/src/xenapi/xenapi_utils.c +++ b/src/xenapi/xenapi_utils.c @@ -29,7 +29,6 @@ #include "domain_conf.h" #include "virerror.h" #include "datatypes.h" -#include "virutil.h" #include "viruuid.h" #include "viralloc.h" #include "virbuffer.h" @@ -37,6 +36,7 @@ #include "viruri.h" #include "xenapi_driver_private.h" #include "xenapi_utils.h" +#include "virstring.h" void xenSessionFree(xen_session *session) diff --git a/src/xenxs/xen_sxpr.c b/src/xenxs/xen_sxpr.c index 76e57ee..9a76d04 100644 --- a/src/xenxs/xen_sxpr.c +++ b/src/xenxs/xen_sxpr.c @@ -37,6 +37,7 @@ #include "xenxs_private.h" #include "xen_sxpr.h" #include "virstoragefile.h" +#include "virstring.h" /* Get a domain id from a S-expression string */ int xenGetDomIdFromSxprString(const char *sexpr, int xendConfigVersion) diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index 275e6ed..57ce2e7 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -38,6 +38,7 @@ #include "xen_sxpr.h" #include "domain_conf.h" #include "virstoragefile.h" +#include "virstring.h" /* Convenience method to grab a long int from the config file object */ static int xenXMConfigGetBool(virConfPtr conf, diff --git a/tests/commandtest.c b/tests/commandtest.c index ac369f9..6cb88c5 100644 --- a/tests/commandtest.c +++ b/tests/commandtest.c @@ -31,13 +31,13 @@ #include "testutils.h" #include "internal.h" #include "nodeinfo.h" -#include "virutil.h" #include "viralloc.h" #include "vircommand.h" #include "virfile.h" #include "virpidfile.h" #include "virerror.h" #include "virthread.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_NONE diff --git a/tests/cputest.c b/tests/cputest.c index ab96824..0105440 100644 --- a/tests/cputest.c +++ b/tests/cputest.c @@ -38,6 +38,7 @@ #include "cpu_conf.h" #include "cpu/cpu.h" #include "cpu/cpu_map.h" +#include "virstring.h" static const char *abs_top_srcdir; diff --git a/tests/domainsnapshotxml2xmltest.c b/tests/domainsnapshotxml2xmltest.c index 694c382..9eddf45 100644 --- a/tests/domainsnapshotxml2xmltest.c +++ b/tests/domainsnapshotxml2xmltest.c @@ -16,6 +16,7 @@ # include "qemu/qemu_conf.h" # include "qemu/qemu_domain.h" # include "testutilsqemu.h" +# include "virstring.h" static virQEMUDriver driver; diff --git a/tests/esxutilstest.c b/tests/esxutilstest.c index e2baea2..bb58a3a 100644 --- a/tests/esxutilstest.c +++ b/tests/esxutilstest.c @@ -10,7 +10,6 @@ # include "internal.h" # include "viralloc.h" -# include "virutil.h" # include "vmx/vmx.h" # include "esx/esx_util.h" # include "esx/esx_vi_types.h" diff --git a/tests/interfacexml2xmltest.c b/tests/interfacexml2xmltest.c index f969fa1..9d86198 100644 --- a/tests/interfacexml2xmltest.c +++ b/tests/interfacexml2xmltest.c @@ -12,7 +12,7 @@ #include "testutils.h" #include "interface_conf.h" #include "testutilsqemu.h" - +#include "virstring.h" static int testCompareXMLToXMLFiles(const char *xml) diff --git a/tests/libvirtdconftest.c b/tests/libvirtdconftest.c index 01e9415..df8d3d8 100644 --- a/tests/libvirtdconftest.c +++ b/tests/libvirtdconftest.c @@ -29,6 +29,7 @@ #include "virerror.h" #include "virlog.h" #include "virconf.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_NONE diff --git a/tests/lxcxml2xmltest.c b/tests/lxcxml2xmltest.c index 4870f42..827c2fd 100644 --- a/tests/lxcxml2xmltest.c +++ b/tests/lxcxml2xmltest.c @@ -15,6 +15,7 @@ # include "internal.h" # include "lxc/lxc_conf.h" # include "testutilslxc.h" +# include "virstring.h" static virCapsPtr caps; static virDomainXMLOptionPtr xmlopt; diff --git a/tests/networkxml2conftest.c b/tests/networkxml2conftest.c index 88016ee..520feba 100644 --- a/tests/networkxml2conftest.c +++ b/tests/networkxml2conftest.c @@ -14,6 +14,7 @@ #include "vircommand.h" #include "viralloc.h" #include "network/bridge_driver.h" +#include "virstring.h" static int testCompareXMLToConfFiles(const char *inxml, const char *outconf, dnsmasqCapsPtr caps) diff --git a/tests/networkxml2xmltest.c b/tests/networkxml2xmltest.c index 1063435..5eca143 100644 --- a/tests/networkxml2xmltest.c +++ b/tests/networkxml2xmltest.c @@ -12,6 +12,7 @@ #include "testutils.h" #include "network_conf.h" #include "testutilsqemu.h" +#include "virstring.h" static int testCompareXMLToXMLFiles(const char *inxml, const char *outxml, diff --git a/tests/nodedevxml2xmltest.c b/tests/nodedevxml2xmltest.c index 38f2e9a..e81c617 100644 --- a/tests/nodedevxml2xmltest.c +++ b/tests/nodedevxml2xmltest.c @@ -12,6 +12,7 @@ #include "testutils.h" #include "node_device_conf.h" #include "testutilsqemu.h" +#include "virstring.h" static int testCompareXMLToXMLFiles(const char *xml) diff --git a/tests/nodeinfotest.c b/tests/nodeinfotest.c index d900eb9..733d350 100644 --- a/tests/nodeinfotest.c +++ b/tests/nodeinfotest.c @@ -8,8 +8,8 @@ #include "testutils.h" #include "internal.h" #include "nodeinfo.h" -#include "virutil.h" #include "virfile.h" +#include "virstring.h" #if ! (defined __linux__ && (defined(__x86_64__) || \ defined(__amd64__) || \ diff --git a/tests/nwfilterxml2xmltest.c b/tests/nwfilterxml2xmltest.c index a215bf8..158bc9f 100644 --- a/tests/nwfilterxml2xmltest.c +++ b/tests/nwfilterxml2xmltest.c @@ -15,6 +15,7 @@ #include "nwfilter_params.h" #include "nwfilter_conf.h" #include "testutilsqemu.h" +#include "virstring.h" static int testCompareXMLToXMLFiles(const char *inxml, const char *outxml, diff --git a/tests/openvzutilstest.c b/tests/openvzutilstest.c index 616b6be..be0c74c 100644 --- a/tests/openvzutilstest.c +++ b/tests/openvzutilstest.c @@ -10,8 +10,8 @@ # include "internal.h" # include "viralloc.h" -# include "virutil.h" # include "openvz/openvz_conf.h" +# include "virstring.h" static int testLocateConfFile(int vpsid ATTRIBUTE_UNUSED, char **conffile, diff --git a/tests/qemuargv2xmltest.c b/tests/qemuargv2xmltest.c index 9f1bb24..005aa0c 100644 --- a/tests/qemuargv2xmltest.c +++ b/tests/qemuargv2xmltest.c @@ -14,8 +14,8 @@ # include "internal.h" # include "qemu/qemu_command.h" - # include "testutilsqemu.h" +# include "virstring.h" static virQEMUDriver driver; diff --git a/tests/qemuhelptest.c b/tests/qemuhelptest.c index eeba4d4..fa56406 100644 --- a/tests/qemuhelptest.c +++ b/tests/qemuhelptest.c @@ -9,6 +9,7 @@ # include "qemu/qemu_capabilities.h" # include "viralloc.h" +# include "virstring.h" struct testInfo { const char *name; diff --git a/tests/qemumonitortest.c b/tests/qemumonitortest.c index a8fc57a..61ac2d6 100644 --- a/tests/qemumonitortest.c +++ b/tests/qemumonitortest.c @@ -11,7 +11,6 @@ # include "internal.h" # include "viralloc.h" -# include "virutil.h" # include "qemu/qemu_monitor.h" struct testEscapeString diff --git a/tests/qemumonitortestutils.c b/tests/qemumonitortestutils.c index 43e7cb9..c24a37f 100644 --- a/tests/qemumonitortestutils.c +++ b/tests/qemumonitortestutils.c @@ -30,9 +30,9 @@ #include "qemu/qemu_monitor.h" #include "rpc/virnetsocket.h" #include "viralloc.h" -#include "virutil.h" #include "virlog.h" #include "virerror.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_NONE diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 9699f77..1286273 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -19,6 +19,7 @@ # include "qemu/qemu_domain.h" # include "datatypes.h" # include "cpu/cpu_map.h" +# include "virstring.h" # include "testutilsqemu.h" diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index a81cfcf..64c1c83 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -16,6 +16,7 @@ # include "qemu/qemu_conf.h" # include "qemu/qemu_domain.h" # include "testutilsqemu.h" +# include "virstring.h" static virQEMUDriver driver; diff --git a/tests/qemuxmlnstest.c b/tests/qemuxmlnstest.c index 4e9144b..cd493e3 100644 --- a/tests/qemuxmlnstest.c +++ b/tests/qemuxmlnstest.c @@ -18,8 +18,8 @@ # include "qemu/qemu_domain.h" # include "datatypes.h" # include "cpu/cpu_map.h" - # include "testutilsqemu.h" +# include "virstring.h" static const char *abs_top_srcdir; static virQEMUDriver driver; diff --git a/tests/securityselinuxlabeltest.c b/tests/securityselinuxlabeltest.c index f585f6f..e270a76 100644 --- a/tests/securityselinuxlabeltest.c +++ b/tests/securityselinuxlabeltest.c @@ -37,9 +37,8 @@ #include "virerror.h" #include "virfile.h" #include "virlog.h" -#include "virutil.h" #include "security/security_manager.h" - +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_NONE diff --git a/tests/securityselinuxtest.c b/tests/securityselinuxtest.c index da8a12f..dd4cd11 100644 --- a/tests/securityselinuxtest.c +++ b/tests/securityselinuxtest.c @@ -31,11 +31,10 @@ #include "internal.h" #include "testutils.h" #include "viralloc.h" -#include "virutil.h" #include "virlog.h" #include "virerror.h" #include "security/security_manager.h" - +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_NONE diff --git a/tests/sexpr2xmltest.c b/tests/sexpr2xmltest.c index b7487ef..f4d119e 100644 --- a/tests/sexpr2xmltest.c +++ b/tests/sexpr2xmltest.c @@ -12,6 +12,7 @@ #include "xenxs/xen_sxpr.h" #include "testutils.h" #include "testutilsxen.h" +#include "virstring.h" static virCapsPtr caps; diff --git a/tests/storagepoolxml2xmltest.c b/tests/storagepoolxml2xmltest.c index 9be63c5..0376e63 100644 --- a/tests/storagepoolxml2xmltest.c +++ b/tests/storagepoolxml2xmltest.c @@ -12,6 +12,7 @@ #include "testutils.h" #include "storage_conf.h" #include "testutilsqemu.h" +#include "virstring.h" static int testCompareXMLToXMLFiles(const char *inxml, const char *outxml) diff --git a/tests/storagevolxml2argvtest.c b/tests/storagevolxml2argvtest.c index 77ba800..e1507b4 100644 --- a/tests/storagevolxml2argvtest.c +++ b/tests/storagevolxml2argvtest.c @@ -5,6 +5,7 @@ #include "datatypes.h" #include "storage/storage_backend.h" #include "testutilsqemu.h" +#include "virstring.h" const char create_tool[] = "qemu-img"; diff --git a/tests/storagevolxml2xmltest.c b/tests/storagevolxml2xmltest.c index 0902496..07c79c1 100644 --- a/tests/storagevolxml2xmltest.c +++ b/tests/storagevolxml2xmltest.c @@ -12,6 +12,7 @@ #include "testutils.h" #include "storage_conf.h" #include "testutilsqemu.h" +#include "virstring.h" static int testCompareXMLToXMLFiles(const char *poolxml, const char *inxml, diff --git a/tests/sysinfotest.c b/tests/sysinfotest.c index 8955208..dc0451b 100644 --- a/tests/sysinfotest.c +++ b/tests/sysinfotest.c @@ -33,8 +33,8 @@ #include "virbuffer.h" #include "virsysinfo.h" #include "testutils.h" -#include "virutil.h" #include "virfile.h" +#include "virstring.h" #if defined (__linux__) diff --git a/tests/testutils.c b/tests/testutils.c index 0fb69ec..b0806de 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -45,6 +45,7 @@ #include "virrandom.h" #include "dirname.h" #include "virprocess.h" +#include "virstring.h" #if TEST_OOM_TRACE # include <execinfo.h> diff --git a/tests/virauthconfigtest.c b/tests/virauthconfigtest.c index 67c5de8..a27bae5 100644 --- a/tests/virauthconfigtest.c +++ b/tests/virauthconfigtest.c @@ -24,7 +24,6 @@ #include <signal.h> #include "testutils.h" -#include "virutil.h" #include "virerror.h" #include "viralloc.h" #include "virlog.h" diff --git a/tests/virbuftest.c b/tests/virbuftest.c index 7f9ee66..c7a504b 100644 --- a/tests/virbuftest.c +++ b/tests/virbuftest.c @@ -5,10 +5,10 @@ #include <string.h> #include "internal.h" -#include "virutil.h" #include "testutils.h" #include "virbuffer.h" #include "viralloc.h" +#include "virstring.h" #define TEST_ERROR(...) \ do { \ diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c index e2adef8..4777fae 100644 --- a/tests/vircgrouptest.c +++ b/tests/vircgrouptest.c @@ -28,7 +28,7 @@ # define __VIR_CGROUP_ALLOW_INCLUDE_PRIV_H__ # include "vircgrouppriv.h" -# include "virutil.h" +# include "virstring.h" # include "virerror.h" # include "virlog.h" # include "virfile.h" diff --git a/tests/virdrivermoduletest.c b/tests/virdrivermoduletest.c index bbceb96..1aae245 100644 --- a/tests/virdrivermoduletest.c +++ b/tests/virdrivermoduletest.c @@ -21,7 +21,6 @@ #include <config.h> #include "testutils.h" -#include "virutil.h" #include "virerror.h" #include "viralloc.h" #include "virlog.h" diff --git a/tests/virhashtest.c b/tests/virhashtest.c index 6e4f267..f36fc76 100644 --- a/tests/virhashtest.c +++ b/tests/virhashtest.c @@ -10,9 +10,8 @@ #include "virhashdata.h" #include "testutils.h" #include "viralloc.h" -#include "virutil.h" #include "virlog.h" - +#include "virstring.h" #define testError(...) \ do { \ diff --git a/tests/viridentitytest.c b/tests/viridentitytest.c index e898795..269a57d 100644 --- a/tests/viridentitytest.c +++ b/tests/viridentitytest.c @@ -25,7 +25,6 @@ #include "testutils.h" #include "viridentity.h" -#include "virutil.h" #include "virerror.h" #include "viralloc.h" #include "virlog.h" diff --git a/tests/virkeyfiletest.c b/tests/virkeyfiletest.c index fb41840..8fe7e38 100644 --- a/tests/virkeyfiletest.c +++ b/tests/virkeyfiletest.c @@ -24,7 +24,6 @@ #include <signal.h> #include "testutils.h" -#include "virutil.h" #include "virerror.h" #include "viralloc.h" #include "virlog.h" diff --git a/tests/virnetmessagetest.c b/tests/virnetmessagetest.c index e58fd1f..96defe4 100644 --- a/tests/virnetmessagetest.c +++ b/tests/virnetmessagetest.c @@ -24,7 +24,6 @@ #include <signal.h> #include "testutils.h" -#include "virutil.h" #include "virerror.h" #include "viralloc.h" #include "virlog.h" diff --git a/tests/virnetsockettest.c b/tests/virnetsockettest.c index aaa6acb..5e2925d 100644 --- a/tests/virnetsockettest.c +++ b/tests/virnetsockettest.c @@ -33,6 +33,7 @@ #include "viralloc.h" #include "virlog.h" #include "virfile.h" +#include "virstring.h" #include "rpc/virnetsocket.h" diff --git a/tests/virportallocatortest.c b/tests/virportallocatortest.c index 1935602..a528506 100644 --- a/tests/virportallocatortest.c +++ b/tests/virportallocatortest.c @@ -54,8 +54,8 @@ int bind(int sockfd ATTRIBUTE_UNUSED, # include "virerror.h" # include "viralloc.h" # include "virlog.h" - # include "virportallocator.h" +# include "virstring.h" # define VIR_FROM_THIS VIR_FROM_RPC diff --git a/tests/virshtest.c b/tests/virshtest.c index b82a4c4..fad6774 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -6,8 +6,8 @@ #include "internal.h" #include "virxml.h" -#include "virutil.h" #include "testutils.h" +#include "virstring.h" #ifdef WIN32 diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c index 0e6ba9e..0016052 100644 --- a/tests/virstoragetest.c +++ b/tests/virstoragetest.c @@ -27,6 +27,7 @@ #include "virerror.h" #include "virlog.h" #include "virstoragefile.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_NONE diff --git a/tests/virstringtest.c b/tests/virstringtest.c index 86d8986..db1e8a9 100644 --- a/tests/virstringtest.c +++ b/tests/virstringtest.c @@ -23,7 +23,6 @@ #include <stdlib.h> #include "testutils.h" -#include "virutil.h" #include "virerror.h" #include "viralloc.h" #include "virlog.h" diff --git a/tests/virtimetest.c b/tests/virtimetest.c index 18f621a..7768ecb 100644 --- a/tests/virtimetest.c +++ b/tests/virtimetest.c @@ -24,7 +24,6 @@ #include <signal.h> #include "testutils.h" -#include "virutil.h" #include "virerror.h" #include "viralloc.h" #include "virlog.h" diff --git a/tests/viruritest.c b/tests/viruritest.c index 3cb88da..0bcd78d 100644 --- a/tests/viruritest.c +++ b/tests/viruritest.c @@ -24,7 +24,6 @@ #include <signal.h> #include "testutils.h" -#include "virutil.h" #include "virerror.h" #include "viralloc.h" #include "virlog.h" diff --git a/tests/vmx2xmltest.c b/tests/vmx2xmltest.c index 0003f5f..bd7cbc6 100644 --- a/tests/vmx2xmltest.c +++ b/tests/vmx2xmltest.c @@ -11,6 +11,7 @@ # include "internal.h" # include "viralloc.h" # include "vmx/vmx.h" +# include "virstring.h" static virCapsPtr caps; static virDomainXMLOptionPtr xmlopt; diff --git a/tests/xencapstest.c b/tests/xencapstest.c index 381802e..e220234 100644 --- a/tests/xencapstest.c +++ b/tests/xencapstest.c @@ -10,6 +10,7 @@ #include "testutils.h" #include "xen/xen_hypervisor.h" #include "virfile.h" +#include "virstring.h" static int testCompareFiles(virArch hostmachine, const char *xml_rel, diff --git a/tests/xmconfigtest.c b/tests/xmconfigtest.c index b7ff48c..8e0c59e 100644 --- a/tests/xmconfigtest.c +++ b/tests/xmconfigtest.c @@ -35,6 +35,7 @@ #include "testutils.h" #include "testutilsxen.h" #include "viralloc.h" +#include "virstring.h" static virCapsPtr caps; static virDomainXMLOptionPtr xmlopt; diff --git a/tests/xml2sexprtest.c b/tests/xml2sexprtest.c index 062ff07..ec196c4 100644 --- a/tests/xml2sexprtest.c +++ b/tests/xml2sexprtest.c @@ -14,6 +14,7 @@ #include "xenxs/xen_sxpr.h" #include "testutils.h" #include "testutilsxen.h" +#include "virstring.h" static virCapsPtr caps; static virDomainXMLOptionPtr xmlopt; diff --git a/tests/xml2vmxtest.c b/tests/xml2vmxtest.c index fa4f6f9..38b5a4d 100644 --- a/tests/xml2vmxtest.c +++ b/tests/xml2vmxtest.c @@ -11,6 +11,7 @@ # include "internal.h" # include "viralloc.h" # include "vmx/vmx.h" +# include "virstring.h" static virCapsPtr caps; static virVMXContext ctx; diff --git a/tools/console.c b/tools/console.c index e423134..9abfb58 100644 --- a/tools/console.c +++ b/tools/console.c @@ -39,7 +39,6 @@ # include "internal.h" # include "console.h" # include "virlog.h" -# include "virutil.h" # include "virfile.h" # include "viralloc.h" # include "virthread.h" diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index f7297f5..5ed89d1 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -38,6 +38,7 @@ #include "virmacaddr.h" #include "virsh-domain.h" #include "virxml.h" +#include "virstring.h" static const char * vshDomainIOErrorToString(int error) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 5c8bcba..9ac9bd1 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -44,7 +44,6 @@ #include "console.h" #include "viralloc.h" #include "vircommand.h" -#include "virutil.h" #include "virfile.h" #include "virjson.h" #include "virkeycode.h" diff --git a/tools/virsh-host.c b/tools/virsh-host.c index a7e31da..a75d844 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -34,10 +34,10 @@ #include "internal.h" #include "virbuffer.h" #include "viralloc.h" -#include "virutil.h" #include "virsh-domain.h" #include "virxml.h" #include "virtypedparam.h" +#include "virstring.h" /* * "capabilities" command diff --git a/tools/virsh-interface.c b/tools/virsh-interface.c index c022e1d..706074f 100644 --- a/tools/virsh-interface.c +++ b/tools/virsh-interface.c @@ -36,6 +36,7 @@ #include "viralloc.h" #include "virutil.h" #include "virxml.h" +#include "virstring.h" virInterfacePtr vshCommandOptInterfaceBy(vshControl *ctl, const vshCmd *cmd, diff --git a/tools/virsh-network.c b/tools/virsh-network.c index bc1a64a..81267bc 100644 --- a/tools/virsh-network.c +++ b/tools/virsh-network.c @@ -34,7 +34,6 @@ #include "internal.h" #include "virbuffer.h" #include "viralloc.h" -#include "virutil.h" #include "virxml.h" #include "conf/network_conf.h" diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index c196e7a..8fa67fc 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -34,7 +34,6 @@ #include "internal.h" #include "virbuffer.h" #include "viralloc.h" -#include "virutil.h" #include "virxml.h" #include "conf/node_device_conf.h" diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c index c1e91ea..f154366 100644 --- a/tools/virsh-pool.c +++ b/tools/virsh-pool.c @@ -34,9 +34,9 @@ #include "internal.h" #include "virbuffer.h" #include "viralloc.h" -#include "virutil.h" #include "virxml.h" #include "conf/storage_conf.h" +#include "virstring.h" virStoragePoolPtr vshCommandOptPoolBy(vshControl *ctl, const vshCmd *cmd, const char *optname, diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c index 44a1e03..4f5fa15 100644 --- a/tools/virsh-snapshot.c +++ b/tools/virsh-snapshot.c @@ -36,7 +36,6 @@ #include "internal.h" #include "virbuffer.h" #include "viralloc.h" -#include "virutil.h" #include "virsh-domain.h" #include "virxml.h" #include "conf/snapshot_conf.h" diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c index 0ca295f..0aaa21e 100644 --- a/tools/virsh-volume.c +++ b/tools/virsh-volume.c @@ -40,6 +40,7 @@ #include "virfile.h" #include "virsh-pool.h" #include "virxml.h" +#include "virstring.h" virStorageVolPtr vshCommandOptVolBy(vshControl *ctl, const vshCmd *cmd, diff --git a/tools/virsh.c b/tools/virsh.c index 6ec2f7b..de2e57a 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -57,7 +57,6 @@ #include "base64.h" #include "virbuffer.h" #include "console.h" -#include "virutil.h" #include "viralloc.h" #include "virxml.h" #include <libvirt/libvirt-qemu.h> @@ -71,6 +70,7 @@ #include "virbitmap.h" #include "conf/domain_conf.h" #include "virtypedparam.h" +#include "virstring.h" #include "virsh-domain.h" #include "virsh-domain-monitor.h" diff --git a/tools/virt-host-validate-common.c b/tools/virt-host-validate-common.c index 34a527f..c17c257 100644 --- a/tools/virt-host-validate-common.c +++ b/tools/virt-host-validate-common.c @@ -31,6 +31,7 @@ #include "viralloc.h" #include "virfile.h" #include "virt-host-validate-common.h" +#include "virstring.h" static bool quiet; -- 1.8.1.5

On 04/29/2013 07:50 AM, Michal Privoznik wrote:
The source code base needs to be adapted as well. Some files include virutil.h just for the string related functions (here, the include is substituted to match the new file), some include virutil.h without any need (here, the include is removed), and some require both. --- cfg.mk | 4 +-
src/util/virstoragefile.c | 2 + src/util/virstring.c | 335 ++++++++++++++++++++++++++++++ src/util/virstring.h | 50 +++++ src/util/virsysinfo.c | 2 +- src/util/virtime.c | 1 - src/util/virtpm.c | 2 +- src/util/virtypedparam.c | 1 + src/util/viruri.c | 2 +- src/util/virusb.c | 1 + src/util/virutil.c | 334 +----------------------------
Hmm, I guess git rename detection only kicks in for entire files, not for big chunks of code motion between existing files.
242 files changed, 590 insertions(+), 557 deletions(-)
Growth is explainable by the number of new #include needed, I hope. The fact that things still compile is good; I'm not reviewing too closely, as the compiler should catch whether the motion was accurate. I'm guessing you just removed #include "virutil.h" everywhere, then compiled and fixed compiler errors for missing usage, until you had the correct set of includes added back in?
+++ b/src/libvirt_private.syms @@ -1745,10 +1745,26 @@ virStorageFileResize;
# util/virstring.h +virArgvToString; +virAsprintf; +virSkipSpaces; +virSkipSpacesAndBackslash; +virSkipSpacesBackwards; +virStrcpy; virStringArrayHasString; virStringFreeList; virStringJoin; virStringSplit; +virStrncpy; +virStrToDouble; +virStrToLong_i; +virStrToLong_l; +virStrToLong_ll; +virStrToLong_ui; +virStrToLong_ul; +virStrToLong_ull; +virTrimSpaces; +virVasprintf;
Looks like a reasonable set to be moved.
+++ b/src/util/virstring.c @@ -21,6 +21,10 @@
#include <config.h>
+#include <stdlib.h> +#include <stdio.h> + +#include "c-ctype.h" #include "virstring.h" #include "viralloc.h" #include "virbuffer.h" @@ -180,3 +184,334 @@ virStringArrayHasString(char **strings, const char *needle)
return false; } + +/* Like strtol, but produce an "int" result, and check more carefully. + Return 0 upon success; return -1 to indicate failure. + When END_PTR is NULL, the byte after the final valid digit must be NUL. + Otherwise, it's like strtol and lets the caller check any suffix for + validity. This function is careful to return -1 when the string S + represents a number that is not representable as an "int". */ +int +virStrToLong_i(char const *s, char **end_ptr, int base, int *result) +{ + long int val; + char *p; + int err; + + errno = 0; + val = strtol(s, &p, base); /* exempt from syntax-check */ + err = (errno || (!end_ptr && *p) || p == s || (int) val != val); + if (end_ptr) + *end_ptr = p; + if (err) + return -1; + *result = val; + return 0; +}
I did a spot check that this function did straight code motion; I'm assuming that for all the others, you did likewise.
+++ b/src/util/virutil.c
-/* Like strtol, but produce an "int" result, and check more carefully. - Return 0 upon success; return -1 to indicate failure. - When END_PTR is NULL, the byte after the final valid digit must be NUL. - Otherwise, it's like strtol and lets the caller check any suffix for - validity. This function is careful to return -1 when the string S - represents a number that is not representable as an "int". */ -int -virStrToLong_i(char const *s, char **end_ptr, int base, int *result) -{ - long int val; - char *p; - int err; - - errno = 0; - val = strtol(s, &p, base); /* exempt from syntax-check */ - err = (errno || (!end_ptr && *p) || p == s || (int) val != val); - if (end_ptr) - *end_ptr = p; - if (err) - return -1; - *result = val; - return 0; -}
ACK. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

The code adaptation is not done right now, but in subsequent patches. Hence I am not implementing syntax-check rule as it would break compilation. Developers are strongly advised to use these new macros. They are similar to VIR_ALLOC() logic: VIR_STRDUP(dst, src) returns zero on success, -1 otherwise. In case you don't want to report OOM error, use _QUIET variant of a macro. --- HACKING | 11 +++++++ docs/hacking.html.in | 14 +++++++++ src/libvirt_private.syms | 2 ++ src/util/virstring.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++ src/util/virstring.h | 20 +++++++++++++ 5 files changed, 121 insertions(+) diff --git a/HACKING b/HACKING index e8bebd4..842f476 100644 --- a/HACKING +++ b/HACKING @@ -719,6 +719,17 @@ sizeof(dest) returns something meaningful). Note that this is a macro, so arguments could be evaluated more than once. This is equivalent to virStrncpy(dest, src, strlen(src), sizeof(dest)). + VIR_STRDUP(char *dst, const char *src); + VIR_STRNDUP(char *dst, const char *src, size_t n); + +You should avoid using strdup or strndup directly as the does not report +out-of-memory error. Use VIR_STRDUP() or VIR_STRNDUP macros instead. Note, +that these two behave in similar way to VIR_ALLOC: on success zero is +returned, otherwise caller is left with negative one. In very specific case, +when you don't want to report the out-of-memory error, you can use +VIR_STRDUP_QUIET or VIR_STRNDUP_QUIET, but such usage is very rare and usually +considered a flaw. + Variable length string buffer ============================= diff --git a/docs/hacking.html.in b/docs/hacking.html.in index 99933d1..1263607 100644 --- a/docs/hacking.html.in +++ b/docs/hacking.html.in @@ -853,6 +853,20 @@ virStrncpy(dest, src, strlen(src), sizeof(dest)). </p> +<pre> + VIR_STRDUP(char *dst, const char *src); + VIR_STRNDUP(char *dst, const char *src, size_t n); +</pre> + <p> + You should avoid using strdup or strndup directly as the does not report + out-of-memory error. Use VIR_STRDUP() or VIR_STRNDUP macros instead. + Note, that these two behave in similar way to VIR_ALLOC: on success zero + is returned, otherwise caller is left with negative one. In very specific + case, when you don't want to report the out-of-memory error, you can use + VIR_STRDUP_QUIET or VIR_STRNDUP_QUIET, but such usage is very rare and + usually considered a flaw. + </p> + <h2><a name="strbuf">Variable length string buffer</a></h2> <p> diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 98660dc..d4cb4a3 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1751,11 +1751,13 @@ virSkipSpaces; virSkipSpacesAndBackslash; virSkipSpacesBackwards; virStrcpy; +virStrdup; virStringArrayHasString; virStringFreeList; virStringJoin; virStringSplit; virStrncpy; +virStrndup; virStrToDouble; virStrToLong_i; virStrToLong_l; diff --git a/src/util/virstring.c b/src/util/virstring.c index 9b4cb01..4a55873 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -515,3 +515,77 @@ virArgvToString(const char *const *argv) return ret; } + +/** + * virStrdup: + * @dest: where to store duplicated string + * @src: the source string to duplicate + * @report: whether to report OOM error, if there's a one + * @domcode: error domain code + * @filename: caller's filename + * @funcname: caller's funcname + * @linenr: caller's line number + * + * Wrapper over strdup, which reports OOM error if told so, + * in which case callers wants to pass @domcode, @filename, + * @funcname and @linenr which should represent location in + * caller's body where virStrdup is called from. Consider + * using VIR_STRDUP which sets these automatically. + * + * Returns: 0 on success, -1 othervise. + */ +int +virStrdup(char **dest, + const char *src, + bool report, + int domcode, + const char *filename, + const char *funcname, + size_t linenr) +{ + if (!(*dest = strdup(src))) { + if (report) + virReportOOMErrorFull(domcode, filename, funcname, linenr); + return -1; + } + + return 0; +} + +/** + * virStrndup: + * @dest: where to store duplicated string + * @src: the source string to duplicate + * @n: how many bytes to copy + * @report: whether to report OOM error, if there's a one + * @domcode: error domain code + * @filename: caller's filename + * @funcname: caller's funcname + * @linenr: caller's line number + * + * Wrapper over strndup, which reports OOM error if told so, + * in which case callers wants to pass @domcode, @filename, + * @funcname and @linenr which should represent location in + * caller's body where virStrdup is called from. Consider + * using VIR_STRNDUP which sets these automatically. + * + * Returns: 0 on success, -1 othervise. + */ +int +virStrndup(char **dest, + const char *src, + size_t n, + bool report, + int domcode, + const char *filename, + const char *funcname, + size_t linenr) +{ + if (!(*dest = strndup(src, n))) { + if (report) + virReportOOMErrorFull(domcode, filename, funcname, linenr); + return -1; + } + + return 0; +} diff --git a/src/util/virstring.h b/src/util/virstring.h index 457caa2..620efba 100644 --- a/src/util/virstring.h +++ b/src/util/virstring.h @@ -87,4 +87,24 @@ char *virStrncpy(char *dest, const char *src, size_t n, size_t destbytes) char *virStrcpy(char *dest, const char *src, size_t destbytes) ATTRIBUTE_RETURN_CHECK; # define virStrcpyStatic(dest, src) virStrcpy((dest), (src), sizeof(dest)) + +int virStrdup(char **dest, const char *src, bool report, int domcode, + const char *filename, const char *funcname, size_t linenr) + ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); + +/* XXX Don't report OOM error for now, unless all code is adapted. */ +# define VIR_STRDUP(dst, src) virStrdup(&(dst), src, false, VIR_FROM_THIS, \ + __FILE__, __FUNCTION__, __LINE__) +# define VIR_STRDUP_QUIET(dst, src) virStrdup(&(dst), src, false, 0, NULL, NULL, 0) +int virStrndup(char **dest, const char *src, size_t n, bool report, int domcode, + const char *filename, const char *funcname, size_t linenr) + ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); + +/* XXX Don't report OOM error for now, unless all code is adapted. */ +# define VIR_STRNDUP(dst, src, n) virStrndup(&(dst), src, n, false, \ + VIR_FROM_THIS, __FILE__, \ + __FUNCTION__, __LINE__) + +# define VIR_STRNDUP_QUIET(dst, src, n) virStrndup(&(dst), src, n, false, \ + 0, NULL, NULL, 0) #endif /* __VIR_STRING_H__ */ -- 1.8.1.5

On 04/29/2013 07:50 AM, Michal Privoznik wrote: s/STRUP/STRDUP/ in the subject line.
The code adaptation is not done right now, but in subsequent patches. Hence I am not implementing syntax-check rule as it would break compilation. Developers are strongly advised to use these new macros. They are similar to VIR_ALLOC() logic: VIR_STRDUP(dst, src) returns zero on success, -1 otherwise. In case you don't want to report OOM error, use _QUIET variant of a macro.
s/use/use the/ Thinking about backportability - it looks like Fedora 19 will probably be based on libvirt 1.0.5 + patches. I'm hoping that if we backport this patch, but not the syntax check or the general cleanups of using VIR_STRDUP everywhere, then further backports of any new code that uses VIR_STRDUP can be done by using this interface, and any merge conflicts of code that used to use strdup should be fairly easy to resolve during the backport process (of course, the IDEAL situation is that 1.0.5 doesn't have any bugs that require backporting across this refactoring, right? :)
+++ b/docs/hacking.html.in @@ -853,6 +853,20 @@ virStrncpy(dest, src, strlen(src), sizeof(dest)). </p>
+<pre> + VIR_STRDUP(char *dst, const char *src); + VIR_STRNDUP(char *dst, const char *src, size_t n); +</pre> + <p> + You should avoid using strdup or strndup directly as the does not report
s/the does/they do/
+ out-of-memory error. Use VIR_STRDUP() or VIR_STRNDUP macros instead. + Note, that these two behave in similar way to VIR_ALLOC: on success zero
s/in similar way/similar/
+ is returned, otherwise caller is left with negative one. In very specific
s/caller is left with negative one/the result is -1 and dst is guaranteed to be NULL/
+ case, when you don't want to report the out-of-memory error, you can use
s/case/cases/
+ VIR_STRDUP_QUIET or VIR_STRNDUP_QUIET, but such usage is very rare and + usually considered a flaw. + </p> + <h2><a name="strbuf">Variable length string buffer</a></h2>
+++ b/src/util/virstring.c @@ -515,3 +515,77 @@ virArgvToString(const char *const *argv)
return ret; } + +/** + * virStrdup: + * @dest: where to store duplicated string + * @src: the source string to duplicate + * @report: whether to report OOM error, if there's a one
s/there's a/there is/
+ * @domcode: error domain code + * @filename: caller's filename + * @funcname: caller's funcname + * @linenr: caller's line number + * + * Wrapper over strdup, which reports OOM error if told so, + * in which case callers wants to pass @domcode, @filename, + * @funcname and @linenr which should represent location in + * caller's body where virStrdup is called from. Consider + * using VIR_STRDUP which sets these automatically. + * + * Returns: 0 on success, -1 othervise.
s/othervise/otherwise/
+ */ +int +virStrdup(char **dest, + const char *src, + bool report, + int domcode, + const char *filename, + const char *funcname, + size_t linenr) +{ + if (!(*dest = strdup(src))) { + if (report) + virReportOOMErrorFull(domcode, filename, funcname, linenr); + return -1; + } + + return 0; +} + +/** + * virStrndup: + * @dest: where to store duplicated string + * @src: the source string to duplicate + * @n: how many bytes to copy + * @report: whether to report OOM error, if there's a one
s/there's a/there is/
+ * @domcode: error domain code + * @filename: caller's filename + * @funcname: caller's funcname + * @linenr: caller's line number + * + * Wrapper over strndup, which reports OOM error if told so, + * in which case callers wants to pass @domcode, @filename, + * @funcname and @linenr which should represent location in + * caller's body where virStrdup is called from. Consider
s/virStrdup/virStrndup/
+ * using VIR_STRNDUP which sets these automatically. + * + * Returns: 0 on success, -1 othervise.
s/othervise/otherwise/
+ */ +int +virStrndup(char **dest, + const char *src, + size_t n, + bool report, + int domcode, + const char *filename, + const char *funcname, + size_t linenr) +{ + if (!(*dest = strndup(src, n))) { + if (report) + virReportOOMErrorFull(domcode, filename, funcname, linenr); + return -1; + } + + return 0; +}
Implementation of the helper functions looks correct.
diff --git a/src/util/virstring.h b/src/util/virstring.h index 457caa2..620efba 100644 --- a/src/util/virstring.h +++ b/src/util/virstring.h @@ -87,4 +87,24 @@ char *virStrncpy(char *dest, const char *src, size_t n, size_t destbytes) char *virStrcpy(char *dest, const char *src, size_t destbytes) ATTRIBUTE_RETURN_CHECK; # define virStrcpyStatic(dest, src) virStrcpy((dest), (src), sizeof(dest)) + +int virStrdup(char **dest, const char *src, bool report, int domcode, + const char *filename, const char *funcname, size_t linenr) + ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); + +/* XXX Don't report OOM error for now, unless all code is adapted. */
I disagree. Since the calling convention changed, anywhere that we use VIR_STRDUP should already be dealing with the new semantics of expecting VIR_STRDUP to report the error. Passing false only made sense if you were trying to make VIR_STRDUP a drop-in replacement for strdup (where you could save work by doing a global search-and-replace for the drop-in, then revisit code later for the new semantics). But since you already have to revisit semantics for this macro, you might as well assume OOM reporting from the beginning, by...
+# define VIR_STRDUP(dst, src) virStrdup(&(dst), src, false, VIR_FROM_THIS, \ + __FILE__, __FUNCTION__, __LINE__)
...doing s/false/true/
+# define VIR_STRDUP_QUIET(dst, src) virStrdup(&(dst), src, false, 0, NULL, NULL, 0) +int virStrndup(char **dest, const char *src, size_t n, bool report, int domcode, + const char *filename, const char *funcname, size_t linenr) + ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
It is hard to read function and macro declarations intermixed like this. I would much rather see this done like viralloc.h, by separating the function declarations up front (and with a BIG disclaimer that most code should not use it directly), then the macros down below, and with full documentation of the macros (since their arguments are slightly different than the arguments of the functions).
+ +/* XXX Don't report OOM error for now, unless all code is adapted. */ +# define VIR_STRNDUP(dst, src, n) virStrndup(&(dst), src, n, false, \ + VIR_FROM_THIS, __FILE__, \ + __FUNCTION__, __LINE__)
Again, s/false/true/ since you are already changing calling conventions on anywhere converted to use this macro.
+ +# define VIR_STRNDUP_QUIET(dst, src, n) virStrndup(&(dst), src, n, false, \ + 0, NULL, NULL, 0) #endif /* __VIR_STRING_H__ */
Getting closer. Looking forward to v3. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

--- daemon/libvirtd-config.c | 37 ++++++++++--------- daemon/libvirtd.c | 17 +++++---- daemon/remote.c | 94 ++++++++++++++++++++---------------------------- 3 files changed, 66 insertions(+), 82 deletions(-) diff --git a/daemon/libvirtd-config.c b/daemon/libvirtd-config.c index efb564e..df2bc7b 100644 --- a/daemon/libvirtd-config.c +++ b/daemon/libvirtd-config.c @@ -59,15 +59,14 @@ remoteConfigGetStringList(virConfPtr conf, const char *key, char ***list_arg, key); return -1; } - list[0] = strdup(p->str); - list[1] = NULL; - if (list[0] == NULL) { + if (VIR_STRDUP(list[0], p->str) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("failed to allocate memory for %s config list value"), key); VIR_FREE(list); return -1; } + list[1] = NULL; break; case VIR_CONF_LIST: { @@ -90,8 +89,7 @@ remoteConfigGetStringList(virConfPtr conf, const char *key, char ***list_arg, VIR_FREE(list); return -1; } - list[i] = strdup(pp->str); - if (list[i] == NULL) { + if (VIR_STRDUP(list[i], pp->str) < 0) { int j; for (j = 0 ; j < i ; j++) VIR_FREE(list[j]); @@ -136,8 +134,8 @@ checkType(virConfValuePtr p, const char *filename, } /* If there is no config data for the key, #var_name, then do nothing. - If there is valid data of type VIR_CONF_STRING, and strdup succeeds, - store the result in var_name. Otherwise, (i.e. invalid type, or strdup + If there is valid data of type VIR_CONF_STRING, and VIR_STRDUP succeeds, + store the result in var_name. Otherwise, (i.e. invalid type, or VIR_STRDUP failure), give a diagnostic and "goto" the cleanup-and-fail label. */ #define GET_CONF_STR(conf, filename, var_name) \ do { \ @@ -146,7 +144,7 @@ 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 = strdup(p->str))) { \ + if (VIR_STRDUP(data->var_name, p->str) < 0) { \ virReportOOMError(); \ goto error; \ } \ @@ -200,7 +198,7 @@ int daemonConfigFilePath(bool privileged, char **configfile) { if (privileged) { - if (!(*configfile = strdup(SYSCONFDIR "/libvirt/libvirtd.conf"))) + if (VIR_STRDUP(*configfile, SYSCONFDIR "/libvirt/libvirtd.conf") < 0) goto no_memory; } else { char *configdir = NULL; @@ -238,9 +236,9 @@ daemonConfigNew(bool privileged ATTRIBUTE_UNUSED) data->listen_tls = 1; data->listen_tcp = 0; - if (!(data->tls_port = strdup(LIBVIRTD_TLS_PORT))) + if (VIR_STRDUP(data->tls_port, LIBVIRTD_TLS_PORT) < 0) goto no_memory; - if (!(data->tcp_port = strdup(LIBVIRTD_TCP_PORT))) + if (VIR_STRDUP(data->tcp_port, LIBVIRTD_TCP_PORT) < 0) goto no_memory; /* Only default to PolicyKit if running as root */ @@ -256,13 +254,14 @@ daemonConfigNew(bool privileged ATTRIBUTE_UNUSED) } #endif - if (data->auth_unix_rw == REMOTE_AUTH_POLKIT) - data->unix_sock_rw_perms = strdup("0777"); /* Allow world */ - else - data->unix_sock_rw_perms = strdup("0700"); /* Allow user only */ - data->unix_sock_ro_perms = strdup("0777"); /* Always allow world */ - if (!data->unix_sock_ro_perms || - !data->unix_sock_rw_perms) + if (data->auth_unix_rw == REMOTE_AUTH_POLKIT) { + if (VIR_STRDUP(data->unix_sock_rw_perms, "0777") < 0) + goto no_memory; + } else { + if (VIR_STRDUP(data->unix_sock_rw_perms, "0700") < 0) + goto no_memory; + } + if (VIR_STRDUP(data->unix_sock_ro_perms, "0777") < 0) goto no_memory; #if WITH_SASL @@ -382,7 +381,7 @@ 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 = strdup("0777"))) { + if (VIR_STRDUP(data->unix_sock_rw_perms, "0777") < 0) { virReportOOMError(); goto error; } diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c index 9f81a0f..07c064d 100644 --- a/daemon/libvirtd.c +++ b/daemon/libvirtd.c @@ -241,7 +241,7 @@ daemonPidFilePath(bool privileged, char **pidfile) { if (privileged) { - if (!(*pidfile = strdup(LOCALSTATEDIR "/run/libvirtd.pid"))) + if (VIR_STRDUP(*pidfile, LOCALSTATEDIR "/run/libvirtd.pid") < 0) goto no_memory; } else { char *rundir = NULL; @@ -287,9 +287,9 @@ daemonUnixSocketPaths(struct daemonConfig *config, goto no_memory; } else { if (privileged) { - if (!(*sockfile = strdup(LOCALSTATEDIR "/run/libvirt/libvirt-sock"))) + if (VIR_STRDUP(*sockfile, LOCALSTATEDIR "/run/libvirt/libvirt-sock") < 0) goto no_memory; - if (!(*rosockfile = strdup(LOCALSTATEDIR "/run/libvirt/libvirt-sock-ro"))) + if (VIR_STRDUP(*rosockfile, LOCALSTATEDIR "/run/libvirt/libvirt-sock-ro") < 0) goto no_memory; } else { char *rundir = NULL; @@ -961,7 +961,10 @@ static int migrateProfile(void) config_home = getenv("XDG_CONFIG_HOME"); if (config_home && config_home[0] != '\0') { - xdg_dir = strdup(config_home); + if (VIR_STRDUP(xdg_dir, config_home) < 0) { + virReportOOMError(); + goto cleanup; + } } else { if (virAsprintf(&xdg_dir, "%s/.config", home) < 0) { goto cleanup; @@ -1172,7 +1175,7 @@ int main(int argc, char **argv) { case 'p': VIR_FREE(pid_file); - if (!(pid_file = strdup(optarg))) { + if (VIR_STRDUP(pid_file, optarg) < 0) { VIR_ERROR(_("Can't allocate memory")); exit(EXIT_FAILURE); } @@ -1180,7 +1183,7 @@ int main(int argc, char **argv) { case 'f': VIR_FREE(remote_config_file); - if (!(remote_config_file = strdup(optarg))) { + if (VIR_STRDUP(remote_config_file, optarg) < 0) { VIR_ERROR(_("Can't allocate memory")); exit(EXIT_FAILURE); } @@ -1287,7 +1290,7 @@ int main(int argc, char **argv) { /* Ensure the rundir exists (on tmpfs on some systems) */ if (privileged) { - run_dir = strdup(LOCALSTATEDIR "/run/libvirt"); + ignore_value(VIR_STRDUP(run_dir, LOCALSTATEDIR "/run/libvirt")); } else { run_dir = virGetUserRuntimeDirectory(); diff --git a/daemon/remote.c b/daemon/remote.c index 8c79680..fa8dedd 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -234,11 +234,9 @@ static int remoteRelayDomainEventIOError(virConnectPtr conn ATTRIBUTE_UNUSED, /* build return data */ memset(&data, 0, sizeof(data)); - data.srcPath = strdup(srcPath); - if (data.srcPath == NULL) + if (VIR_STRDUP(data.srcPath, srcPath) < 0) goto mem_error; - data.devAlias = strdup(devAlias); - if (data.devAlias == NULL) + if (VIR_STRDUP(data.devAlias, devAlias) < 0) goto mem_error; make_nonnull_domain(&data.dom, dom); data.action = action; @@ -275,15 +273,12 @@ static int remoteRelayDomainEventIOErrorReason(virConnectPtr conn ATTRIBUTE_UNUS /* build return data */ memset(&data, 0, sizeof(data)); - data.srcPath = strdup(srcPath); - if (data.srcPath == NULL) + if (VIR_STRDUP(data.srcPath, srcPath) < 0) goto mem_error; - data.devAlias = strdup(devAlias); - if (data.devAlias == NULL) + if (VIR_STRDUP(data.devAlias, devAlias) < 0) goto mem_error; data.action = action; - data.reason = strdup(reason); - if (data.reason == NULL) + if (VIR_STRDUP(data.reason, reason) < 0) goto mem_error; make_nonnull_domain(&data.dom, dom); @@ -334,22 +329,17 @@ static int remoteRelayDomainEventGraphics(virConnectPtr conn ATTRIBUTE_UNUSED, data.phase = phase; data.local.family = local->family; data.remote.family = remote->family; - data.authScheme = strdup(authScheme); - if (data.authScheme == NULL) + if (VIR_STRDUP(data.authScheme, authScheme) < 0) goto mem_error; - data.local.node = strdup(local->node); - if (data.local.node == NULL) + if (VIR_STRDUP(data.local.node, local->node) < 0) goto mem_error; - data.local.service = strdup(local->service); - if (data.local.service == NULL) + if (VIR_STRDUP(data.local.service, local->service) < 0) goto mem_error; - data.remote.node = strdup(remote->node); - if (data.remote.node == NULL) + if (VIR_STRDUP(data.remote.node, remote->node) < 0) goto mem_error; - data.remote.service = strdup(remote->service); - if (data.remote.service == NULL) + if (VIR_STRDUP(data.remote.service, remote->service) < 0) goto mem_error; data.subject.subject_len = subject->nidentity; @@ -357,11 +347,9 @@ static int remoteRelayDomainEventGraphics(virConnectPtr conn ATTRIBUTE_UNUSED, goto mem_error; for (i = 0 ; i < data.subject.subject_len ; i++) { - data.subject.subject_val[i].type = strdup(subject->identities[i].type); - if (data.subject.subject_val[i].type == NULL) + if (VIR_STRDUP(data.subject.subject_val[i].type, subject->identities[i].type) < 0) goto mem_error; - data.subject.subject_val[i].name = strdup(subject->identities[i].name); - if (data.subject.subject_val[i].name == NULL) + if (VIR_STRDUP(data.subject.subject_val[i].name, subject->identities[i].name) < 0) goto mem_error; } make_nonnull_domain(&data.dom, dom); @@ -407,8 +395,7 @@ static int remoteRelayDomainEventBlockJob(virConnectPtr conn ATTRIBUTE_UNUSED, /* build return data */ memset(&data, 0, sizeof(data)); - data.path = strdup(path); - if (data.path == NULL) + if (VIR_STRDUP(data.path, path) < 0) goto mem_error; data.type = type; data.status = status; @@ -473,17 +460,17 @@ static int remoteRelayDomainEventDiskChange(virConnectPtr conn ATTRIBUTE_UNUSED, memset(&data, 0, sizeof(data)); if (oldSrcPath && ((VIR_ALLOC(oldSrcPath_p) < 0) || - !(*oldSrcPath_p = strdup(oldSrcPath)))) + VIR_STRDUP(*oldSrcPath_p, oldSrcPath) < 0)) goto mem_error; if (newSrcPath && ((VIR_ALLOC(newSrcPath_p) < 0) || - !(*newSrcPath_p = strdup(newSrcPath)))) + VIR_STRDUP(*newSrcPath_p, newSrcPath) < 0)) goto mem_error; data.oldSrcPath = oldSrcPath_p; data.newSrcPath = newSrcPath_p; - if (!(data.devAlias = strdup(devAlias))) + if (VIR_STRDUP(data.devAlias, devAlias) < 0) goto mem_error; data.reason = reason; @@ -520,7 +507,7 @@ static int remoteRelayDomainEventTrayChange(virConnectPtr conn ATTRIBUTE_UNUSED, /* build return data */ memset(&data, 0, sizeof(data)); - if (!(data.devAlias = strdup(devAlias))) { + if (VIR_STRDUP(data.devAlias, devAlias) < 0) { virReportOOMError(); return -1; } @@ -850,8 +837,7 @@ remoteSerializeTypedParameters(virTypedParameterPtr params, } /* remoteDispatchClientRequest will free this: */ - val[j].field = strdup(params[i].field); - if (val[j].field == NULL) { + if (VIR_STRDUP(val[j].field, params[i].field) < 0) { virReportOOMError(); goto cleanup; } @@ -876,9 +862,8 @@ remoteSerializeTypedParameters(virTypedParameterPtr params, val[j].value.remote_typed_param_value_u.b = params[i].value.b; break; case VIR_TYPED_PARAM_STRING: - val[j].value.remote_typed_param_value_u.s = - strdup(params[i].value.s); - if (val[j].value.remote_typed_param_value_u.s == NULL) { + if (VIR_STRDUP(val[j].value.remote_typed_param_value_u.s, + params[i].value.s) < 0) { virReportOOMError(); goto cleanup; } @@ -966,9 +951,8 @@ remoteDeserializeTypedParameters(remote_typed_param *args_params_val, args_params_val[i].value.remote_typed_param_value_u.b; break; case VIR_TYPED_PARAM_STRING: - params[i].value.s = - strdup(args_params_val[i].value.remote_typed_param_value_u.s); - if (params[i].value.s == NULL) { + if (VIR_STRDUP(params[i].value.s, + args_params_val[i].value.remote_typed_param_value_u.s) < 0) { virReportOOMError(); goto cleanup; } @@ -2145,8 +2129,7 @@ remoteDispatchNodeGetCPUStats(virNetServerPtr server ATTRIBUTE_UNUSED, for (i = 0; i < nparams; ++i) { /* remoteDispatchClientRequest will free this: */ - ret->params.params_val[i].field = strdup(params[i].field); - if (ret->params.params_val[i].field == NULL) + if (VIR_STRDUP(ret->params.params_val[i].field, params[i].field) < 0) goto no_memory; ret->params.params_val[i].value = params[i].value; @@ -2223,8 +2206,7 @@ remoteDispatchNodeGetMemoryStats(virNetServerPtr server ATTRIBUTE_UNUSED, for (i = 0; i < nparams; ++i) { /* remoteDispatchClientRequest will free this: */ - ret->params.params_val[i].field = strdup(params[i].field); - if (ret->params.params_val[i].field == NULL) + if (VIR_STRDUP(ret->params.params_val[i].field, params[i].field) < 0) goto no_memory; ret->params.params_val[i].value = params[i].value; @@ -3100,7 +3082,7 @@ remoteDispatchNodeDeviceGetParent(virNetServerPtr server ATTRIBUTE_UNUSED, virReportOOMError(); goto cleanup; } - if (!(*parent_p = strdup(parent))) { + if (VIR_STRDUP(*parent_p, parent) < 0) { VIR_FREE(parent_p); virReportOOMError(); goto cleanup; @@ -4769,14 +4751,14 @@ static void make_nonnull_domain(remote_nonnull_domain *dom_dst, virDomainPtr dom_src) { dom_dst->id = dom_src->id; - dom_dst->name = strdup(dom_src->name); + ignore_value(VIR_STRDUP_QUIET(dom_dst->name , dom_src->name)); memcpy(dom_dst->uuid, dom_src->uuid, VIR_UUID_BUFLEN); } static void make_nonnull_network(remote_nonnull_network *net_dst, virNetworkPtr net_src) { - net_dst->name = strdup(net_src->name); + ignore_value(VIR_STRDUP_QUIET(net_dst->name, net_src->name)); memcpy(net_dst->uuid, net_src->uuid, VIR_UUID_BUFLEN); } @@ -4784,29 +4766,29 @@ static void make_nonnull_interface(remote_nonnull_interface *interface_dst, virInterfacePtr interface_src) { - interface_dst->name = strdup(interface_src->name); - interface_dst->mac = strdup(interface_src->mac); + ignore_value(VIR_STRDUP_QUIET(interface_dst->name, interface_src->name)); + ignore_value(VIR_STRDUP_QUIET(interface_dst->mac, interface_src->mac)); } static void make_nonnull_storage_pool(remote_nonnull_storage_pool *pool_dst, virStoragePoolPtr pool_src) { - pool_dst->name = strdup(pool_src->name); + ignore_value(VIR_STRDUP_QUIET(pool_dst->name, pool_src->name)); memcpy(pool_dst->uuid, pool_src->uuid, VIR_UUID_BUFLEN); } static void make_nonnull_storage_vol(remote_nonnull_storage_vol *vol_dst, virStorageVolPtr vol_src) { - vol_dst->pool = strdup(vol_src->pool); - vol_dst->name = strdup(vol_src->name); - vol_dst->key = strdup(vol_src->key); + ignore_value(VIR_STRDUP_QUIET(vol_dst->pool, vol_src->pool)); + ignore_value(VIR_STRDUP_QUIET(vol_dst->name, vol_src->name)); + ignore_value(VIR_STRDUP_QUIET(vol_dst->key, vol_src->key)); } static void make_nonnull_node_device(remote_nonnull_node_device *dev_dst, virNodeDevicePtr dev_src) { - dev_dst->name = strdup(dev_src->name); + ignore_value(VIR_STRDUP_QUIET(dev_dst->name, dev_src->name)); } static void @@ -4814,20 +4796,20 @@ make_nonnull_secret(remote_nonnull_secret *secret_dst, virSecretPtr secret_src) { memcpy(secret_dst->uuid, secret_src->uuid, VIR_UUID_BUFLEN); secret_dst->usageType = secret_src->usageType; - secret_dst->usageID = strdup(secret_src->usageID); + ignore_value(VIR_STRDUP_QUIET(secret_dst->usageID, secret_src->usageID)); } static void make_nonnull_nwfilter(remote_nonnull_nwfilter *nwfilter_dst, virNWFilterPtr nwfilter_src) { - nwfilter_dst->name = strdup(nwfilter_src->name); + ignore_value(VIR_STRDUP_QUIET(nwfilter_dst->name, nwfilter_src->name)); memcpy(nwfilter_dst->uuid, nwfilter_src->uuid, VIR_UUID_BUFLEN); } static void make_nonnull_domain_snapshot(remote_nonnull_domain_snapshot *snapshot_dst, virDomainSnapshotPtr snapshot_src) { - snapshot_dst->name = strdup(snapshot_src->name); + ignore_value(VIR_STRDUP_QUIET(snapshot_dst->name, snapshot_src->name)); make_nonnull_domain(&snapshot_dst->dom, snapshot_src->domain); } @@ -4844,7 +4826,7 @@ remoteSerializeDomainDiskErrors(virDomainDiskErrorPtr errors, goto no_memory; for (i = 0; i < nerrors; i++) { - if (!(val[i].disk = strdup(errors[i].disk))) + if (VIR_STRDUP(val[i].disk, errors[i].disk) < 0) goto no_memory; val[i].error = errors[i].error; } -- 1.8.1.5

On 04/29/2013 07:50 AM, Michal Privoznik wrote:
--- daemon/libvirtd-config.c | 37 ++++++++++--------- daemon/libvirtd.c | 17 +++++---- daemon/remote.c | 94 ++++++++++++++++++++---------------------------- 3 files changed, 66 insertions(+), 82 deletions(-)
diff --git a/daemon/libvirtd-config.c b/daemon/libvirtd-config.c index efb564e..df2bc7b 100644 --- a/daemon/libvirtd-config.c +++ b/daemon/libvirtd-config.c @@ -59,15 +59,14 @@ remoteConfigGetStringList(virConfPtr conf, const char *key, char ***list_arg, key); return -1; } - list[0] = strdup(p->str); - list[1] = NULL; - if (list[0] == NULL) { + if (VIR_STRDUP(list[0], p->str) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("failed to allocate memory for %s config list value"), key);
We should just nuke this error, and let VIR_STRDUP's OOM error suffice. This whole function could probably use a cleanup pass to use virReportOOMError() as appropriate.
VIR_FREE(list); return -1; } + list[1] = NULL; break;
case VIR_CONF_LIST: { @@ -90,8 +89,7 @@ remoteConfigGetStringList(virConfPtr conf, const char *key, char ***list_arg, VIR_FREE(list); return -1; } - list[i] = strdup(pp->str); - if (list[i] == NULL) { + if (VIR_STRDUP(list[i], pp->str) < 0) { int j; for (j = 0 ; j < i ; j++) VIR_FREE(list[j]);
Yep, here's another case where we should nuke the virReportError(VIR_ERR_CONFIG_UNSUPPORTED) and rely on VIR_STRDUP's OOM error instead.
@@ -136,8 +134,8 @@ checkType(virConfValuePtr p, const char *filename, }
/* If there is no config data for the key, #var_name, then do nothing. - If there is valid data of type VIR_CONF_STRING, and strdup succeeds, - store the result in var_name. Otherwise, (i.e. invalid type, or strdup + If there is valid data of type VIR_CONF_STRING, and VIR_STRDUP succeeds, + store the result in var_name. Otherwise, (i.e. invalid type, or VIR_STRDUP failure), give a diagnostic and "goto" the cleanup-and-fail label. */ #define GET_CONF_STR(conf, filename, var_name) \ do { \ @@ -146,7 +144,7 @@ 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 = strdup(p->str))) { \ + if (VIR_STRDUP(data->var_name, p->str) < 0) { \ virReportOOMError(); \
Drop the virReportOOMError here; since VIR_STRDUP is documented to do the work for you.
goto error; \ } \ @@ -200,7 +198,7 @@ int daemonConfigFilePath(bool privileged, char **configfile) { if (privileged) { - if (!(*configfile = strdup(SYSCONFDIR "/libvirt/libvirtd.conf"))) + if (VIR_STRDUP(*configfile, SYSCONFDIR "/libvirt/libvirtd.conf") < 0) goto no_memory;
You can drop the no_memory label and just use the error label.
} else { char *configdir = NULL; @@ -238,9 +236,9 @@ daemonConfigNew(bool privileged ATTRIBUTE_UNUSED) data->listen_tls = 1; data->listen_tcp = 0;
- if (!(data->tls_port = strdup(LIBVIRTD_TLS_PORT))) + if (VIR_STRDUP(data->tls_port, LIBVIRTD_TLS_PORT) < 0) goto no_memory; - if (!(data->tcp_port = strdup(LIBVIRTD_TCP_PORT))) + if (VIR_STRDUP(data->tcp_port, LIBVIRTD_TCP_PORT) < 0) goto no_memory;
Hmm. Here, the no_memory label does additional cleanup...
/* Only default to PolicyKit if running as root */ @@ -256,13 +254,14 @@ daemonConfigNew(bool privileged ATTRIBUTE_UNUSED) } #endif
- if (data->auth_unix_rw == REMOTE_AUTH_POLKIT) - data->unix_sock_rw_perms = strdup("0777"); /* Allow world */ - else - data->unix_sock_rw_perms = strdup("0700"); /* Allow user only */ - data->unix_sock_ro_perms = strdup("0777"); /* Always allow world */ - if (!data->unix_sock_ro_perms || - !data->unix_sock_rw_perms) + if (data->auth_unix_rw == REMOTE_AUTH_POLKIT) { + if (VIR_STRDUP(data->unix_sock_rw_perms, "0777") < 0) + goto no_memory; + } else { + if (VIR_STRDUP(data->unix_sock_rw_perms, "0700") < 0) + goto no_memory; + } + if (VIR_STRDUP(data->unix_sock_ro_perms, "0777") < 0) goto no_memory;
...and one of the paths into the no_memory label is via virAsprintf(), which has not yet been converted to report OOM. So for this function, you'll need to add a label (and later delete no_memory when we do a second pass over the code to scrub virAsprintf usage): no_memory: virReportOOMError(); cleanup: daemonConfigFree(data); return NULL;
#if WITH_SASL @@ -382,7 +381,7 @@ 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 = strdup("0777"))) { + if (VIR_STRDUP(data->unix_sock_rw_perms, "0777") < 0) { virReportOOMError();
Drop the duplicate error.
goto error; } diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c index 9f81a0f..07c064d 100644 --- a/daemon/libvirtd.c +++ b/daemon/libvirtd.c @@ -241,7 +241,7 @@ daemonPidFilePath(bool privileged, char **pidfile) { if (privileged) { - if (!(*pidfile = strdup(LOCALSTATEDIR "/run/libvirtd.pid"))) + if (VIR_STRDUP(*pidfile, LOCALSTATEDIR "/run/libvirtd.pid") < 0) goto no_memory;
Change to goto error.
} else { char *rundir = NULL; @@ -287,9 +287,9 @@ daemonUnixSocketPaths(struct daemonConfig *config, goto no_memory; } else { if (privileged) { - if (!(*sockfile = strdup(LOCALSTATEDIR "/run/libvirt/libvirt-sock"))) + if (VIR_STRDUP(*sockfile, LOCALSTATEDIR "/run/libvirt/libvirt-sock") < 0) goto no_memory; - if (!(*rosockfile = strdup(LOCALSTATEDIR "/run/libvirt/libvirt-sock-ro"))) + if (VIR_STRDUP(*rosockfile, LOCALSTATEDIR "/run/libvirt/libvirt-sock-ro") < 0) goto no_memory;
Change both to goto error
} else { char *rundir = NULL; @@ -961,7 +961,10 @@ static int migrateProfile(void)
config_home = getenv("XDG_CONFIG_HOME"); if (config_home && config_home[0] != '\0') { - xdg_dir = strdup(config_home); + if (VIR_STRDUP(xdg_dir, config_home) < 0) { + virReportOOMError();
Don't report the error twice.
+ goto cleanup; + } } else { if (virAsprintf(&xdg_dir, "%s/.config", home) < 0) { goto cleanup; @@ -1172,7 +1175,7 @@ int main(int argc, char **argv) {
case 'p': VIR_FREE(pid_file); - if (!(pid_file = strdup(optarg))) { + if (VIR_STRDUP(pid_file, optarg) < 0) { VIR_ERROR(_("Can't allocate memory"));
_This_ instance might need to use VIR_STRDUP_QUIET and keep the VIR_ERROR() report; main() is early enough that virReportOOMError() might not go anywhere useful. Probably will never be triggered in practice, though, so I'd also be okay with regular VIR_STRDUP and dropping the VIR_ERROR.
exit(EXIT_FAILURE); } @@ -1180,7 +1183,7 @@ int main(int argc, char **argv) {
case 'f': VIR_FREE(remote_config_file); - if (!(remote_config_file = strdup(optarg))) { + if (VIR_STRDUP(remote_config_file, optarg) < 0) { VIR_ERROR(_("Can't allocate memory"));
Same story.
exit(EXIT_FAILURE); } @@ -1287,7 +1290,7 @@ int main(int argc, char **argv) {
/* Ensure the rundir exists (on tmpfs on some systems) */ if (privileged) { - run_dir = strdup(LOCALSTATEDIR "/run/libvirt"); + ignore_value(VIR_STRDUP(run_dir, LOCALSTATEDIR "/run/libvirt"));
Here, I'd hoist the OOM error that occurs several lines later into this if branch (since it can't be reached on the else branch) rather than using ignore_value just to then check for NULL ourselves a few lines later. Which turns this into: if (privileged) { if (VIR_STRDUP(run_dir, LOCALSTATEDIR "/run/libvirt") < 0) goto cleanup; } else { run_dir = virGetUserRuntimeDirectory();
} else { run_dir = virGetUserRuntimeDirectory();
diff --git a/daemon/remote.c b/daemon/remote.c index 8c79680..fa8dedd 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -234,11 +234,9 @@ static int remoteRelayDomainEventIOError(virConnectPtr conn ATTRIBUTE_UNUSED,
/* build return data */ memset(&data, 0, sizeof(data)); - data.srcPath = strdup(srcPath); - if (data.srcPath == NULL) + if (VIR_STRDUP(data.srcPath, srcPath) < 0) goto mem_error;
Drop the virReportOOMError() from mem_error(); at which point the label should be renamed to plain 'error'.
- data.devAlias = strdup(devAlias); - if (data.devAlias == NULL) + if (VIR_STRDUP(data.devAlias, devAlias) < 0) goto mem_error; make_nonnull_domain(&data.dom, dom); data.action = action; @@ -275,15 +273,12 @@ static int remoteRelayDomainEventIOErrorReason(virConnectPtr conn ATTRIBUTE_UNUS
/* build return data */ memset(&data, 0, sizeof(data)); - data.srcPath = strdup(srcPath); - if (data.srcPath == NULL) + if (VIR_STRDUP(data.srcPath, srcPath) < 0) goto mem_error; - data.devAlias = strdup(devAlias); - if (data.devAlias == NULL) + if (VIR_STRDUP(data.devAlias, devAlias) < 0) goto mem_error; data.action = action; - data.reason = strdup(reason); - if (data.reason == NULL) + if (VIR_STRDUP(data.reason, reason) < 0) goto mem_error;
Same story (in fact, true for much of this file, so I'll quit pointing it out).
@@ -473,17 +460,17 @@ static int remoteRelayDomainEventDiskChange(virConnectPtr conn ATTRIBUTE_UNUSED, memset(&data, 0, sizeof(data)); if (oldSrcPath && ((VIR_ALLOC(oldSrcPath_p) < 0) || - !(*oldSrcPath_p = strdup(oldSrcPath)))) + VIR_STRDUP(*oldSrcPath_p, oldSrcPath) < 0)) goto mem_error;
Ah, now here's where we have to choose to either report OOM twice on VIR_STRDUP failure until a second pass of patches cleans up VIR_ALLOC to report OOM, or where we temporarily have to make the code ugly so that VIR_ALLOC uses goto mem_error while VIR_STRDUP uses goto error. I guess I can live with either version, as long as we do get the VIR_ALLOC usage scrubbed before 1.0.6.
@@ -520,7 +507,7 @@ static int remoteRelayDomainEventTrayChange(virConnectPtr conn ATTRIBUTE_UNUSED, /* build return data */ memset(&data, 0, sizeof(data));
- if (!(data.devAlias = strdup(devAlias))) { + if (VIR_STRDUP(data.devAlias, devAlias) < 0) { virReportOOMError();
Drop the error report.
return -1; } @@ -850,8 +837,7 @@ remoteSerializeTypedParameters(virTypedParameterPtr params, }
/* remoteDispatchClientRequest will free this: */ - val[j].field = strdup(params[i].field); - if (val[j].field == NULL) { + if (VIR_STRDUP(val[j].field, params[i].field) < 0) { virReportOOMError();
And again.
goto cleanup; } @@ -876,9 +862,8 @@ remoteSerializeTypedParameters(virTypedParameterPtr params, val[j].value.remote_typed_param_value_u.b = params[i].value.b; break; case VIR_TYPED_PARAM_STRING: - val[j].value.remote_typed_param_value_u.s = - strdup(params[i].value.s); - if (val[j].value.remote_typed_param_value_u.s == NULL) { + if (VIR_STRDUP(val[j].value.remote_typed_param_value_u.s, + params[i].value.s) < 0) { virReportOOMError();
And again.
goto cleanup; } @@ -966,9 +951,8 @@ remoteDeserializeTypedParameters(remote_typed_param *args_params_val, args_params_val[i].value.remote_typed_param_value_u.b; break; case VIR_TYPED_PARAM_STRING: - params[i].value.s = - strdup(args_params_val[i].value.remote_typed_param_value_u.s); - if (params[i].value.s == NULL) { + if (VIR_STRDUP(params[i].value.s, + args_params_val[i].value.remote_typed_param_value_u.s) < 0) { virReportOOMError();
Here too.
goto cleanup; } @@ -2145,8 +2129,7 @@ remoteDispatchNodeGetCPUStats(virNetServerPtr server ATTRIBUTE_UNUSED,
for (i = 0; i < nparams; ++i) { /* remoteDispatchClientRequest will free this: */ - ret->params.params_val[i].field = strdup(params[i].field); - if (ret->params.params_val[i].field == NULL) + if (VIR_STRDUP(ret->params.params_val[i].field, params[i].field) < 0) goto no_memory;
Here, goto cleanup.
ret->params.params_val[i].value = params[i].value; @@ -2223,8 +2206,7 @@ remoteDispatchNodeGetMemoryStats(virNetServerPtr server ATTRIBUTE_UNUSED,
for (i = 0; i < nparams; ++i) { /* remoteDispatchClientRequest will free this: */ - ret->params.params_val[i].field = strdup(params[i].field); - if (ret->params.params_val[i].field == NULL) + if (VIR_STRDUP(ret->params.params_val[i].field, params[i].field) < 0) goto no_memory;
goto cleanup
ret->params.params_val[i].value = params[i].value; @@ -3100,7 +3082,7 @@ remoteDispatchNodeDeviceGetParent(virNetServerPtr server ATTRIBUTE_UNUSED, virReportOOMError(); goto cleanup; } - if (!(*parent_p = strdup(parent))) { + if (VIR_STRDUP(*parent_p, parent) < 0) { VIR_FREE(parent_p); virReportOOMError();
drop the duplicate error report
goto cleanup; @@ -4769,14 +4751,14 @@ static void make_nonnull_domain(remote_nonnull_domain *dom_dst, virDomainPtr dom_src) { dom_dst->id = dom_src->id; - dom_dst->name = strdup(dom_src->name); + ignore_value(VIR_STRDUP_QUIET(dom_dst->name , dom_src->name)); memcpy(dom_dst->uuid, dom_src->uuid, VIR_UUID_BUFLEN);
Ouch. Pre-existing bug that we leave dom_dst->name as NULL on OOM. It means that we could segfault instead of gracefully returning an error to the user when we ran out of memory. We probably ought to clean that up first (in fact, it would be appropriate to even clean it up before 1.0.5 - I might tackle that if I have time later today). You should NOT have to wrap ignore_value() around every caller of VIR_STRDUP_QUIET. What that says to me is that the macro you write in patch 2/37 needs to inline the ignore_value() as part of the macro.
}
static void make_nonnull_network(remote_nonnull_network *net_dst, virNetworkPtr net_src) { - net_dst->name = strdup(net_src->name); + ignore_value(VIR_STRDUP_QUIET(net_dst->name, net_src->name)); memcpy(net_dst->uuid, net_src->uuid, VIR_UUID_BUFLEN);
Hmm. All of our make_nonnull_* functions share that bug.
@@ -4844,7 +4826,7 @@ remoteSerializeDomainDiskErrors(virDomainDiskErrorPtr errors, goto no_memory;
for (i = 0; i < nerrors; i++) { - if (!(val[i].disk = strdup(errors[i].disk))) + if (VIR_STRDUP(val[i].disk, errors[i].disk) < 0) goto no_memory;
This one's another case of VIR_ALLOC_N and VIR_STRDUP both feeding into the same label; up to you whether to temporarily leave this one as double-reporting (until the VIR_ALLOC audit), or whether to re-arrange the label to have no_memory report OOM first instead of last, as well as add a new error: label for the VIR_STRDUP to jump to. It looks like we still have a long ways to go before this series is ready - I don't see any point in churning the code to add a silent VIR_STRDUP and then make a second pass that turns it to be noisy - it's simpler in the git history if we just start life with VIR_STRDUP as noisy and make the cleanups as we go as part of converting to use VIR_STRDUP. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

--- src/conf/capabilities.c | 26 ++++++++---------- src/conf/cpu_conf.c | 12 ++++----- src/conf/domain_conf.c | 64 ++++++++++++++++++++------------------------- src/conf/domain_event.c | 31 +++++++++++----------- src/conf/node_device_conf.c | 28 +++++++++----------- src/conf/nwfilter_conf.c | 18 +++++-------- src/conf/nwfilter_params.c | 22 +++++++--------- src/conf/snapshot_conf.c | 6 ++--- src/conf/storage_conf.c | 9 +++---- src/conf/virchrdev.c | 6 ++--- 10 files changed, 98 insertions(+), 124 deletions(-) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 5340b63..4b4b670 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -31,7 +31,7 @@ #include "viruuid.h" #include "cpu_conf.h" #include "virerror.h" - +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_CAPABILITIES @@ -228,7 +228,7 @@ virCapabilitiesAddHostFeature(virCapsPtr caps, caps->host.nfeatures, 1) < 0) return -1; - if ((caps->host.features[caps->host.nfeatures] = strdup(name)) == NULL) + if (VIR_STRDUP(caps->host.features[caps->host.nfeatures], name) < 0) return -1; caps->host.nfeatures++; @@ -250,7 +250,7 @@ virCapabilitiesAddHostMigrateTransport(virCapsPtr caps, caps->host.nmigrateTrans, 1) < 0) return -1; - if ((caps->host.migrateTrans[caps->host.nmigrateTrans] = strdup(name)) == NULL) + if (VIR_STRDUP(caps->host.migrateTrans[caps->host.nmigrateTrans], name) < 0) return -1; caps->host.nmigrateTrans++; @@ -334,7 +334,7 @@ virCapabilitiesAllocMachines(const char *const *names, int nnames) for (i = 0; i < nnames; i++) { if (VIR_ALLOC(machines[i]) < 0 || - !(machines[i]->name = strdup(names[i]))) { + VIR_STRDUP(machines[i]->name, names[i]) < 0) { virCapabilitiesFreeMachines(machines, nnames); return NULL; } @@ -392,17 +392,15 @@ virCapabilitiesAddGuest(virCapsPtr caps, if (VIR_ALLOC(guest) < 0) goto no_memory; - if ((guest->ostype = strdup(ostype)) == NULL) + if (VIR_STRDUP(guest->ostype, ostype) < 0) goto no_memory; guest->arch.id = arch; guest->arch.wordsize = virArchGetWordSize(arch); - if (emulator && - (guest->arch.defaultInfo.emulator = strdup(emulator)) == NULL) + if (emulator && VIR_STRDUP(guest->arch.defaultInfo.emulator, emulator) < 0) goto no_memory; - if (loader && - (guest->arch.defaultInfo.loader = strdup(loader)) == NULL) + if (loader && VIR_STRDUP(guest->arch.defaultInfo.loader, loader) < 0) goto no_memory; if (VIR_RESIZE_N(caps->guests, caps->nguests_max, @@ -448,14 +446,12 @@ virCapabilitiesAddGuestDomain(virCapsGuestPtr guest, if (VIR_ALLOC(dom) < 0) goto no_memory; - if ((dom->type = strdup(hvtype)) == NULL) + if (VIR_STRDUP(dom->type, hvtype) < 0) goto no_memory; - if (emulator && - (dom->info.emulator = strdup(emulator)) == NULL) + if (emulator && VIR_STRDUP(dom->info.emulator, emulator) < 0) goto no_memory; - if (loader && - (dom->info.loader = strdup(loader)) == NULL) + if (loader && VIR_STRDUP(dom->info.loader, loader) < 0) goto no_memory; if (VIR_RESIZE_N(guest->arch.domains, guest->arch.ndomains_max, @@ -497,7 +493,7 @@ virCapabilitiesAddGuestFeature(virCapsGuestPtr guest, if (VIR_ALLOC(feature) < 0) goto no_memory; - if ((feature->name = strdup(name)) == NULL) + if (VIR_STRDUP(feature->name, name) < 0) goto no_memory; feature->defaultOn = defaultOn; feature->toggle = toggle; diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c index 6aaee75..7a50d76 100644 --- a/src/conf/cpu_conf.c +++ b/src/conf/cpu_conf.c @@ -99,9 +99,9 @@ virCPUDefCopyModel(virCPUDefPtr dst, { unsigned int i; - if ((src->model && !(dst->model = strdup(src->model))) - || (src->vendor && !(dst->vendor = strdup(src->vendor))) - || (src->vendor_id && !(dst->vendor_id = strdup(src->vendor_id))) + if ((src->model && VIR_STRDUP(dst->model, src->model) < 0) + || (src->vendor && VIR_STRDUP(dst->vendor, src->vendor) < 0) + || (src->vendor_id && VIR_STRDUP(dst->vendor_id, src->vendor_id) < 0) || VIR_ALLOC_N(dst->features, src->nfeatures) < 0) goto no_memory; dst->nfeatures_max = dst->nfeatures = src->nfeatures; @@ -118,7 +118,7 @@ virCPUDefCopyModel(virCPUDefPtr dst, dst->features[i].policy = src->features[i].policy; } - if (!(dst->features[i].name = strdup(src->features[i].name))) + if (VIR_STRDUP(dst->features[i].name, src->features[i].name) < 0) goto no_memory; } @@ -167,7 +167,7 @@ virCPUDefCopy(const virCPUDefPtr cpu) if (!copy->cells[i].cpumask) goto no_memory; - if (!(copy->cells[i].cpustr = strdup(cpu->cells[i].cpustr))) + if (VIR_STRDUP(copy->cells[i].cpustr, cpu->cells[i].cpustr) < 0) goto no_memory; } copy->cells_cpus = cpu->cells_cpus; @@ -694,7 +694,7 @@ virCPUDefAddFeature(virCPUDefPtr def, if (def->type == VIR_CPU_TYPE_HOST) policy = -1; - if (!(def->features[def->nfeatures].name = strdup(name))) + if (VIR_STRDUP(def->features[def->nfeatures].name, name) < 0) goto no_memory; def->features[def->nfeatures].policy = policy; diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 51cb1fa..db854d3 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1352,7 +1352,7 @@ virDomainChrSourceDefCopy(virDomainChrSourceDefPtr dest, case VIR_DOMAIN_CHR_TYPE_FILE: case VIR_DOMAIN_CHR_TYPE_PIPE: if (src->data.file.path && - !(dest->data.file.path = strdup(src->data.file.path))) { + VIR_STRDUP(dest->data.file.path, src->data.file.path) < 0) { virReportOOMError(); return -1; } @@ -1360,26 +1360,26 @@ virDomainChrSourceDefCopy(virDomainChrSourceDefPtr dest, case VIR_DOMAIN_CHR_TYPE_UDP: if (src->data.udp.bindHost && - !(dest->data.udp.bindHost = strdup(src->data.udp.bindHost))) { + VIR_STRDUP(dest->data.udp.bindHost, src->data.udp.bindHost) < 0) { virReportOOMError(); return -1; } if (src->data.udp.bindService && - !(dest->data.udp.bindService = strdup(src->data.udp.bindService))) { + VIR_STRDUP(dest->data.udp.bindService, src->data.udp.bindService) < 0) { virReportOOMError(); return -1; } if (src->data.udp.connectHost && - !(dest->data.udp.connectHost = strdup(src->data.udp.connectHost))) { + VIR_STRDUP(dest->data.udp.connectHost, src->data.udp.connectHost) < 0) { virReportOOMError(); return -1; } if (src->data.udp.connectService && - !(dest->data.udp.connectService = strdup(src->data.udp.connectService))) { + VIR_STRDUP(dest->data.udp.connectService, src->data.udp.connectService) < 0) { virReportOOMError(); return -1; } @@ -1387,13 +1387,13 @@ virDomainChrSourceDefCopy(virDomainChrSourceDefPtr dest, case VIR_DOMAIN_CHR_TYPE_TCP: if (src->data.tcp.host && - !(dest->data.tcp.host = strdup(src->data.tcp.host))) { + VIR_STRDUP(dest->data.tcp.host, src->data.tcp.host) < 0) { virReportOOMError(); return -1; } if (src->data.tcp.service && - !(dest->data.tcp.service = strdup(src->data.tcp.service))) { + VIR_STRDUP(dest->data.tcp.service, src->data.tcp.service) < 0) { virReportOOMError(); return -1; } @@ -1401,7 +1401,7 @@ virDomainChrSourceDefCopy(virDomainChrSourceDefPtr dest, case VIR_DOMAIN_CHR_TYPE_UNIX: if (src->data.nix.path && - !(dest->data.nix.path = strdup(src->data.nix.path))) { + VIR_STRDUP(dest->data.nix.path, src->data.nix.path) < 0) { virReportOOMError(); return -1; } @@ -2378,11 +2378,11 @@ virDomainDeviceInfoCopy(virDomainDeviceInfoPtr dst, dst->alias = NULL; dst->romfile = NULL; - if (src->alias && !(dst->alias = strdup(src->alias))) { + if (src->alias && VIR_STRDUP(dst->alias, src->alias) < 0) { virReportOOMError(); return -1; } - if (src->romfile && !(dst->romfile = strdup(src->romfile))) { + if (src->romfile && VIR_STRDUP(dst->romfile, src->romfile) < 0) { virReportOOMError(); return -1; } @@ -4124,8 +4124,7 @@ virSecurityLabelDefsParseXML(virDomainDefPtr def, /* Copy model from host. */ VIR_DEBUG("Found seclabel without a model, using '%s'", host->secModels[0].model); - def->seclabels[0]->model = strdup(host->secModels[0].model); - if (!def->seclabels[0]->model) { + if (VIR_STRDUP(def->seclabels[0]->model, host->secModels[0].model) < 0) { virReportOOMError(); goto error; } @@ -5741,7 +5740,7 @@ 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 = strdup("usb")) == NULL) { + VIR_STRDUP(addrtype, "usb") < 0) { virReportOOMError(); goto error; } @@ -6133,7 +6132,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt, addrtype = virXPathString("string(./source/address/@type)", ctxt); /* if not explicitly stated, source/vendor implies usb device */ if (!addrtype && virXPathNode("./source/vendor", ctxt) && - ((addrtype = strdup("usb")) == NULL)) { + VIR_STRDUP(addrtype, "usb") < 0) { virReportOOMError(); goto error; } @@ -7006,7 +7005,7 @@ virDomainTPMDefParseXML(const xmlNodePtr node, switch (def->type) { case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH: path = virXPathString("string(./backend/device/@path)", ctxt); - if (!path && !(path = strdup(VIR_DOMAIN_TPM_DEFAULT_DEVICE))) { + if (!path && VIR_STRDUP(path, VIR_DOMAIN_TPM_DEFAULT_DEVICE) < 0) { virReportOOMError(); goto error; } @@ -8732,7 +8731,7 @@ virDomainRedirFilterUsbVersionHelper(const char *version, unsigned int minor; unsigned int hex; - if (!(version_copy = strdup(version))) { + if (VIR_STRDUP(version_copy, version) < 0) { virReportOOMError(); return -1; } @@ -9681,7 +9680,7 @@ virDomainDefGetDefaultEmulator(virDomainDefPtr def, return NULL; } - if (!(retemu = strdup(emulator))) + if (VIR_STRDUP(retemu, emulator) < 0) virReportOOMError(); return retemu; @@ -10784,10 +10783,8 @@ virDomainDefParseXML(xmlDocPtr xml, def->os.type = virXPathString("string(./os/type[1])", ctxt); if (!def->os.type) { if (def->os.bootloader) { - def->os.type = strdup("xen"); - if (!def->os.type) { + if (VIR_STRDUP(def->os.type, "xen") < 0) goto no_memory; - } } else { virReportError(VIR_ERR_OS_TYPE, "%s", _("no OS type")); @@ -10802,9 +10799,8 @@ virDomainDefParseXML(xmlDocPtr xml, if (STREQ(def->os.type, "linux") && def->virtType == VIR_DOMAIN_VIRT_XEN) { VIR_FREE(def->os.type); - if (!(def->os.type = strdup("xen"))) { + if (VIR_STRDUP(def->os.type, "xen") < 0) goto no_memory; - } } if (!virCapabilitiesSupportsGuestOSType(caps, def->os.type)) { @@ -10858,11 +10854,9 @@ virDomainDefParseXML(xmlDocPtr xml, def->os.type, def->os.arch, virDomainVirtTypeToString(def->virtType)); - if (defaultMachine != NULL) { - if (!(def->os.machine = strdup(defaultMachine))) { - goto no_memory; - } - } + if (defaultMachine && + VIR_STRDUP(def->os.machine, defaultMachine) < 0) + goto no_memory; } /* @@ -10891,7 +10885,7 @@ virDomainDefParseXML(xmlDocPtr xml, _("No data supplied for <initarg> element")); goto error; } - if (!(def->os.initargv[i] = strdup((const char*)nodes[i]->children->content))) + if (VIR_STRDUP(def->os.initargv[i], (const char*)nodes[i]->children->content) < 0) goto no_memory; } def->os.initargv[n] = NULL; @@ -16492,7 +16486,7 @@ virDomainObjListCopyInactiveNames(void *payload, virObjectLock(obj); if (!virDomainObjIsActive(obj) && data->numnames < data->maxnames) { - if (!(data->names[data->numnames] = strdup(obj->def->name))) + if (VIR_STRDUP(data->names[data->numnames], obj->def->name) < 0) data->oom = 1; else data->numnames++; @@ -17045,8 +17039,8 @@ virDomainGraphicsListenSetAddress(virDomainGraphicsDefPtr def, return 0; } - listenInfo->address = (len == -1) ? strdup(address) : strndup(address, len); - if (!listenInfo->address) { + if ((len == -1 && VIR_STRDUP(listenInfo->address, address) < 0) || + (len != -1 && VIR_STRNDUP(listenInfo->address, address, len) < 0)) { virReportOOMError(); return -1; } @@ -17087,8 +17081,8 @@ virDomainGraphicsListenSetNetwork(virDomainGraphicsDefPtr def, return 0; } - listenInfo->network = (len == -1) ? strdup(network) : strndup(network, len); - if (!listenInfo->network) { + if ((len == -1 && VIR_STRDUP(listenInfo->network, network) < 0) || + (len != -1 && VIR_STRNDUP(listenInfo->network, network, len) < 0)) { virReportOOMError(); return -1; } @@ -17427,7 +17421,7 @@ virDomainDefGenSecurityLabelDef(const char *model) virSecurityLabelDefPtr seclabel = NULL; if (VIR_ALLOC(seclabel) < 0 || - (model && !(seclabel->model = strdup(model)))) { + (model && VIR_STRDUP(seclabel->model, model) < 0)) { virReportOOMError(); virSecurityLabelDefFree(seclabel); seclabel = NULL; @@ -17442,7 +17436,7 @@ virDomainDiskDefGenSecurityLabelDef(const char *model) virSecurityDeviceLabelDefPtr seclabel = NULL; if (VIR_ALLOC(seclabel) < 0 || - (model && !(seclabel->model = strdup(model)))) { + (model && VIR_STRDUP(seclabel->model, model) < 0)) { virReportOOMError(); virSecurityDeviceLabelDefFree(seclabel); seclabel = NULL; diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c index 825012a..b5f5c92 100644 --- a/src/conf/domain_event.c +++ b/src/conf/domain_event.c @@ -28,6 +28,7 @@ #include "datatypes.h" #include "viralloc.h" #include "virerror.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_NONE @@ -385,7 +386,7 @@ virDomainEventCallbackListAddID(virConnectPtr conn, if (dom) { if (VIR_ALLOC(event->dom) < 0) goto no_memory; - if (!(event->dom->name = strdup(dom->name))) + if (VIR_STRDUP(event->dom->name, dom->name) < 0) goto no_memory; memcpy(event->dom->uuid, dom->uuid, VIR_UUID_BUFLEN); event->dom->id = dom->id; @@ -668,7 +669,7 @@ static virDomainEventPtr virDomainEventNewInternal(int eventID, } event->eventID = eventID; - if (!(event->dom.name = strdup(name))) { + if (VIR_STRDUP(event->dom.name, name) < 0) { virReportOOMError(); VIR_FREE(event); return NULL; @@ -791,9 +792,9 @@ static virDomainEventPtr virDomainEventIOErrorNewFromDomImpl(int event, if (ev) { ev->data.ioError.action = action; - if (!(ev->data.ioError.srcPath = strdup(srcPath)) || - !(ev->data.ioError.devAlias = strdup(devAlias)) || - (reason && !(ev->data.ioError.reason = strdup(reason)))) { + if (VIR_STRDUP(ev->data.ioError.srcPath, srcPath) < 0 || + VIR_STRDUP(ev->data.ioError.devAlias, devAlias) < 0 || + (reason && VIR_STRDUP(ev->data.ioError.reason, reason) < 0)) { virDomainEventFree(ev); ev = NULL; } @@ -815,9 +816,9 @@ static virDomainEventPtr virDomainEventIOErrorNewFromObjImpl(int event, if (ev) { ev->data.ioError.action = action; - if (!(ev->data.ioError.srcPath = strdup(srcPath)) || - !(ev->data.ioError.devAlias = strdup(devAlias)) || - (reason && !(ev->data.ioError.reason = strdup(reason)))) { + if (VIR_STRDUP(ev->data.ioError.srcPath, srcPath) < 0 || + VIR_STRDUP(ev->data.ioError.devAlias, devAlias) < 0 || + (reason && VIR_STRDUP(ev->data.ioError.reason, reason) < 0)) { virDomainEventFree(ev); ev = NULL; } @@ -882,7 +883,7 @@ virDomainEventPtr virDomainEventGraphicsNewFromDom(virDomainPtr dom, if (ev) { ev->data.graphics.phase = phase; - if (!(ev->data.graphics.authScheme = strdup(authScheme))) { + if (VIR_STRDUP(ev->data.graphics.authScheme, authScheme) < 0) { virDomainEventFree(ev); return NULL; } @@ -907,7 +908,7 @@ virDomainEventPtr virDomainEventGraphicsNewFromObj(virDomainObjPtr obj, if (ev) { ev->data.graphics.phase = phase; - if (!(ev->data.graphics.authScheme = strdup(authScheme))) { + if (VIR_STRDUP(ev->data.graphics.authScheme, authScheme) < 0) { virDomainEventFree(ev); return NULL; } @@ -928,7 +929,7 @@ virDomainEventBlockJobNew(int id, const char *name, unsigned char *uuid, id, name, uuid); if (ev) { - if (!(ev->data.blockJob.path = strdup(path))) { + if (VIR_STRDUP(ev->data.blockJob.path, path) < 0) { virReportOOMError(); virDomainEventFree(ev); return NULL; @@ -987,15 +988,15 @@ virDomainEventDiskChangeNew(int id, const char *name, id, name, uuid); if (ev) { - if (!(ev->data.diskChange.devAlias = strdup(devAlias))) + if (VIR_STRDUP(ev->data.diskChange.devAlias, devAlias) < 0) goto error; if (oldSrcPath && - !(ev->data.diskChange.oldSrcPath = strdup(oldSrcPath))) + VIR_STRDUP(ev->data.diskChange.oldSrcPath, oldSrcPath) < 0) goto error; if (newSrcPath && - !(ev->data.diskChange.newSrcPath = strdup(newSrcPath))) + VIR_STRDUP(ev->data.diskChange.newSrcPath, newSrcPath) < 0) goto error; ev->data.diskChange.reason = reason; @@ -1042,7 +1043,7 @@ virDomainEventTrayChangeNew(int id, const char *name, id, name, uuid); if (ev) { - if (!(ev->data.trayChange.devAlias = strdup(devAlias))) + if (VIR_STRDUP(ev->data.trayChange.devAlias, devAlias) < 0) goto error; ev->data.trayChange.reason = reason; diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index f9303c1..346a2a0 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -35,6 +35,7 @@ #include "virbuffer.h" #include "viruuid.h" #include "virrandom.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_NODEDEV @@ -1163,13 +1164,9 @@ virNodeDeviceDefParseXML(xmlXPathContextPtr ctxt, virReportError(VIR_ERR_NO_NAME, NULL); goto error; } - } else { - def->name = strdup("new device"); - - if (!def->name) { - virReportOOMError(); - goto error; - } + } else if (VIR_STRDUP(def->name, "new device") < 0) { + virReportOOMError(); + goto error; } /* Extract device parent, if any */ @@ -1290,8 +1287,14 @@ virNodeDeviceGetWWNs(virNodeDeviceDefPtr def, while (cap != NULL) { if (cap->type == VIR_NODE_DEV_CAP_SCSI_HOST && cap->data.scsi_host.flags & VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST) { - *wwnn = strdup(cap->data.scsi_host.wwnn); - *wwpn = strdup(cap->data.scsi_host.wwpn); + if (VIR_STRDUP(*wwnn, cap->data.scsi_host.wwnn) < 0) { + VIR_FREE(*wwpn); + ret = -1; + } + if (VIR_STRDUP(*wwpn, cap->data.scsi_host.wwpn) < 0){ + VIR_FREE(*wwnn); + ret = -1; + } break; } @@ -1302,14 +1305,7 @@ virNodeDeviceGetWWNs(virNodeDeviceDefPtr def, virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Device is not a fibre channel HBA")); ret = -1; - } else if (*wwnn == NULL || *wwpn == NULL) { - /* Free the other one, if allocated... */ - VIR_FREE(*wwnn); - VIR_FREE(*wwpn); - ret = -1; - virReportOOMError(); } - return ret; } diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c index 08222de..686a63f 100644 --- a/src/conf/nwfilter_conf.c +++ b/src/conf/nwfilter_conf.c @@ -400,9 +400,7 @@ virNWFilterRuleDefAddString(virNWFilterRuleDefPtr nwf, return NULL; } - nwf->strings[nwf->nstrings] = strndup(string, maxstrlen); - - if (!nwf->strings[nwf->nstrings]) { + if (VIR_STRNDUP(nwf->strings[nwf->nstrings], string, maxstrlen) < 0) { virReportOOMError(); return NULL; } @@ -2555,13 +2553,10 @@ virNWFilterDefParseXML(xmlXPathContextPtr ctxt) { } } chain = NULL; - } else { - ret->chainsuffix = strdup(virNWFilterChainSuffixTypeToString( - VIR_NWFILTER_CHAINSUFFIX_ROOT)); - if (ret->chainsuffix == NULL) { - virReportOOMError(); - goto cleanup; - } + } else if (VIR_STRDUP(ret->chainsuffix, + virNWFilterChainSuffixTypeToString(VIR_NWFILTER_CHAINSUFFIX_ROOT)) < 0) { + virReportOOMError(); + goto cleanup; } uuid = virXPathString("string(./uuid)", ctxt); @@ -3094,8 +3089,7 @@ virNWFilterObjLoad(virConnectPtr conn, } VIR_FREE(nwfilter->configFile); /* for driver reload */ - nwfilter->configFile = strdup(path); - if (nwfilter->configFile == NULL) { + if (VIR_STRDUP(nwfilter->configFile, path) < 0) { virReportOOMError(); virNWFilterDefFree(def); return NULL; diff --git a/src/conf/nwfilter_params.c b/src/conf/nwfilter_params.c index 2509c0d..2700945 100644 --- a/src/conf/nwfilter_params.c +++ b/src/conf/nwfilter_params.c @@ -80,8 +80,7 @@ virNWFilterVarValueCopy(const virNWFilterVarValuePtr val) switch (res->valType) { case NWFILTER_VALUE_TYPE_SIMPLE: if (val->u.simple.value) { - res->u.simple.value = strdup(val->u.simple.value); - if (!res->u.simple.value) + if (VIR_STRDUP(res->u.simple.value, val->u.simple.value) < 0) goto err_exit; } break; @@ -90,8 +89,7 @@ virNWFilterVarValueCopy(const virNWFilterVarValuePtr val) goto err_exit; res->u.array.nValues = val->u.array.nValues; for (i = 0; i < val->u.array.nValues; i++) { - str = strdup(val->u.array.values[i]); - if (!str) + if (VIR_STRDUP(str, val->u.array.values[i]) < 0) goto err_exit; res->u.array.values[i] = str; } @@ -133,9 +131,9 @@ virNWFilterVarValueCreateSimple(char *value) virNWFilterVarValuePtr virNWFilterVarValueCreateSimpleCopyValue(const char *value) { - char *val = strdup(value); + char *val; - if (!val) { + if (VIR_STRDUP(val, value) < 0) { virReportOOMError(); return NULL; } @@ -654,8 +652,8 @@ virNWFilterHashTablePut(virNWFilterHashTablePtr table, { if (!virHashLookup(table->hashTable, name)) { if (copyName) { - name = strdup(name); - if (!name) { + char *new_name; + if (VIR_STRDUP(new_name, name) < 0) { virReportOOMError(); return -1; } @@ -664,7 +662,7 @@ virNWFilterHashTablePut(virNWFilterHashTablePtr table, VIR_FREE(name); return -1; } - table->names[table->nNames++] = (char *)name; + table->names[table->nNames++] = new_name; } if (virHashAddEntry(table->hashTable, name, val) < 0) { @@ -1006,8 +1004,7 @@ virNWFilterVarAccessParse(const char *varAccess) if (input[idx] == '\0') { /* in the form 'IP', which is equivalent to IP[@0] */ - dest->varName = strndup(input, idx); - if (!dest->varName) { + if (VIR_STRNDUP(dest->varName, input, idx) < 0) { virReportOOMError(); goto err_exit; } @@ -1023,8 +1020,7 @@ virNWFilterVarAccessParse(const char *varAccess) varNameLen = idx; - dest->varName = strndup(input, varNameLen); - if (!dest->varName) { + if (VIR_STRNDUP(dest->varName, input, varNameLen) < 0) { virReportOOMError(); goto err_exit; } diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index 5b54a28..8115b9e 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -463,7 +463,7 @@ virDomainSnapshotAlignDisks(virDomainSnapshotDefPtr def, } if (STRNEQ(disk->name, def->dom->disks[idx]->dst)) { VIR_FREE(disk->name); - if (!(disk->name = strdup(def->dom->disks[idx]->dst))) { + if (VIR_STRDUP(disk->name, def->dom->disks[idx]->dst) < 0) { virReportOOMError(); goto cleanup; } @@ -485,7 +485,7 @@ virDomainSnapshotAlignDisks(virDomainSnapshotDefPtr def, if (inuse) continue; disk = &def->disks[ndisks++]; - if (!(disk->name = strdup(def->dom->disks[i]->dst))) { + if (VIR_STRDUP(disk->name, def->dom->disks[i]->dst) < 0) { virReportOOMError(); goto cleanup; } @@ -768,7 +768,7 @@ static void virDomainSnapshotObjListCopyNames(void *payload, return; if (data->names && data->count < data->maxnames && - !(data->names[data->count] = strdup(obj->def->name))) { + VIR_STRDUP(data->names[data->count], obj->def->name) < 0) { data->error = true; virReportOOMError(); return; diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index 9f2012e..2a1a9ff 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -878,8 +878,7 @@ virStoragePoolDefParseXML(xmlXPathContextPtr ctxt) { if (options->flags & VIR_STORAGE_POOL_SOURCE_NAME) { if (ret->source.name == NULL) { /* source name defaults to pool name */ - ret->source.name = strdup(ret->name); - if (ret->source.name == NULL) { + if (VIR_STRDUP(ret->source.name, ret->name) < 0) { virReportOOMError(); goto cleanup; } @@ -1679,15 +1678,13 @@ virStoragePoolObjLoad(virStoragePoolObjListPtr pools, } VIR_FREE(pool->configFile); /* for driver reload */ - pool->configFile = strdup(path); - if (pool->configFile == NULL) { + if (VIR_STRDUP(pool->configFile, path) < 0) { virReportOOMError(); virStoragePoolDefFree(def); return NULL; } VIR_FREE(pool->autostartLink); /* for driver reload */ - pool->autostartLink = strdup(autostartLink); - if (pool->autostartLink == NULL) { + if (VIR_STRDUP(pool->autostartLink, autostartLink) < 0) { virReportOOMError(); virStoragePoolDefFree(def); return NULL; diff --git a/src/conf/virchrdev.c b/src/conf/virchrdev.c index 025d4a8..2adf4aa 100644 --- a/src/conf/virchrdev.c +++ b/src/conf/virchrdev.c @@ -52,7 +52,7 @@ typedef struct _virChrdevStreamInfo virChrdevStreamInfo; typedef virChrdevStreamInfo *virChrdevStreamInfoPtr; struct _virChrdevStreamInfo { virChrdevsPtr devs; - const char *path; + char *path; }; #ifdef VIR_CHRDEV_LOCK_FILE_PATH @@ -73,7 +73,7 @@ static char *virChrdevLockFilePath(const char *dev) char *filename; char *p; - if (!(devCopy = strdup(dev))) { + if (VIR_STRDUP(devCopy, dev) < 0) { virReportOOMError(); goto cleanup; } @@ -401,7 +401,7 @@ int virChrdevOpen(virChrdevsPtr devs, goto error; cbdata->devs = devs; - if (!(cbdata->path = strdup(path))) { + if (VIR_STRDUP(cbdata->path, path) < 0) { virReportOOMError(); goto error; } -- 1.8.1.5

--- src/cpu/cpu_generic.c | 6 +++--- src/cpu/cpu_map.c | 3 ++- src/cpu/cpu_powerpc.c | 10 +++++----- src/cpu/cpu_x86.c | 6 +++--- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/cpu/cpu_generic.c b/src/cpu/cpu_generic.c index 9d5117f..e907269 100644 --- a/src/cpu/cpu_generic.c +++ b/src/cpu/cpu_generic.c @@ -28,7 +28,7 @@ #include "virhash.h" #include "cpu.h" #include "cpu_generic.h" - +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_CPU @@ -131,7 +131,7 @@ genericBaseline(virCPUDefPtr *cpus, } if (VIR_ALLOC(cpu) < 0 || - !(cpu->model = strdup(cpus[0]->model)) || + VIR_STRDUP(cpu->model, cpus[0]->model) < 0 || VIR_ALLOC_N(features, cpus[0]->nfeatures) < 0) goto no_memory; @@ -183,7 +183,7 @@ genericBaseline(virCPUDefPtr *cpus, if (!features[i].name) continue; - if (!(cpu->features[j++].name = strdup(features[i].name))) + if (VIR_STRDUP(cpu->features[j++].name, features[i].name) < 0) goto no_memory; } diff --git a/src/cpu/cpu_map.c b/src/cpu/cpu_map.c index 015be2e..7c2bdec 100644 --- a/src/cpu/cpu_map.c +++ b/src/cpu/cpu_map.c @@ -27,6 +27,7 @@ #include "cpu.h" #include "cpu_map.h" #include "configmake.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_CPU @@ -149,7 +150,7 @@ cpuMapOverride(const char *path) { char *map; - if (!(map = strdup(path))) + if (VIR_STRDUP(map, path) < 0) return -1; VIR_FREE(cpumap); diff --git a/src/cpu/cpu_powerpc.c b/src/cpu/cpu_powerpc.c index b253db2..3aa7395 100644 --- a/src/cpu/cpu_powerpc.c +++ b/src/cpu/cpu_powerpc.c @@ -29,9 +29,9 @@ #include "virlog.h" #include "viralloc.h" #include "cpu.h" - #include "cpu_map.h" #include "virbuffer.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_CPU @@ -333,8 +333,8 @@ ppcDecode(virCPUDefPtr cpu, goto cleanup; } - if (!(cpu->model = strdup(model->name)) || - (model->vendor && !(cpu->vendor = strdup(model->vendor->name)))) { + if (VIR_STRDUP(cpu->model, model->name) < 0 || + (model->vendor && VIR_STRDUP(cpu->vendor, model->vendor->name) < 0)) { virReportOOMError(); goto cleanup; } @@ -449,10 +449,10 @@ ppcBaseline(virCPUDefPtr *cpus, } if (VIR_ALLOC(cpu) < 0 || - !(cpu->model = strdup(model->name))) + VIR_STRDUP(cpu->model, model->name) < 0) goto no_memory; - if (vendor && !(cpu->vendor = strdup(vendor->name))) + if (vendor && VIR_STRDUP(cpu->vendor, vendor->name) < 0) goto no_memory; cpu->type = VIR_CPU_TYPE_GUEST; diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c index 14d525e..009c2c0 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -449,13 +449,13 @@ x86DataToCPU(const union cpuData *data, const struct x86_vendor *vendor; if (VIR_ALLOC(cpu) < 0 || - !(cpu->model = strdup(model->name)) || + VIR_STRDUP(cpu->model, model->name) < 0 || !(copy = x86DataCopy(data)) || !(modelData = x86DataCopy(model->data))) goto no_memory; if ((vendor = x86DataToVendor(copy, map)) && - !(cpu->vendor = strdup(vendor->name))) + VIR_STRDUP(cpu->vendor, vendor->name) < 0) goto no_memory; x86DataSubtract(copy, modelData); @@ -767,7 +767,7 @@ x86ModelCopy(const struct x86_model *model) struct x86_model *copy; if (VIR_ALLOC(copy) < 0 - || !(copy->name = strdup(model->name)) + || VIR_STRDUP(copy->name, model->name) < 0 || !(copy->data = x86DataCopy(model->data))) { x86ModelFree(copy); return NULL; -- 1.8.1.5

--- src/esx/esx_driver.c | 33 +++++++++---------------- src/esx/esx_interface_driver.c | 5 ++-- src/esx/esx_network_driver.c | 20 ++++++--------- src/esx/esx_storage_backend_iscsi.c | 14 ++++------- src/esx/esx_storage_backend_vmfs.c | 8 ++---- src/esx/esx_util.c | 37 +++++++++------------------- src/esx/esx_vi.c | 49 +++++++++---------------------------- src/esx/esx_vi_types.c | 22 +++++------------ 8 files changed, 58 insertions(+), 130 deletions(-) diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index dcf64b8..a5caafe 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -669,9 +669,7 @@ esxConnectToHost(esxPrivate *priv, } if (conn->uri->user != NULL) { - username = strdup(conn->uri->user); - - if (username == NULL) { + if (VIR_STRDUP(username, conn->uri->user) < 0) { virReportOOMError(); goto cleanup; } @@ -751,13 +749,10 @@ esxConnectToHost(esxPrivate *priv, VIR_WARN("The server is in maintenance mode"); } - if (*vCenterIpAddress != NULL) { - *vCenterIpAddress = strdup(*vCenterIpAddress); - - if (*vCenterIpAddress == NULL) { - virReportOOMError(); - goto cleanup; - } + if (*vCenterIpAddress && + VIR_STRDUP(*vCenterIpAddress, *vCenterIpAddress) < 0) { + virReportOOMError(); + goto cleanup; } result = 0; @@ -801,9 +796,7 @@ esxConnectToVCenter(esxPrivate *priv, } if (conn->uri->user != NULL) { - username = strdup(conn->uri->user); - - if (username == NULL) { + if (VIR_STRDUP(username, conn->uri->user) < 0) { virReportOOMError(); goto cleanup; } @@ -1278,9 +1271,7 @@ esxConnectGetHostname(virConnectPtr conn) } if (domainName == NULL || strlen(domainName) < 1) { - complete = strdup(hostName); - - if (complete == NULL) { + if (VIR_STRDUP(complete, hostName) < 0) { virReportOOMError(); goto cleanup; } @@ -1294,7 +1285,7 @@ esxConnectGetHostname(virConnectPtr conn) cleanup: /* * If we goto cleanup in case of an error then complete is still NULL, - * either strdup returned NULL or virAsprintf failed. When virAsprintf + * either VIR_STRDUP returned NULL or virAsprintf failed. When virAsprintf * fails it guarantees setting complete to NULL */ esxVI_String_Free(&propertyNameList); @@ -2016,9 +2007,9 @@ esxDomainDestroy(virDomainPtr dom) static char * esxDomainGetOSType(virDomainPtr domain ATTRIBUTE_UNUSED) { - char *osType = strdup("hvm"); + char *osType; - if (osType == NULL) { + if (VIR_STRDUP(osType, "hvm") < 0) { virReportOOMError(); return NULL; } @@ -3577,9 +3568,9 @@ esxDomainSetAutostart(virDomainPtr domain, int autostart) static char * esxDomainGetSchedulerType(virDomainPtr domain ATTRIBUTE_UNUSED, int *nparams) { - char *type = strdup("allocation"); + char *type; - if (type == NULL) { + if (VIR_STRDUP(type, "allocation") < 0) { virReportOOMError(); return NULL; } diff --git a/src/esx/esx_interface_driver.c b/src/esx/esx_interface_driver.c index fe5194c..ba006a2 100644 --- a/src/esx/esx_interface_driver.c +++ b/src/esx/esx_interface_driver.c @@ -35,6 +35,7 @@ #include "esx_vi.h" #include "esx_vi_methods.h" #include "esx_util.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_ESX @@ -114,9 +115,7 @@ esxConnectListInterfaces(virConnectPtr conn, char **const names, int maxnames) for (physicalNic = physicalNicList; physicalNic != NULL; physicalNic = physicalNic->_next) { - names[count] = strdup(physicalNic->device); - - if (names[count] == NULL) { + if (VIR_STRDUP(names[count], physicalNic->device) < 0) { virReportOOMError(); goto cleanup; } diff --git a/src/esx/esx_network_driver.c b/src/esx/esx_network_driver.c index fd57b61..cb6a806 100644 --- a/src/esx/esx_network_driver.c +++ b/src/esx/esx_network_driver.c @@ -35,6 +35,7 @@ #include "esx_vi.h" #include "esx_vi_methods.h" #include "esx_util.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_ESX @@ -122,9 +123,7 @@ esxConnectListNetworks(virConnectPtr conn, char **const names, int maxnames) for (hostVirtualSwitch = hostVirtualSwitchList; hostVirtualSwitch != NULL; hostVirtualSwitch = hostVirtualSwitch->_next) { - names[count] = strdup(hostVirtualSwitch->name); - - if (names[count] == NULL) { + if (VIR_STRDUP(names[count], hostVirtualSwitch->name) < 0) { virReportOOMError(); goto cleanup; } @@ -713,9 +712,7 @@ esxNetworkGetXMLDesc(virNetworkPtr network_, unsigned int flags) md5_buffer(hostVirtualSwitch->key, strlen(hostVirtualSwitch->key), def->uuid); - def->name = strdup(hostVirtualSwitch->name); - - if (def->name == NULL) { + if (VIR_STRDUP(def->name, hostVirtualSwitch->name) < 0) { virReportOOMError(); goto cleanup; } @@ -752,10 +749,8 @@ esxNetworkGetXMLDesc(virNetworkPtr network_, unsigned int flags) if (STREQ(physicalNicKey->value, physicalNic->key)) { def->forward.ifs[def->forward.nifs].type = VIR_NETWORK_FORWARD_HOSTDEV_DEVICE_NETDEV; - def->forward.ifs[def->forward.nifs].device.dev - = strdup(physicalNic->device); - - if (def->forward.ifs[def->forward.nifs].device.dev == NULL) { + if (VIR_STRDUP(def->forward.ifs[def->forward.nifs].device.dev, + physicalNic->device) < 0) { virReportOOMError(); goto cleanup; } @@ -823,9 +818,8 @@ esxNetworkGetXMLDesc(virNetworkPtr network_, unsigned int flags) for (networkName = networkNameList; networkName != NULL; networkName = networkName->_next) { if (STREQ(networkName->value, hostPortGroup->spec->name)) { - def->portGroups[def->nPortGroups].name = strdup(networkName->value); - - if (def->portGroups[def->nPortGroups].name == NULL) { + if (VIR_STRDUP(def->portGroups[def->nPortGroups].name, + networkName->value) < 0) { virReportOOMError(); goto cleanup; } diff --git a/src/esx/esx_storage_backend_iscsi.c b/src/esx/esx_storage_backend_iscsi.c index 941e800..57aa24b 100644 --- a/src/esx/esx_storage_backend_iscsi.c +++ b/src/esx/esx_storage_backend_iscsi.c @@ -38,6 +38,7 @@ #include "esx_vi.h" #include "esx_vi_methods.h" #include "esx_util.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_ESX @@ -130,9 +131,7 @@ esxStorageBackendISCSIListPools(virConnectPtr conn, char **const names, */ for (target = hostInternetScsiHba->configuredStaticTarget; target != NULL && count < maxnames; target = target->_next) { - names[count] = strdup(target->iScsiName); - - if (names[count] == NULL) { + if (VIR_STRDUP(names[count], target->iScsiName) < 0) { virReportOOMError(); goto cleanup; } @@ -419,9 +418,7 @@ esxStorageBackendISCSIPoolListVolumes(virStoragePoolPtr pool, char **const names hostScsiTopologyLun != NULL && count < maxnames; hostScsiTopologyLun = hostScsiTopologyLun->_next) { if (STREQ(hostScsiTopologyLun->scsiLun, scsiLun->key)) { - names[count] = strdup(scsiLun->deviceName); - - if (names[count] == NULL) { + if (VIR_STRDUP(names[count], scsiLun->deviceName) < 0) { virReportOOMError(); goto cleanup; } @@ -739,9 +736,8 @@ esxStorageBackendISCSIVolumeWipe(virStorageVolPtr volume ATTRIBUTE_UNUSED, static char * esxStorageBackendISCSIVolumeGetPath(virStorageVolPtr volume) { - char *path = strdup(volume->name); - - if (path == NULL) { + char *path; + if (VIR_STRDUP(path, volume->name) < 0) { virReportOOMError(); return NULL; } diff --git a/src/esx/esx_storage_backend_vmfs.c b/src/esx/esx_storage_backend_vmfs.c index dea6716..42efeb1 100644 --- a/src/esx/esx_storage_backend_vmfs.c +++ b/src/esx/esx_storage_backend_vmfs.c @@ -168,9 +168,7 @@ esxStorageBackendVMFSListPools(virConnectPtr conn, char **const names, goto cleanup; } - names[count] = strdup(dynamicProperty->val->string); - - if (names[count] == NULL) { + if (VIR_STRDUP(names[count], dynamicProperty->val->string) < 0) { virReportOOMError(); goto cleanup; } @@ -614,9 +612,7 @@ esxStorageBackendVMFSPoolListVolumes(virStoragePoolPtr pool, char **const names, for (fileInfo = searchResults->file; fileInfo != NULL; fileInfo = fileInfo->_next) { if (length < 1) { - names[count] = strdup(fileInfo->path); - - if (names[count] == NULL) { + if (VIR_STRDUP(names[count], fileInfo->path) < 0) { virReportOOMError(); goto cleanup; } diff --git a/src/esx/esx_util.c b/src/esx/esx_util.c index 4566fec..55efb17 100644 --- a/src/esx/esx_util.c +++ b/src/esx/esx_util.c @@ -65,9 +65,7 @@ esxUtil_ParseUri(esxUtil_ParsedUri **parsedUri, virURIPtr uri) if (STRCASEEQ(queryParam->name, "transport")) { VIR_FREE((*parsedUri)->transport); - (*parsedUri)->transport = strdup(queryParam->value); - - if ((*parsedUri)->transport == NULL) { + if (VIR_STRDUP((*parsedUri)->transport, queryParam->value) < 0) { virReportOOMError(); goto cleanup; } @@ -83,9 +81,7 @@ esxUtil_ParseUri(esxUtil_ParsedUri **parsedUri, virURIPtr uri) } else if (STRCASEEQ(queryParam->name, "vcenter")) { VIR_FREE((*parsedUri)->vCenter); - (*parsedUri)->vCenter = strdup(queryParam->value); - - if ((*parsedUri)->vCenter == NULL) { + if (VIR_STRDUP((*parsedUri)->vCenter, queryParam->value) < 0) { virReportOOMError(); goto cleanup; } @@ -137,9 +133,7 @@ esxUtil_ParseUri(esxUtil_ParsedUri **parsedUri, virURIPtr uri) tmp = queryParam->value; } - (*parsedUri)->proxy_hostname = strdup(tmp); - - if ((*parsedUri)->proxy_hostname == NULL) { + if (VIR_STRDUP((*parsedUri)->proxy_hostname, tmp) < 0) { virReportOOMError(); goto cleanup; } @@ -171,22 +165,15 @@ esxUtil_ParseUri(esxUtil_ParsedUri **parsedUri, virURIPtr uri) } } - if (uri->path != NULL) { - (*parsedUri)->path = strdup(uri->path); - - if ((*parsedUri)->path == NULL) { - virReportOOMError(); - goto cleanup; - } + if (uri->path && VIR_STRDUP((*parsedUri)->path, uri->path) < 0) { + virReportOOMError(); + goto cleanup; } - if ((*parsedUri)->transport == NULL) { - (*parsedUri)->transport = strdup("https"); - - if ((*parsedUri)->transport == NULL) { - virReportOOMError(); - goto cleanup; - } + if (!(*parsedUri)->transport && + VIR_STRDUP((*parsedUri)->transport, "https") < 0) { + virReportOOMError(); + goto cleanup; } result = 0; @@ -494,11 +481,11 @@ esxUtil_ReplaceSpecialWindowsPathChars(char *string) char * esxUtil_EscapeDatastoreItem(const char *string) { - char *replaced = strdup(string); + char *replaced; char *escaped1; char *escaped2 = NULL; - if (replaced == NULL) { + if (VIR_STRDUP(replaced, string) < 0) { virReportOOMError(); return NULL; } diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c index ee48159..7245fbb 100644 --- a/src/esx/esx_vi.c +++ b/src/esx/esx_vi.c @@ -947,9 +947,7 @@ esxVI_Context_LookupManagedObjects(esxVI_Context *ctx) return -1; } - ctx->datacenterPath = strdup(ctx->datacenter->name); - - if (ctx->datacenterPath == NULL) { + if (VIR_STRDUP(ctx->datacenterPath, ctx->datacenter->name) < 0) { virReportOOMError(); return -1; } @@ -967,9 +965,7 @@ esxVI_Context_LookupManagedObjects(esxVI_Context *ctx) return -1; } - ctx->computeResourcePath = strdup(ctx->computeResource->name); - - if (ctx->computeResourcePath == NULL) { + if (VIR_STRDUP(ctx->computeResourcePath, ctx->computeResource->name) < 0) { virReportOOMError(); return -1; } @@ -981,9 +977,7 @@ esxVI_Context_LookupManagedObjects(esxVI_Context *ctx) return -1; } - ctx->hostSystemName = strdup(ctx->hostSystem->name); - - if (ctx->hostSystemName == NULL) { + if (VIR_STRDUP(ctx->hostSystemName, ctx->hostSystem->name) < 0) { virReportOOMError(); return -1; } @@ -1003,9 +997,7 @@ esxVI_Context_LookupManagedObjectsByPath(esxVI_Context *ctx, const char *path) esxVI_ManagedObjectReference *root = NULL; esxVI_Folder *folder = NULL; - tmp = strdup(path); - - if (tmp == NULL) { + if (VIR_STRDUP(tmp, path) < 0) { virReportOOMError(); goto cleanup; } @@ -1160,9 +1152,7 @@ esxVI_Context_LookupManagedObjectsByPath(esxVI_Context *ctx, const char *path) goto cleanup; } - ctx->hostSystemName = strdup(previousItem); - - if (ctx->hostSystemName == NULL) { + if (VIR_STRDUP(ctx->hostSystemName, previousItem) < 0) { virReportOOMError(); goto cleanup; } @@ -2498,9 +2488,7 @@ esxVI_GetVirtualMachineIdentity(esxVI_ObjectContent *virtualMachine, goto failure; } - *name = strdup(dynamicProperty->val->string); - - if (*name == NULL) { + if (VIR_STRDUP(*name, dynamicProperty->val->string) < 0) { virReportOOMError(); goto failure; } @@ -2611,9 +2599,7 @@ esxVI_GetSnapshotTreeNames(esxVI_VirtualMachineSnapshotTree *snapshotTreeList, snapshotTree != NULL && count < nameslen; snapshotTree = snapshotTree->_next) { if (!(leaves && snapshotTree->childSnapshotList)) { - names[count] = strdup(snapshotTree->name); - - if (names[count] == NULL) { + if (VIR_STRDUP(names[count], snapshotTree->name) < 0) { virReportOOMError(); goto failure; } @@ -4388,9 +4374,7 @@ esxVI_WaitForTaskCompletion(esxVI_Context *ctx, return -1; } - version = strdup(""); - - if (version == NULL) { + if (VIR_STRDUP(version, "") < 0) { virReportOOMError(); return -1; } @@ -4469,9 +4453,7 @@ esxVI_WaitForTaskCompletion(esxVI_Context *ctx, } VIR_FREE(version); - version = strdup(updateSet->version); - - if (version == NULL) { + if (VIR_STRDUP(version, updateSet->version) < 0) { virReportOOMError(); goto cleanup; } @@ -4523,19 +4505,14 @@ esxVI_WaitForTaskCompletion(esxVI_Context *ctx, } if (taskInfo->error == NULL) { - *errorMessage = strdup(_("Unknown error")); - - if (*errorMessage == NULL) { + if (VIR_STRDUP(*errorMessage, _("Unknown error")) < 0) { virReportOOMError(); goto cleanup; } } else if (taskInfo->error->localizedMessage == NULL) { - *errorMessage = strdup(taskInfo->error->fault->_actualType); - - if (*errorMessage == NULL) { + if (VIR_STRDUP(*errorMessage, taskInfo->error->fault->_actualType) < 0) virReportOOMError(); goto cleanup; - } } else { if (virAsprintf(errorMessage, "%s - %s", taskInfo->error->fault->_actualType, @@ -4984,9 +4961,7 @@ esxVI_LookupStoragePoolNameByScsiLunKey(esxVI_Context *ctx, hostScsiTopologyLun != NULL; hostScsiTopologyLun = hostScsiTopologyLun->_next) { if (STREQ(hostScsiTopologyLun->scsiLun, key)) { - *poolName = strdup(candidate->iScsiName); - - if (*poolName == NULL) { + if (VIR_STRDUP(*poolName, candidate->iScsiName) < 0) { virReportOOMError(); goto cleanup; } diff --git a/src/esx/esx_vi_types.c b/src/esx/esx_vi_types.c index 7f40308..df2866d 100644 --- a/src/esx/esx_vi_types.c +++ b/src/esx/esx_vi_types.c @@ -1050,13 +1050,9 @@ esxVI_AnyType_Deserialize(xmlNodePtr node, esxVI_AnyType **anyType) (*anyType)->value = (char *)xmlNodeListGetString(node->doc, node->children, 1); - if ((*anyType)->value == NULL) { - (*anyType)->value = strdup(""); - - if ((*anyType)->value == NULL) { - virReportOOMError(); - goto failure; - } + if (!(*anyType)->value && VIR_STRDUP((*anyType)->value, "") < 0) { + virReportOOMError(); + goto failure; } #define _DESERIALIZE_NUMBER(_type, _xsdType, _name, _min, _max) \ @@ -1177,9 +1173,7 @@ esxVI_String_AppendValueToList(esxVI_String **stringList, const char *value) return -1; } - string->value = strdup(value); - - if (string->value == NULL) { + if (VIR_STRDUP(string->value, value) < 0) { virReportOOMError(); goto failure; } @@ -1244,9 +1238,7 @@ esxVI_String_DeepCopyValue(char **dest, const char *src) return 0; } - *dest = strdup(src); - - if (*dest == NULL) { + if (VIR_STRDUP(*dest, src) < 0) { virReportOOMError(); return -1; } @@ -1328,9 +1320,7 @@ esxVI_String_DeserializeValue(xmlNodePtr node, char **value) *value = (char *)xmlNodeListGetString(node->doc, node->children, 1); if (*value == NULL) { - *value = strdup(""); - - if (*value == NULL) { + if (VIR_STRDUP(*value, "") < 0) { virReportOOMError(); return -1; } -- 1.8.1.5

--- src/hyperv/hyperv_driver.c | 35 +++++++++++------------------------ src/hyperv/hyperv_util.c | 15 +++++---------- 2 files changed, 16 insertions(+), 34 deletions(-) diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c index 7031fdb..23d30e1 100644 --- a/src/hyperv/hyperv_driver.c +++ b/src/hyperv/hyperv_driver.c @@ -140,9 +140,7 @@ hypervConnectOpen(virConnectPtr conn, virConnectAuthPtr auth, unsigned int flags /* Request credentials */ if (conn->uri->user != NULL) { - username = strdup(conn->uri->user); - - if (username == NULL) { + if (VIR_STRDUP(username, conn->uri->user) < 0) { virReportOOMError(); goto cleanup; } @@ -257,9 +255,7 @@ hypervConnectGetHostname(virConnectPtr conn) goto cleanup; } - hostname = strdup(computerSystem->data->DNSHostName); - - if (hostname == NULL) { + if (VIR_STRDUP(hostname, computerSystem->data->DNSHostName) < 0) { virReportOOMError(); goto cleanup; } @@ -652,9 +648,9 @@ hypervDomainDestroy(virDomainPtr domain) static char * hypervDomainGetOSType(virDomainPtr domain ATTRIBUTE_UNUSED) { - char *osType = strdup("hvm"); + char *osType; - if (osType == NULL) { + if (VIR_STRDUP(osType, "hvm") < 0) { virReportOOMError(); return NULL; } @@ -908,20 +904,15 @@ hypervDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) return NULL; } - def->name = strdup(computerSystem->data->ElementName); - - if (def->name == NULL) { + if (VIR_STRDUP(def->name, computerSystem->data->ElementName) < 0) { virReportOOMError(); goto cleanup; } - if (virtualSystemSettingData->data->Notes != NULL) { - def->description = strdup(virtualSystemSettingData->data->Notes); - - if (def->description == NULL) { - virReportOOMError(); - goto cleanup; - } + if (virtualSystemSettingData->data->Notes && + VIR_STRDUP(def->description, virtualSystemSettingData->data->Notes) < 0) { + virReportOOMError(); + goto cleanup; } def->mem.max_balloon = memorySettingData->data->Limit * 1024; /* megabyte to kilobyte */ @@ -930,9 +921,7 @@ hypervDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) def->vcpus = processorSettingData->data->VirtualQuantity; def->maxvcpus = processorSettingData->data->VirtualQuantity; - def->os.type = strdup("hvm"); - - if (def->os.type == NULL) { + if (VIR_STRDUP(def->os.type, "hvm") < 0) { virReportOOMError(); goto cleanup; } @@ -981,9 +970,7 @@ hypervConnectListDefinedDomains(virConnectPtr conn, char **const names, int maxn for (computerSystem = computerSystemList; computerSystem != NULL; computerSystem = computerSystem->next) { - names[count] = strdup(computerSystem->data->ElementName); - - if (names[count] == NULL) { + if (VIR_STRDUP(names[count], computerSystem->data->ElementName) < 0) { virReportOOMError(); goto cleanup; } diff --git a/src/hyperv/hyperv_util.c b/src/hyperv/hyperv_util.c index a55b939..6d5f79a 100644 --- a/src/hyperv/hyperv_util.c +++ b/src/hyperv/hyperv_util.c @@ -27,6 +27,7 @@ #include "viralloc.h" #include "virlog.h" #include "viruuid.h" +#include "virstring.h" #include "hyperv_private.h" #include "hyperv_util.h" @@ -56,9 +57,7 @@ hypervParseUri(hypervParsedUri **parsedUri, virURIPtr uri) if (STRCASEEQ(queryParam->name, "transport")) { VIR_FREE((*parsedUri)->transport); - (*parsedUri)->transport = strdup(queryParam->value); - - if ((*parsedUri)->transport == NULL) { + if (VIR_STRDUP((*parsedUri)->transport, queryParam->value) < 0) { virReportOOMError(); goto cleanup; } @@ -77,13 +76,9 @@ hypervParseUri(hypervParsedUri **parsedUri, virURIPtr uri) } } - if ((*parsedUri)->transport == NULL) { - (*parsedUri)->transport = strdup("https"); - - if ((*parsedUri)->transport == NULL) { - virReportOOMError(); - goto cleanup; - } + if (!(*parsedUri)->transport && VIR_STRDUP((*parsedUri)->transport, "https") < 0) { + virReportOOMError(); + goto cleanup; } result = 0; -- 1.8.1.5

--- src/libxl/libxl_conf.c | 59 ++++++++++++++++++++++-------------------------- src/libxl/libxl_driver.c | 13 ++++++----- 2 files changed, 34 insertions(+), 38 deletions(-) diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index 7e0753a..19d40f3 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -302,7 +302,7 @@ libxlMakeDomCreateInfo(libxlDriverPrivatePtr driver, else c_info->type = LIBXL_DOMAIN_TYPE_PV; - if ((c_info->name = strdup(def->name)) == NULL) { + if (VIR_STRDUP(c_info->name, def->name) < 0) { virReportOOMError(); goto error; } @@ -403,7 +403,7 @@ libxlMakeDomBuildInfo(virDomainDefPtr def, libxl_domain_config *d_config) else { bootorder[def->os.nBootDevs] = '\0'; } - if ((b_info->u.hvm.boot = strdup(bootorder)) == NULL) { + if (VIR_STRDUP(b_info->u.hvm.boot, bootorder) < 0) { virReportOOMError(); goto error; } @@ -418,36 +418,33 @@ libxlMakeDomBuildInfo(virDomainDefPtr def, libxl_domain_config *d_config) b_info->shadow_memkb = 4 * (256 * libxl_bitmap_count_set(&b_info->avail_vcpus) + 2 * (b_info->max_memkb / 1024)); } else { - if (def->os.bootloader) { - if ((b_info->u.pv.bootloader = strdup(def->os.bootloader)) == NULL) { - virReportOOMError(); - goto error; - } + if (def->os.bootloader && + VIR_STRDUP(b_info->u.pv.bootloader, def->os.bootloader) < 0) { + virReportOOMError(); + goto error; } if (def->os.bootloaderArgs) { if (!(b_info->u.pv.bootloader_args = virStringSplit(def->os.bootloaderArgs, " \t\n", 0))) goto error; } - if (def->os.cmdline) { - if ((b_info->u.pv.cmdline = strdup(def->os.cmdline)) == NULL) { - virReportOOMError(); - goto error; - } + if (def->os.cmdline && + VIR_STRDUP(b_info->u.pv.cmdline, def->os.cmdline) < 0) { + virReportOOMError(); + goto error; } if (def->os.kernel) { - /* libxl_init_build_info() sets kernel.path = strdup("hvmloader") */ + /* libxl_init_build_info() sets VIR_STRDUP(kernel.path, "hvmloader") */ VIR_FREE(b_info->u.pv.kernel); - if ((b_info->u.pv.kernel = strdup(def->os.kernel)) == NULL) { + if (VIR_STRDUP(b_info->u.pv.kernel, def->os.kernel) < 0) { virReportOOMError(); goto error; } } - if (def->os.initrd) { - if ((b_info->u.pv.ramdisk = strdup(def->os.initrd)) == NULL) { - virReportOOMError(); - goto error; - } + if (def->os.initrd && + VIR_STRDUP(b_info->u.pv.ramdisk, def->os.initrd) < 0) { + virReportOOMError(); + goto error; } } @@ -461,12 +458,12 @@ error: int libxlMakeDisk(virDomainDiskDefPtr l_disk, libxl_device_disk *x_disk) { - if (l_disk->src && (x_disk->pdev_path = strdup(l_disk->src)) == NULL) { + if (l_disk->src && VIR_STRDUP(x_disk->pdev_path, l_disk->src) < 0) { virReportOOMError(); return -1; } - if (l_disk->dst && (x_disk->vdev = strdup(l_disk->dst)) == NULL) { + if (l_disk->dst && VIR_STRDUP(x_disk->vdev, l_disk->dst) < 0) { virReportOOMError(); return -1; } @@ -575,7 +572,7 @@ 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 = strdup(l_nic->model)) == NULL) { + if (VIR_STRDUP(x_nic->model, l_nic->model) < 0) { virReportOOMError(); return -1; } @@ -584,19 +581,19 @@ libxlMakeNic(virDomainNetDefPtr l_nic, libxl_device_nic *x_nic) x_nic->nictype = LIBXL_NIC_TYPE_VIF; } - if (l_nic->ifname && (x_nic->ifname = strdup(l_nic->ifname)) == NULL) { + if (l_nic->ifname && VIR_STRDUP(x_nic->ifname, l_nic->ifname) < 0) { virReportOOMError(); return -1; } if (l_nic->type == VIR_DOMAIN_NET_TYPE_BRIDGE) { if (l_nic->data.bridge.brname && - (x_nic->bridge = strdup(l_nic->data.bridge.brname)) == NULL) { + VIR_STRDUP(x_nic->bridge, l_nic->data.bridge.brname) < 0) { virReportOOMError(); return -1; } if (l_nic->script && - (x_nic->script = strdup(l_nic->script)) == NULL) { + VIR_STRDUP(x_nic->script, l_nic->script) < 0) { virReportOOMError(); return -1; } @@ -656,13 +653,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 = strdup(l_vfb->data.sdl.display)) == NULL) { + VIR_STRDUP(x_vfb->sdl.display, l_vfb->data.sdl.display) < 0) { virReportOOMError(); return -1; } if (l_vfb->data.sdl.xauth && - (x_vfb->sdl.xauthority = - strdup(l_vfb->data.sdl.xauth)) == NULL) { + VIR_STRDUP(x_vfb->sdl.xauthority, l_vfb->data.sdl.xauth) < 0) { virReportOOMError(); return -1; } @@ -686,16 +682,15 @@ libxlMakeVfb(libxlDriverPrivatePtr driver, listenAddr = virDomainGraphicsListenGetAddress(l_vfb, 0); if (listenAddr) { - /* libxl_device_vfb_init() does strdup("127.0.0.1") */ + /* libxl_device_vfb_init() does VIR_STRDUP(("127.0.0.1") */ VIR_FREE(x_vfb->vnc.listen); - if ((x_vfb->vnc.listen = strdup(listenAddr)) == NULL) { + if (VIR_STRDUP(x_vfb->vnc.listen, listenAddr) < 0) { virReportOOMError(); return -1; } } if (l_vfb->data.vnc.keymap && - (x_vfb->keymap = - strdup(l_vfb->data.vnc.keymap)) == NULL) { + VIR_STRDUP(x_vfb->keymap, l_vfb->data.vnc.keymap) < 0) { virReportOOMError(); return -1; } diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 7361743..a73aff5 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -1881,7 +1881,7 @@ libxlDomainGetOSType(virDomainPtr dom) goto cleanup; } - if (!(type = strdup(vm->def->os.type))) + if (VIR_STRDUP(type, vm->def->os.type) < 0) virReportOOMError(); cleanup: @@ -3856,6 +3856,7 @@ libxlDomainGetSchedulerType(virDomainPtr dom, int *nparams) libxlDomainObjPrivatePtr priv; virDomainObjPtr vm; char * ret = NULL; + int rc; libxl_scheduler sched_id; libxlDriverLock(driver); @@ -3879,18 +3880,18 @@ libxlDomainGetSchedulerType(virDomainPtr dom, int *nparams) *nparams = 0; switch (sched_id) { case LIBXL_SCHEDULER_SEDF: - ret = strdup("sedf"); + rc = VIR_STRDUP(ret, "sedf"); break; case LIBXL_SCHEDULER_CREDIT: - ret = strdup("credit"); + rc = VIR_STRDUP(ret, "credit"); if (nparams) *nparams = XEN_SCHED_CREDIT_NPARAM; break; case LIBXL_SCHEDULER_CREDIT2: - ret = strdup("credit2"); + rc = VIR_STRDUP(ret, "credit2"); break; case LIBXL_SCHEDULER_ARINC653: - ret = strdup("arinc653"); + rc = VIR_STRDUP(ret, "arinc653"); break; default: virReportError(VIR_ERR_INTERNAL_ERROR, @@ -3899,7 +3900,7 @@ libxlDomainGetSchedulerType(virDomainPtr dom, int *nparams) goto cleanup; } - if (!ret) + if (rc < 0) virReportOOMError(); cleanup: -- 1.8.1.5

--- src/locking/lock_daemon.c | 12 ++++++------ src/locking/lock_daemon_config.c | 8 ++++---- src/locking/lock_daemon_dispatch.c | 3 ++- src/locking/lock_driver_lockd.c | 22 +++++++++++----------- src/locking/lock_driver_sanlock.c | 8 ++++---- src/locking/lock_manager.c | 2 +- 6 files changed, 28 insertions(+), 27 deletions(-) diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c index 0d8ef39..2ace573 100644 --- a/src/locking/lock_daemon.c +++ b/src/locking/lock_daemon.c @@ -370,7 +370,7 @@ virLockDaemonPidFilePath(bool privileged, char **pidfile) { if (privileged) { - if (!(*pidfile = strdup(LOCALSTATEDIR "/run/virtlockd.pid"))) + if (VIR_STRDUP(*pidfile, LOCALSTATEDIR "/run/virtlockd.pid") < 0) goto no_memory; } else { char *rundir = NULL; @@ -408,7 +408,7 @@ virLockDaemonUnixSocketPaths(bool privileged, char **sockfile) { if (privileged) { - if (!(*sockfile = strdup(LOCALSTATEDIR "/run/libvirt/virtlockd-sock"))) + if (VIR_STRDUP(*sockfile, LOCALSTATEDIR "/run/libvirt/virtlockd-sock") < 0) goto no_memory; } else { char *rundir = NULL; @@ -867,7 +867,7 @@ virLockDaemonClientNewPostExecRestart(virNetServerClientPtr client, _("Missing ownerName data in JSON document")); goto error; } - if (!(priv->ownerName = strdup(ownerName))) { + if (VIR_STRDUP(priv->ownerName, ownerName) < 0) { virReportOOMError(); goto error; } @@ -1221,13 +1221,13 @@ int main(int argc, char **argv) { case 'p': VIR_FREE(pid_file); - if (!(pid_file = strdup(optarg))) + if (VIR_STRDUP(pid_file, optarg) < 0) exit(EXIT_FAILURE); break; case 'f': VIR_FREE(remote_config_file); - if (!(remote_config_file = strdup(optarg))) + if (VIR_STRDUP(remote_config_file, optarg) < 0) exit(EXIT_FAILURE); break; @@ -1312,7 +1312,7 @@ int main(int argc, char **argv) { /* Ensure the rundir exists (on tmpfs on some systems) */ if (privileged) { - if (!(run_dir = strdup(LOCALSTATEDIR "/run/libvirt"))) { + if (VIR_STRDUP(run_dir, LOCALSTATEDIR "/run/libvirt") < 0) { virReportOOMError(); goto cleanup; } diff --git a/src/locking/lock_daemon_config.c b/src/locking/lock_daemon_config.c index c3d59bd..972e7cf 100644 --- a/src/locking/lock_daemon_config.c +++ b/src/locking/lock_daemon_config.c @@ -53,8 +53,8 @@ checkType(virConfValuePtr p, const char *filename, } /* If there is no config data for the key, #var_name, then do nothing. - If there is valid data of type VIR_CONF_STRING, and strdup succeeds, - store the result in var_name. Otherwise, (i.e. invalid type, or strdup + If there is valid data of type VIR_CONF_STRING, and VIR_STRDUP succeeds, + store the result in var_name. Otherwise, (i.e. invalid type, or VIR_STRDUP failure), give a diagnostic and "goto" the cleanup-and-fail label. */ #define GET_CONF_STR(conf, filename, var_name) \ do { \ @@ -63,7 +63,7 @@ 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 = strdup(p->str))) { \ + if (VIR_STRDUP(data->var_name, p->str) < 0) { \ virReportOOMError(); \ goto error; \ } \ @@ -85,7 +85,7 @@ int virLockDaemonConfigFilePath(bool privileged, char **configfile) { if (privileged) { - if (!(*configfile = strdup(SYSCONFDIR "/libvirt/virtlockd.conf"))) + if (VIR_STRDUP(*configfile, SYSCONFDIR "/libvirt/virtlockd.conf") < 0) goto no_memory; } else { char *configdir = NULL; diff --git a/src/locking/lock_daemon_dispatch.c b/src/locking/lock_daemon_dispatch.c index 8a92802..472b6e6 100644 --- a/src/locking/lock_daemon_dispatch.c +++ b/src/locking/lock_daemon_dispatch.c @@ -30,6 +30,7 @@ #include "lock_protocol.h" #include "lock_daemon_dispatch_stubs.h" #include "virerror.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_RPC @@ -275,7 +276,7 @@ virLockSpaceProtocolDispatchRegister(virNetServerPtr server ATTRIBUTE_UNUSED, goto cleanup; } - if (!(priv->ownerName = strdup(args->owner.name))) { + if (VIR_STRDUP(priv->ownerName, args->owner.name) < 0) { virReportOOMError(); goto cleanup; } diff --git a/src/locking/lock_driver_lockd.c b/src/locking/lock_driver_lockd.c index 28a4f15..41ff13f 100644 --- a/src/locking/lock_driver_lockd.c +++ b/src/locking/lock_driver_lockd.c @@ -129,7 +129,7 @@ static int virLockManagerLockDaemonLoadConfig(const char *configFile) CHECK_TYPE("file_lockspace_dir", VIR_CONF_STRING); if (p && p->str) { VIR_FREE(driver->fileLockSpaceDir); - if (!(driver->fileLockSpaceDir = strdup(p->str))) { + if (VIR_STRDUP(driver->fileLockSpaceDir, p->str) < 0) { virReportOOMError(); virConfFree(conf); return -1; @@ -140,7 +140,7 @@ static int virLockManagerLockDaemonLoadConfig(const char *configFile) CHECK_TYPE("lvm_lockspace_dir", VIR_CONF_STRING); if (p && p->str) { VIR_FREE(driver->lvmLockSpaceDir); - if (!(driver->lvmLockSpaceDir = strdup(p->str))) { + if (VIR_STRDUP(driver->lvmLockSpaceDir, p->str) < 0) { virReportOOMError(); virConfFree(conf); return -1; @@ -151,7 +151,7 @@ static int virLockManagerLockDaemonLoadConfig(const char *configFile) CHECK_TYPE("scsi_lockspace_dir", VIR_CONF_STRING); if (p && p->str) { VIR_FREE(driver->scsiLockSpaceDir); - if (!(driver->scsiLockSpaceDir = strdup(p->str))) { + if (VIR_STRDUP(driver->scsiLockSpaceDir, p->str) < 0) { virReportOOMError(); virConfFree(conf); return -1; @@ -174,7 +174,7 @@ static char *virLockManagerLockDaemonPath(bool privileged) { char *path; if (privileged) { - if (!(path = strdup(LOCALSTATEDIR "/run/libvirt/virtlockd-sock"))) { + if (VIR_STRDUP(path, LOCALSTATEDIR "/run/libvirt/virtlockd-sock") < 0) { virReportOOMError(); return NULL; } @@ -468,7 +468,7 @@ 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 = strdup(params[i].value.str))) { + if (VIR_STRDUP(priv->name, params[i].value.str) < 0) { virReportOOMError(); return -1; } @@ -588,7 +588,7 @@ static int virLockManagerLockDaemonAddResource(virLockManagerPtr lock, if (newName) { VIR_DEBUG("Got an LVM UUID %s for %s", newName, name); - if (!(newLockspace = strdup(driver->lvmLockSpaceDir))) + if (VIR_STRDUP(newLockspace, driver->lvmLockSpaceDir) < 0) goto no_memory; autoCreate = true; break; @@ -605,7 +605,7 @@ static int virLockManagerLockDaemonAddResource(virLockManagerPtr lock, if (newName) { VIR_DEBUG("Got an SCSI ID %s for %s", newName, name); - if (!(newLockspace = strdup(driver->scsiLockSpaceDir))) + if (VIR_STRDUP(newLockspace, driver->scsiLockSpaceDir) < 0) goto no_memory; autoCreate = true; break; @@ -615,16 +615,16 @@ static int virLockManagerLockDaemonAddResource(virLockManagerPtr lock, } if (driver->fileLockSpaceDir) { - if (!(newLockspace = strdup(driver->fileLockSpaceDir))) + if (VIR_STRDUP(newLockspace, driver->fileLockSpaceDir) < 0) goto no_memory; if (!(newName = virLockManagerLockDaemonDiskLeaseName(name))) goto no_memory; autoCreate = true; VIR_DEBUG("Using indirect lease %s for %s", newName, name); } else { - if (!(newLockspace = strdup(""))) + if (VIR_STRDUP(newLockspace, "") < 0) goto no_memory; - if (!(newName = strdup(name))) + if (VIR_STRDUP(newName, name) < 0) goto no_memory; VIR_DEBUG("Using direct lease for %s", name); } @@ -662,7 +662,7 @@ static int virLockManagerLockDaemonAddResource(virLockManagerPtr lock, virReportOOMError(); return -1; } - if (!(newName = strdup(name))) + if (VIR_STRDUP(newName, name) < 0) goto no_memory; } break; diff --git a/src/locking/lock_driver_sanlock.c b/src/locking/lock_driver_sanlock.c index 48c6d56..23e9ce9 100644 --- a/src/locking/lock_driver_sanlock.c +++ b/src/locking/lock_driver_sanlock.c @@ -128,7 +128,7 @@ static int virLockManagerSanlockLoadConfig(const char *configFile) CHECK_TYPE("disk_lease_dir", VIR_CONF_STRING); if (p && p->str) { VIR_FREE(driver->autoDiskLeasePath); - if (!(driver->autoDiskLeasePath = strdup(p->str))) { + if (VIR_STRDUP(driver->autoDiskLeasePath, p->str) < 0) { virReportOOMError(); virConfFree(conf); return -1; @@ -149,7 +149,7 @@ static int virLockManagerSanlockLoadConfig(const char *configFile) p = virConfGetValue(conf, "user"); CHECK_TYPE("user", VIR_CONF_STRING); if (p) { - if (!(tmp = strdup(p->str))) { + if (VIR_STRDUP(tmp, p->str) < 0) { virReportOOMError(); virConfFree(conf); return -1; @@ -166,7 +166,7 @@ static int virLockManagerSanlockLoadConfig(const char *configFile) p = virConfGetValue(conf, "group"); CHECK_TYPE("group", VIR_CONF_STRING); if (p) { - if (!(tmp = strdup(p->str))) { + if (VIR_STRDUP(tmp, p->str) < 0) { virReportOOMError(); virConfFree(conf); return -1; @@ -407,7 +407,7 @@ static int virLockManagerSanlockInit(unsigned int version, driver->autoDiskLease = false; driver->user = (uid_t) -1; driver->group = (gid_t) -1; - if (!(driver->autoDiskLeasePath = strdup(LOCALSTATEDIR "/lib/libvirt/sanlock"))) { + if (VIR_STRDUP(driver->autoDiskLeasePath, LOCALSTATEDIR "/lib/libvirt/sanlock") < 0) { VIR_FREE(driver); virReportOOMError(); goto error; diff --git a/src/locking/lock_manager.c b/src/locking/lock_manager.c index 82bbe6b..aba9161 100644 --- a/src/locking/lock_manager.c +++ b/src/locking/lock_manager.c @@ -194,7 +194,7 @@ virLockManagerPluginPtr virLockManagerPluginNew(const char *name, plugin->driver = driver; plugin->handle = handle; plugin->refs = 1; - if (!(plugin->name = strdup(name))) { + if (VIR_STRDUP(plugin->name, name) < 0) { virReportOOMError(); goto cleanup; } -- 1.8.1.5

--- src/lxc/lxc_cgroup.c | 2 +- src/lxc/lxc_conf.c | 18 +++++++++--------- src/lxc/lxc_container.c | 8 ++++---- src/lxc/lxc_controller.c | 6 +++--- src/lxc/lxc_driver.c | 7 ++----- src/lxc/lxc_process.c | 4 ++-- 6 files changed, 21 insertions(+), 24 deletions(-) diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c index bc3b0d1..2df8ba8 100644 --- a/src/lxc/lxc_cgroup.c +++ b/src/lxc/lxc_cgroup.c @@ -538,7 +538,7 @@ virCgroupPtr virLXCCgroupCreate(virDomainDefPtr def, bool startup) goto cleanup; } - if (!(res->partition = strdup("/machine"))) { + if (VIR_STRDUP(res->partition, "/machine") < 0) { virReportOOMError(); VIR_FREE(res); goto cleanup; diff --git a/src/lxc/lxc_conf.c b/src/lxc/lxc_conf.c index 13c0d97..2971c08 100644 --- a/src/lxc/lxc_conf.c +++ b/src/lxc/lxc_conf.c @@ -37,7 +37,7 @@ #include "configmake.h" #include "lxc_container.h" #include "virnodesuspend.h" - +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_LXC @@ -119,9 +119,9 @@ virCapsPtr lxcCapsInit(virLXCDriverPtr driver) if (VIR_ALLOC(caps->host.secModels) < 0) goto no_memory; caps->host.nsecModels = 1; - if (!(caps->host.secModels[0].model = strdup(model))) + if (VIR_STRDUP(caps->host.secModels[0].model, model) < 0) goto no_memory; - if (!(caps->host.secModels[0].doi = strdup(doi))) + if (VIR_STRDUP(caps->host.secModels[0].doi, doi) < 0) goto no_memory; } @@ -161,17 +161,17 @@ int lxcLoadDriverConfig(virLXCDriverPtr driver) driver->securityRequireConfined = false; /* Set the container configuration directory */ - if ((driver->configDir = strdup(LXC_CONFIG_DIR)) == NULL) + if (VIR_STRDUP(driver->configDir,LXC_CONFIG_DIR) < 0) goto no_memory; - if ((driver->stateDir = strdup(LXC_STATE_DIR)) == NULL) + if (VIR_STRDUP(driver->stateDir, LXC_STATE_DIR) < 0) goto no_memory; - if ((driver->logDir = strdup(LXC_LOG_DIR)) == NULL) + if (VIR_STRDUP(driver->logDir, LXC_LOG_DIR) < 0) goto no_memory; - if ((driver->autostartDir = strdup(LXC_AUTOSTART_DIR)) == NULL) + if (VIR_STRDUP(driver->autostartDir, LXC_AUTOSTART_DIR) < 0) goto no_memory; - if ((filename = strdup(SYSCONFDIR "/libvirt/lxc.conf")) == NULL) + if (VIR_STRDUP(filename, SYSCONFDIR "/libvirt/lxc.conf") < 0) goto no_memory; /* Avoid error from non-existant or unreadable file. */ @@ -196,7 +196,7 @@ int lxcLoadDriverConfig(virLXCDriverPtr driver) p = virConfGetValue(conf, "security_driver"); CHECK_TYPE("security_driver", VIR_CONF_STRING); if (p && p->str) { - if (!(driver->securityDriverName = strdup(p->str))) { + if (VIR_STRDUP(driver->securityDriverName, p->str) < 0) { virReportOOMError(); virConfFree(conf); return -1; diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c index ff4069a..6bf9916 100644 --- a/src/lxc/lxc_container.c +++ b/src/lxc/lxc_container.c @@ -439,7 +439,7 @@ static int lxcContainerGetSubtree(const char *prefix, virReportOOMError(); goto cleanup; } - if (!(mounts[nmounts] = strdup(mntent.mnt_dir))) { + if (VIR_STRDUP(mounts[nmounts], mntent.mnt_dir) < 0) { virReportOOMError(); goto cleanup; } @@ -1041,7 +1041,7 @@ lxcContainerMountDetectFilesystem(const char *src, char **type) goto cleanup; } - if (!(*type = strdup(data))) { + if (VIR_STRDUP(*type, data) < 0) { virReportOOMError(); goto cleanup; } @@ -1948,13 +1948,13 @@ static int lxcContainerChild(void *data) goto cleanup; } } else { - if (!(ttyPath = strdup(argv->ttyPaths[0]))) { + if (VIR_STRDUP(ttyPath, argv->ttyPaths[0]) < 0) { virReportOOMError(); goto cleanup; } } } else { - if (!(ttyPath = strdup("/dev/null"))) { + if (VIR_STRDUP(ttyPath, "/dev/null") < 0) { virReportOOMError(); goto cleanup; } diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c index f1800eb..855a6d1 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c @@ -156,7 +156,7 @@ static virLXCControllerPtr virLXCControllerNew(const char *name) ctrl->timerShutdown = -1; ctrl->firstClient = true; - if (!(ctrl->name = strdup(name))) + if (VIR_STRDUP(ctrl->name, name) < 0) goto no_memory; if ((caps = lxcCapsInit(NULL)) == NULL) @@ -1566,7 +1566,7 @@ int main(int argc, char *argv[]) break; case 'n': - if ((name = strdup(optarg)) == NULL) { + if (VIR_STRDUP(name, optarg) < 0) { virReportOOMError(); goto cleanup; } @@ -1577,7 +1577,7 @@ int main(int argc, char *argv[]) virReportOOMError(); goto cleanup; } - if ((veths[nveths++] = strdup(optarg)) == NULL) { + if (VIR_STRDUP(veths[nveths++], optarg) < 0) { virReportOOMError(); goto cleanup; } diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 84a97de..3a1bbbf 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -626,9 +626,7 @@ static char *lxcDomainGetOSType(virDomainPtr dom) goto cleanup; } - ret = strdup(vm->def->os.type); - - if (ret == NULL) + if (VIR_STRDUP(ret, vm->def->os.type) < 0) virReportOOMError(); cleanup: @@ -1629,8 +1627,7 @@ static char *lxcDomainGetSchedulerType(virDomainPtr dom, *nparams = 3; } - ret = strdup("posix"); - if (!ret) + if (VIR_STRDUP(ret, "posix") < 0) virReportOOMError(); cleanup: diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index b10e81c..5c36fae 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -996,8 +996,8 @@ virLXCProcessEnsureRootFS(virDomainObjPtr vm) root->type = VIR_DOMAIN_FS_TYPE_MOUNT; - if (!(root->src = strdup("/")) || - !(root->dst = strdup("/"))) + if (VIR_STRDUP(root->src, "/") < 0 || + VIR_STRDUP(root->dst, "/") < 0) goto no_memory; if (VIR_INSERT_ELEMENT(vm->def->fss, -- 1.8.1.5

On 04/29/2013 09:50 AM, Michal Privoznik wrote:
--- src/lxc/lxc_cgroup.c | 2 +- src/lxc/lxc_conf.c | 18 +++++++++--------- src/lxc/lxc_container.c | 8 ++++---- src/lxc/lxc_controller.c | 6 +++--- src/lxc/lxc_driver.c | 7 ++----- src/lxc/lxc_process.c | 4 ++-- 6 files changed, 21 insertions(+), 24 deletions(-)
@@ -161,17 +161,17 @@ int lxcLoadDriverConfig(virLXCDriverPtr driver) driver->securityRequireConfined = false;
/* Set the container configuration directory */ - if ((driver->configDir = strdup(LXC_CONFIG_DIR)) == NULL) + if (VIR_STRDUP(driver->configDir,LXC_CONFIG_DIR) < 0)
Missing a space ^^^
goto no_memory;

--- src/network/bridge_driver.c | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index b561e85..1a4029c 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -378,7 +378,7 @@ networkStateInitialize(bool privileged, "%s/log/libvirt/qemu", LOCALSTATEDIR) == -1) goto out_of_memory; - if ((base = strdup(SYSCONFDIR "/libvirt")) == NULL) + if (VIR_STRDUP(base, SYSCONFDIR "/libvirt") < 0) goto out_of_memory; } else { char *userdir = virGetUserCacheDirectory(); @@ -2820,7 +2820,7 @@ static int networkConnectListNetworks(virConnectPtr conn, char **const names, in for (i = 0 ; i < driver->networks.count && got < nnames ; i++) { virNetworkObjLock(driver->networks.objs[i]); if (virNetworkObjIsActive(driver->networks.objs[i])) { - if (!(names[got] = strdup(driver->networks.objs[i]->def->name))) { + if (VIR_STRDUP(names[got], driver->networks.objs[i]->def->name) < 0) { virNetworkObjUnlock(driver->networks.objs[i]); virReportOOMError(); goto cleanup; @@ -2864,7 +2864,7 @@ static int networkConnectListDefinedNetworks(virConnectPtr conn, char **const na for (i = 0 ; i < driver->networks.count && got < nnames ; i++) { virNetworkObjLock(driver->networks.objs[i]); if (!virNetworkObjIsActive(driver->networks.objs[i])) { - if (!(names[got] = strdup(driver->networks.objs[i]->def->name))) { + if (VIR_STRDUP(names[got], driver->networks.objs[i]->def->name) < 0) { virNetworkObjUnlock(driver->networks.objs[i]); virReportOOMError(); goto cleanup; @@ -3489,8 +3489,7 @@ static char *networkGetBridgeName(virNetworkPtr net) { goto cleanup; } - bridge = strdup(network->def->bridge); - if (!bridge) + if (VIR_STRDUP(bridge, network->def->bridge) < 0) virReportOOMError(); cleanup: @@ -3678,14 +3677,11 @@ networkCreateInterfacePool(virNetworkDefPtr netdef) { (netdef->forward.type == VIR_NETWORK_FORWARD_VEPA) || (netdef->forward.type == VIR_NETWORK_FORWARD_PASSTHROUGH)) { netdef->forward.ifs[ii].type = VIR_NETWORK_FORWARD_HOSTDEV_DEVICE_NETDEV; - if (vfname[ii]) { - netdef->forward.ifs[ii].device.dev = strdup(vfname[ii]); - if (!netdef->forward.ifs[ii].device.dev) { - virReportOOMError(); - goto finish; - } - } - else { + if (vfname[ii] && + VIR_STRDUP(netdef->forward.ifs[ii].device.dev, vfname[ii]) < 0) { + virReportOOMError(); + goto finish; + } else { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Direct mode types require interface names")); goto finish; @@ -3828,8 +3824,7 @@ networkAllocateActualDevice(virDomainNetDefPtr iface) } iface->data.network.actual->type = actualType = VIR_DOMAIN_NET_TYPE_BRIDGE; - iface->data.network.actual->data.bridge.brname = strdup(netdef->bridge); - if (!iface->data.network.actual->data.bridge.brname) { + if (VIR_STRDUP(iface->data.network.actual->data.bridge.brname, netdef->bridge) < 0) { virReportOOMError(); goto error; } @@ -4049,8 +4044,7 @@ networkAllocateActualDevice(virDomainNetDefPtr iface) netdef->name); goto error; } - iface->data.network.actual->data.direct.linkdev = strdup(dev->device.dev); - if (!iface->data.network.actual->data.direct.linkdev) { + if (VIR_STRDUP(iface->data.network.actual->data.direct.linkdev, dev->device.dev) < 0) { virReportOOMError(); goto error; } -- 1.8.1.5

--- src/node_device/node_device_driver.c | 28 ++++------ src/node_device/node_device_hal.c | 13 ++--- src/node_device/node_device_udev.c | 102 +++++++++++++++-------------------- 3 files changed, 60 insertions(+), 83 deletions(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c index 95df2e5..2ef05ab 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -36,6 +36,7 @@ #include "node_device_conf.h" #include "node_device_hal.h" #include "node_device_driver.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_NODEDEV @@ -88,12 +89,9 @@ static int update_driver_name(virNodeDeviceObjPtr dev) } p = strrchr(devpath, '/'); - if (p) { - dev->def->driver = strdup(p+1); - if (!dev->def->driver) { - virReportOOMError(); - goto cleanup; - } + if (p && VIR_STRDUP(dev->def->driver, p+1) < 0) { + virReportOOMError(); + goto cleanup; } ret = 0; @@ -161,7 +159,7 @@ nodeListDevices(virConnectPtr conn, virNodeDeviceObjLock(driver->devs.objs[i]); if (cap == NULL || virNodeDeviceHasCap(driver->devs.objs[i], cap)) { - if ((names[ndevs++] = strdup(driver->devs.objs[i]->def->name)) == NULL) { + if (VIR_STRDUP(names[ndevs++], driver->devs.objs[i]->def->name) < 0) { virNodeDeviceObjUnlock(driver->devs.objs[i]); virReportOOMError(); goto failure; @@ -321,8 +319,7 @@ nodeDeviceGetParent(virNodeDevicePtr dev) } if (obj->def->parent) { - ret = strdup(obj->def->parent); - if (!ret) + if (VIR_STRDUP(ret, obj->def->parent) < 0) virReportOOMError(); } else { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -388,8 +385,7 @@ nodeDeviceListCaps(virNodeDevicePtr dev, char **const names, int maxnames) } for (caps = obj->def->caps; caps && ncaps < maxnames; caps = caps->next) { - names[ncaps] = strdup(virNodeDevCapTypeToString(caps->type)); - if (names[ncaps++] == NULL) { + if (VIR_STRDUP(names[ncaps], virNodeDevCapTypeToString(caps->type)) < 0) { virReportOOMError(); goto cleanup; } @@ -554,7 +550,10 @@ nodeDeviceDestroy(virNodeDevicePtr dev) goto out; } - parent_name = strdup(obj->def->parent); + if (VIR_STRDUP(parent_name, obj->def->parent) < 0) { + virReportOOMError(); + 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 @@ -563,11 +562,6 @@ nodeDeviceDestroy(virNodeDevicePtr dev) virNodeDeviceObjUnlock(obj); obj = NULL; - if (parent_name == NULL) { - virReportOOMError(); - goto out; - } - if (virNodeDeviceGetParentHost(&driver->devs, dev->name, parent_name, diff --git a/src/node_device/node_device_hal.c b/src/node_device/node_device_hal.c index 63245a9..1077445 100644 --- a/src/node_device/node_device_hal.c +++ b/src/node_device/node_device_hal.c @@ -445,10 +445,10 @@ static void dev_create(const char *udi) virNodeDeviceDefPtr def = NULL; const char *name = hal_name(udi); int rv; - char *privData = strdup(udi); + char *privData; char *devicePath = NULL; - if (!privData) + if (VIR_STRDUP(privDatam udi) < 0) return; nodeDeviceLock(driverState); @@ -457,14 +457,15 @@ static void dev_create(const char *udi) if (VIR_ALLOC(def) < 0) goto failure; - if ((def->name = strdup(name)) == NULL) + if (VIR_STRDUP(def->name, name) < 0) goto failure; if (get_str_prop(ctx, udi, "info.parent", &parent_key) == 0) { - def->parent = strdup(hal_name(parent_key)); - VIR_FREE(parent_key); - if (def->parent == NULL) + if (VIR_STRDUP(def->parent, hal_name(parent_key)) < 0) { + VIR_FREE(parent_key); goto failure; + } + VIR_FREE(parent_key); } rv = gather_capabilities(ctx, udi, &def->caps); diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c index c3c97d7..9bc4496 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -125,8 +125,7 @@ static int udevGetDeviceProperty(struct udev_device *udev_device, /* If this allocation is changed, the comment at the beginning * of the function must also be changed. */ - *property_value = strdup(udev_value); - if (*property_value == NULL) { + if (VIR_STRDUP(*property_value, udev_value) < 0) { 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)); @@ -214,8 +213,7 @@ static int udevGetDeviceSysfsAttr(struct udev_device *udev_device, /* If this allocation is changed, the comment at the beginning * of the function must also be changed. */ - *attr_value = strdup(udev_value); - if (*attr_value == NULL) { + if (VIR_STRDUP(*attr_value, udev_value) < 0) { 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)); @@ -387,20 +385,14 @@ static int udevTranslatePCIIds(unsigned int vendor, NULL, NULL); - if (vendor_name != NULL) { - *vendor_string = strdup(vendor_name); - if (*vendor_string == NULL) { - virReportOOMError(); - goto out; - } + if (vendor_name && VIR_STRDUP(*vendor_string, vendor_name) < 0) { + virReportOOMError(); + goto out; } - if (device_name != NULL) { - *product_string = strdup(device_name); - if (*product_string == NULL) { - virReportOOMError(); - goto out; - } + if (device_name && VIR_STRDUP(*product_string, device_name) < 0) { + virReportOOMError(); + goto out; } ret = 0; @@ -691,8 +683,7 @@ static int udevProcessSCSITarget(struct udev_device *device ATTRIBUTE_UNUSED, sysname = udev_device_get_sysname(device); - data->scsi_target.name = strdup(sysname); - if (data->scsi_target.name == NULL) { + if (VIR_STRDUP(data->scsi_target.name, sysname) < 0) { virReportOOMError(); goto out; } @@ -718,34 +709,34 @@ static int udevGetSCSIType(virNodeDeviceDefPtr def ATTRIBUTE_UNUSED, switch (type) { case TYPE_DISK: - *typestring = strdup("disk"); + ret = VIR_STRDUP(*typestring, "disk"); break; case TYPE_TAPE: - *typestring = strdup("tape"); + ret = VIR_STRDUP(*typestring, "tape"); break; case TYPE_PROCESSOR: - *typestring = strdup("processor"); + ret = VIR_STRDUP(*typestring, "processor"); break; case TYPE_WORM: - *typestring = strdup("worm"); + ret = VIR_STRDUP(*typestring, "worm"); break; case TYPE_ROM: - *typestring = strdup("cdrom"); + ret = VIR_STRDUP(*typestring, "cdrom"); break; case TYPE_SCANNER: - *typestring = strdup("scanner"); + ret = VIR_STRDUP(*typestring, "scanner"); break; case TYPE_MOD: - *typestring = strdup("mod"); + ret = VIR_STRDUP(*typestring, "mod"); break; case TYPE_MEDIUM_CHANGER: - *typestring = strdup("changer"); + ret = VIR_STRDUP(*typestring, "changer"); break; case TYPE_ENCLOSURE: - *typestring = strdup("enclosure"); + ret = VIR_STRDUP(*typestring, "enclosure"); break; case TYPE_RAID: - *typestring = strdup("raid"); + ret = VIR_STRDUP(*typestring, "raid"); break; case TYPE_NO_LUN: default: @@ -753,14 +744,12 @@ static int udevGetSCSIType(virNodeDeviceDefPtr def ATTRIBUTE_UNUSED, break; } - if (*typestring == NULL) { - if (foundtype == 1) { - ret = -1; + if (foundtype == 1) { + if (ret < 0) virReportOOMError(); - } else { - VIR_DEBUG("Failed to find SCSI device type %d for %s", - type, def->sysfs_path); - } + } else { + VIR_DEBUG("Failed to find SCSI device type %d for %s", + type, def->sysfs_path); } return ret; @@ -917,8 +906,7 @@ static int udevProcessCDROM(struct udev_device *device, * change it to cdrom to preserve compatibility with earlier * versions of libvirt. */ VIR_FREE(def->caps->data.storage.drive_type); - def->caps->data.storage.drive_type = strdup("cdrom"); - if (def->caps->data.storage.drive_type == NULL) { + if (VIR_STRDUP(def->caps->data.storage.drive_type, "cdrom") < 0) { virReportOOMError(); goto out; } @@ -996,10 +984,7 @@ static int udevKludgeStorageType(virNodeDeviceDefPtr def) if (STRPREFIX(def->caps->data.storage.block, "/dev/vd")) { /* virtio disk */ - def->caps->data.storage.drive_type = strdup("disk"); - if (def->caps->data.storage.drive_type != NULL) { - ret = 0; - } + ret = VIR_STRDUP(def->caps->data.storage.drive_type, "disk"); } if (ret != 0) { @@ -1043,7 +1028,9 @@ static int udevProcessStorage(struct udev_device *device, VIR_DEBUG("No devnode for '%s'", udev_device_get_devpath(device)); goto out; } - data->storage.block = strdup(devnode); + + if (VIR_STRDUP(data->storage.block, devnode) < 0) + goto out; if (udevGetStringProperty(device, "ID_BUS", @@ -1083,15 +1070,13 @@ static int udevProcessStorage(struct udev_device *device, &tmp_int, 0) == PROPERTY_FOUND) && (tmp_int == 1)) { - data->storage.drive_type = strdup("floppy"); - if (!data->storage.drive_type) + if (VIR_STRDUP(data->storage.drive_type, "floppy") < 0) goto out; } else if ((udevGetIntProperty(device, "ID_DRIVE_FLASH_SD", &tmp_int, 0) == PROPERTY_FOUND) && (tmp_int == 1)) { - data->storage.drive_type = strdup("sd"); - if (!data->storage.drive_type) + if (VIR_STRDUP(data->storage.drive_type, "sd") < 0) goto out; } else { @@ -1294,16 +1279,14 @@ static int udevSetParent(struct udev_device *device, dev = virNodeDeviceFindBySysfsPath(&driverState->devs, parent_sysfs_path); if (dev != NULL) { - def->parent = strdup(dev->def->name); - virNodeDeviceObjUnlock(dev); - - if (def->parent == NULL) { + if (VIR_STRDUP(def->parent, dev->def->name) < 0) { + virNodeDeviceObjUnlock(dev); virReportOOMError(); goto out; } + virNodeDeviceObjUnlock(dev); - def->parent_sysfs_path = strdup(parent_sysfs_path); - if (def->parent_sysfs_path == NULL) { + if (VIR_STRDUP(def->parent_sysfs_path, parent_sysfs_path) < 0) { virReportOOMError(); goto out; } @@ -1312,11 +1295,7 @@ static int udevSetParent(struct udev_device *device, } while (def->parent == NULL && parent_device != NULL); - if (def->parent == NULL) { - def->parent = strdup("computer"); - } - - if (def->parent == NULL) { + if (!def->parent && VIR_STRDUP(def->parent, "computer") < 0) { virReportOOMError(); goto out; } @@ -1339,7 +1318,11 @@ static int udevAddOneDevice(struct udev_device *device) goto out; } - def->sysfs_path = strdup(udev_device_get_syspath(device)); + if (VIR_STRDUP(def->sysfs_path, udev_device_get_syspath(device)) < 0) { + virReportOOMError(); + goto out; + } + if (udevGetStringProperty(device, "DRIVER", &def->driver) == PROPERTY_ERROR) { @@ -1617,8 +1600,7 @@ static int udevSetupSystemDev(void) goto out; } - def->name = strdup("computer"); - if (def->name == NULL) { + if (VIR_STRDUP(def->name, "computer") < 0) { virReportOOMError(); goto out; } -- 1.8.1.5

On 04/29/2013 09:50 AM, Michal Privoznik wrote:
--- src/node_device/node_device_driver.c | 28 ++++------ src/node_device/node_device_hal.c | 13 ++--- src/node_device/node_device_udev.c | 102 +++++++++++++++-------------------- 3 files changed, 60 insertions(+), 83 deletions(-)
...
@@ -388,8 +385,7 @@ nodeDeviceListCaps(virNodeDevicePtr dev, char **const names, int maxnames) }
for (caps = obj->def->caps; caps && ncaps < maxnames; caps = caps->next) { - names[ncaps] = strdup(virNodeDevCapTypeToString(caps->type)); - if (names[ncaps++] == NULL) { + if (VIR_STRDUP(names[ncaps], virNodeDevCapTypeToString(caps->type)) < 0) {
Lost the autoincrement ^^^
virReportOOMError(); goto cleanup; }
...
--- a/src/node_device/node_device_hal.c +++ b/src/node_device/node_device_hal.c @@ -445,10 +445,10 @@ static void dev_create(const char *udi) virNodeDeviceDefPtr def = NULL; const char *name = hal_name(udi); int rv; - char *privData = strdup(udi); + char *privData; char *devicePath = NULL;
- if (!privData) + if (VIR_STRDUP(privDatam udi) < 0)
s/m/,/ ...

On 04/29/2013 12:51 PM, John Ferlan wrote:
On 04/29/2013 09:50 AM, Michal Privoznik wrote:
--- src/node_device/node_device_driver.c | 28 ++++------ src/node_device/node_device_hal.c | 13 ++--- src/node_device/node_device_udev.c | 102 +++++++++++++++-------------------- 3 files changed, 60 insertions(+), 83 deletions(-)
...
@@ -388,8 +385,7 @@ nodeDeviceListCaps(virNodeDevicePtr dev, char **const names, int maxnames) }
for (caps = obj->def->caps; caps && ncaps < maxnames; caps = caps->next) { - names[ncaps] = strdup(virNodeDevCapTypeToString(caps->type)); - if (names[ncaps++] == NULL) { + if (VIR_STRDUP(names[ncaps], virNodeDevCapTypeToString(caps->type)) < 0) {
Lost the autoincrement ^^^
Except that you probably don't want an increment inside VIR_STRDUP, since as an all-caps macro name, you aren't guaranteed that the destination will be evaluated exactly once if we didn't document it that way in virstring.h. (Hmm, it looks like the implementation is actually safe in evaluating exactly once, but we ought to make that part of the contract.) -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

--- src/interface/interface_backend_udev.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/src/interface/interface_backend_udev.c b/src/interface/interface_backend_udev.c index 7daad16..65c8c31 100644 --- a/src/interface/interface_backend_udev.c +++ b/src/interface/interface_backend_udev.c @@ -227,14 +227,12 @@ udevListInterfacesByStatus(virConnectPtr conn, path = udev_list_entry_get_name(dev_entry); dev = udev_device_new_from_syspath(udev, path); - names[count] = strdup(udev_device_get_sysname(dev)); - udev_device_unref(dev); - - /* If strdup() failed, we are out of memory */ - if (!names[count]) { + if (VIR_STRDUP(names[count], udev_device_get_sysname(dev)) < 0) { virReportOOMError(); + udev_device_unref(dev); goto err; } + udev_device_unref(dev); count++; } @@ -751,8 +749,7 @@ udevGetIfaceDefBond(struct udev *udev, _("Could not retrieve 'bonding/arp_ip_target' for '%s'"), name); goto cleanup; } - ifacedef->data.bond.target = strdup(tmp_str); - if (!ifacedef->data.bond.target) { + if (VIR_STRDUP(ifacedef->data.bond.target, tmp_str) < 0) { virReportOOMError(); goto cleanup; } @@ -839,8 +836,7 @@ udevGetIfaceDefBridge(struct udev *udev, goto error; } - ifacedef->data.bridge.delay = strdup(tmp_str); - if (!ifacedef->data.bridge.delay) { + if (VIR_STRDUP(ifacedef->data.bridge.delay, tmp_str) < 0) { virReportOOMError(); goto error; } @@ -938,8 +934,7 @@ udevGetIfaceDefVlan(struct udev *udev ATTRIBUTE_UNUSED, char *vid; char *vlan_parent_dev = NULL; - vlan_parent_dev = strdup(name); - if (!vlan_parent_dev) { + if (VIR_STRDUP(vlan_parent_dev, name) < 0) { virReportOOMError(); goto cleanup; } @@ -987,9 +982,7 @@ udevGetIfaceDef(struct udev *udev, const char *name) /* Clear our structure and set safe defaults */ ifacedef->startmode = VIR_INTERFACE_START_UNSPECIFIED; - ifacedef->name = strdup(name); - - if (!ifacedef->name) { + if (VIR_STRDUP(ifacedef->name, name) < 0) { virReportOOMError(); goto cleanup; } @@ -1003,8 +996,7 @@ udevGetIfaceDef(struct udev *udev, const char *name) } /* MAC address */ - ifacedef->mac = strdup(udev_device_get_sysattr_value(dev, "address")); - if (!ifacedef->mac) { + if (VIR_STRDUP(ifacedef->mac, udev_device_get_sysattr_value(dev, "address")) < 0) { virReportOOMError(); goto cleanup; } -- 1.8.1.5

--- src/nwfilter/nwfilter_dhcpsnoop.c | 15 +++++++-------- src/nwfilter/nwfilter_driver.c | 4 ++-- src/nwfilter/nwfilter_ebiptables_driver.c | 10 +++++----- src/nwfilter/nwfilter_gentech_driver.c | 4 ++-- src/nwfilter/nwfilter_learnipaddr.c | 3 +-- 5 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c b/src/nwfilter/nwfilter_dhcpsnoop.c index df11e89..3047d4d 100644 --- a/src/nwfilter/nwfilter_dhcpsnoop.c +++ b/src/nwfilter/nwfilter_dhcpsnoop.c @@ -133,11 +133,11 @@ struct _virNWFilterSnoopReq { virNWFilterTechDriverPtr techdriver; char *ifname; int ifindex; - const char *linkdev; + char *linkdev; enum virDomainNetType nettype; char ifkey[VIR_IFKEY_LEN]; virMacAddr macaddr; - const char *filtername; + char *filtername; virNWFilterHashTablePtr vars; virNWFilterDriverStatePtr driver; /* start and end of lease list, ordered by lease time */ @@ -1408,7 +1408,7 @@ virNWFilterDHCPSnoopThread(void *req0) fds[i].fd = pcap_fileno(pcapConf[i].handle); } tmp = virNetDevGetIndex(req->ifname, &ifindex); - threadkey = strdup(req->threadkey); + ignore_value(VIR_STRDUP(threadkey, req->threadkey)); worker = virThreadPoolNew(1, 1, 0, virNWFilterDHCPDecodeWorker, req); @@ -1631,15 +1631,14 @@ virNWFilterDHCPSnoopReq(virNWFilterTechDriverPtr techdriver, req->driver = driver; req->techdriver = techdriver; tmp = virNetDevGetIndex(ifname, &req->ifindex); - req->linkdev = linkdev ? strdup(linkdev) : NULL; + req->linkdev = NULL; req->nettype = nettype; - req->ifname = strdup(ifname); virMacAddrSet(&req->macaddr, macaddr); - req->filtername = strdup(filtername); req->vars = virNWFilterHashTableCreate(0); - if (!req->ifname || !req->filtername || !req->vars || tmp < 0 || - (linkdev != NULL && req->linkdev == NULL)) { + if ((linkdev && VIR_STRDUP(req->linkdev, linkdev) < 0) || + VIR_STRDUP(req->ifname, ifname) < 0 || + VIR_STRDUP(req->filtername, filtername) < 0 || !req->vars || tmp < 0) { virReportOOMError(); goto exit_snoopreqput; } diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c index 7eec3de..0a3c24f 100644 --- a/src/nwfilter/nwfilter_driver.c +++ b/src/nwfilter/nwfilter_driver.c @@ -221,7 +221,7 @@ nwfilterStateInitialize(bool privileged, goto error; } - if ((base = strdup(SYSCONFDIR "/libvirt")) == NULL) + if (VIR_STRDUP(base, SYSCONFDIR "/libvirt") < 0) goto out_of_memory; if (virAsprintf(&driverState->configDir, @@ -454,7 +454,7 @@ nwfilterConnectListNWFilters(virConnectPtr conn, nwfilterDriverLock(driver); for (i = 0 ; i < driver->nwfilters.count && got < nnames ; i++) { virNWFilterObjLock(driver->nwfilters.objs[i]); - if (!(names[got] = strdup(driver->nwfilters.objs[i]->def->name))) { + if (VIR_STRDUP(names[got], driver->nwfilters.objs[i]->def->name) < 0) { virNWFilterObjUnlock(driver->nwfilters.objs[i]); virReportOOMError(); goto cleanup; diff --git a/src/nwfilter/nwfilter_ebiptables_driver.c b/src/nwfilter/nwfilter_ebiptables_driver.c index ac94355..5d1c8d7 100644 --- a/src/nwfilter/nwfilter_ebiptables_driver.c +++ b/src/nwfilter/nwfilter_ebiptables_driver.c @@ -2975,6 +2975,7 @@ ebtablesCreateTmpSubChain(ebiptablesRuleInstPtr *inst, char chainPrefix = (incoming) ? CHAINPREFIX_HOST_IN_TEMP : CHAINPREFIX_HOST_OUT_TEMP; char *protostr = NULL; + int rc; PRINT_ROOT_CHAIN(rootchain, chainPrefix, ifname); PRINT_CHAIN(chain, chainPrefix, ifname, @@ -2982,18 +2983,17 @@ ebtablesCreateTmpSubChain(ebiptablesRuleInstPtr *inst, switch (protoidx) { case L2_PROTO_MAC_IDX: - protostr = strdup(""); + rc = VIR_STRDUP(protostr, ""); break; case L2_PROTO_STP_IDX: - ignore_value(virAsprintf(&protostr, "-d " NWFILTER_MAC_BGA " ")); + rc = virAsprintf(&protostr, "-d " NWFILTER_MAC_BGA " "); break; default: - ignore_value(virAsprintf(&protostr, "-p 0x%04x ", - l3_protocols[protoidx].attr)); + rc = virAsprintf(&protostr, "-p 0x%04x ", l3_protocols[protoidx].attr); break; } - if (!protostr) { + if (rc < 0) { virReportOOMError(); return -1; } diff --git a/src/nwfilter/nwfilter_gentech_driver.c b/src/nwfilter/nwfilter_gentech_driver.c index 958f47a..90f38f3 100644 --- a/src/nwfilter/nwfilter_gentech_driver.c +++ b/src/nwfilter/nwfilter_gentech_driver.c @@ -37,6 +37,7 @@ #include "nwfilter_learnipaddr.h" #include "virnetdev.h" #include "datatypes.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_NWFILTER @@ -866,8 +867,7 @@ __virNWFilterInstantiateFilter(const unsigned char *vmuuid, } virMacAddrFormat(macaddr, vmmacaddr); - str_macaddr = strdup(vmmacaddr); - if (!str_macaddr) { + if (VIR_STRDUP(str_macaddr, vmmacaddr) < 0) { virReportOOMError(); rc = -1; goto err_exit; diff --git a/src/nwfilter/nwfilter_learnipaddr.c b/src/nwfilter/nwfilter_learnipaddr.c index 14fd32c..d945af2 100644 --- a/src/nwfilter/nwfilter_learnipaddr.c +++ b/src/nwfilter/nwfilter_learnipaddr.c @@ -705,8 +705,7 @@ virNWFilterLearnIPAddress(virNWFilterTechDriverPtr techdriver, if (virNWFilterHashTablePutAll(filterparams, ht) < 0) goto err_free_ht; - req->filtername = strdup(filtername); - if (req->filtername == NULL) { + if (VIR_STRDUP(req->filtername, filtername) < 0) { virReportOOMError(); goto err_free_ht; } -- 1.8.1.5

--- src/openvz/openvz_conf.c | 31 +++++++++++++++---------------- src/openvz/openvz_driver.c | 30 +++++++++++++++--------------- 2 files changed, 30 insertions(+), 31 deletions(-) diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c index 49fae28..9dbdc74 100644 --- a/src/openvz/openvz_conf.c +++ b/src/openvz/openvz_conf.c @@ -135,9 +135,9 @@ openvzParseBarrierLimit(const char* value, { char *token; char *saveptr = NULL; - char *str = strdup(value); + char *str; - if (str == NULL) { + if (VIR_STRDUP(str, value) < 0) { virReportOOMError(); goto error; } @@ -230,9 +230,7 @@ openvzReadNetworkConf(virDomainDefPtr def, goto no_memory; net->type = VIR_DOMAIN_NET_TYPE_ETHERNET; - net->data.ethernet.ipaddr = strdup(token); - - if (net->data.ethernet.ipaddr == NULL) + if (VIR_STRDUP(net->data.ethernet.ipaddr, token) < 0) goto no_memory; if (VIR_REALLOC_N(def->nets, def->nnets + 1) < 0) @@ -405,7 +403,8 @@ openvzReadFSConf(virDomainDefPtr def, goto no_memory; fs->type = VIR_DOMAIN_FS_TYPE_TEMPLATE; - fs->src = strdup(temp); + if (VIR_STRDUP(fs->src, temp) < 0) + goto no_memory; } else { /* OSTEMPLATE was not found, VE was booted from a private dir directly */ ret = openvzReadVPSConfigParam(veid, "VE_PRIVATE", &temp); @@ -428,7 +427,8 @@ openvzReadFSConf(virDomainDefPtr def, VIR_FREE(veid_str); } - fs->dst = strdup("/"); + if (VIR_STRDUP(fs->dst, "/") < 0) + goto no_memory; param = "DISKSPACE"; ret = openvzReadVPSConfigParam(veid, param, &temp); @@ -451,9 +451,6 @@ openvzReadFSConf(virDomainDefPtr def, } } - if (fs->src == NULL || fs->dst == NULL) - goto no_memory; - if (VIR_REALLOC_N(def->fss, def->nfss + 1) < 0) goto no_memory; def->fss[def->nfss++] = fs; @@ -607,9 +604,9 @@ int openvzLoadDomains(struct openvz_driver *driver) { goto cleanup; } - if (!(def->os.type = strdup("exe"))) + if (VIR_STRDUP(def->os.type, "exe") < 0) goto no_memory; - if (!(def->os.init = strdup("/sbin/init"))) + if (VIR_STRDUP(def->os.init, "/sbin/init") < 0) goto no_memory; ret = openvzReadVPSConfigParam(veid, "CPUS", &temp); @@ -800,8 +797,7 @@ openvzReadConfigParam(const char *conf_file, const char *param, char **value) saveptr = NULL; if ((token = strtok_r(sf, "\"\t\n", &saveptr)) != NULL) { VIR_FREE(*value); - *value = strdup(token); - if (*value == NULL) { + if (VIR_STRDUP(*value, token) < 0) { err = 1; break; } @@ -952,10 +948,13 @@ openvzLocateConfDir(void) { const char *conf_dir_list[] = {"/etc/vz/conf", "/usr/local/etc/conf", NULL}; int i=0; + char *ret = NULL; while (conf_dir_list[i]) { - if (!access(conf_dir_list[i], F_OK)) - return strdup(conf_dir_list[i]); + if (!access(conf_dir_list[i], F_OK)) { + ignore_value(VIR_STRDUP(ret, conf_dir_list[i])); + return ret; + } i++; } diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index e6d7146..027cda8 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -88,7 +88,7 @@ static void openvzDriverUnlock(struct openvz_driver *driver) struct openvz_driver ovz_driver; -static void cmdExecFree(const char *cmdExec[]) +static void cmdExecFree(char *cmdExec[]) { int i=-1; while (cmdExec[++i]) { @@ -104,7 +104,7 @@ openvzDomainDefPostParse(virDomainDefPtr def, { /* fill the init path */ if (STREQ(def->os.type, "exe") && !def->os.init) { - if (!(def->os.init = strdup("/sbin/init"))) { + if (VIR_STRDUP(def->os.init, "/sbin/init") < 0) { virReportOOMError(); return -1; } @@ -358,7 +358,7 @@ static char *openvzDomainGetOSType(virDomainPtr dom) goto cleanup; } - if (!(ret = strdup(vm->def->os.type))) + if (VIR_STRDUP(ret, vm->def->os.type) < 0) virReportOOMError(); cleanup: @@ -772,12 +772,14 @@ openvzGenerateVethName(int veid, char *dev_name_ve) { char dev_name[32]; int ifNo = 0; + char *ret; if (sscanf(dev_name_ve, "%*[^0-9]%d", &ifNo) != 1) return NULL; if (snprintf(dev_name, sizeof(dev_name), "veth%d.%d", veid, ifNo) < 7) return NULL; - return strdup(dev_name); + ignore_value(VIR_STRDUP(ret, dev_name)); + return ret; } static char * @@ -788,7 +790,8 @@ openvzGenerateContainerVethName(int veid) /* try to get line "^NETIF=..." from config */ if (openvzReadVPSConfigParam(veid, "NETIF", &temp) <= 0) { - name = strdup("eth0"); + if (VIR_STRDUP(name, "eth0") < 0) + virReportOOMError(); } else { char *saveptr = NULL; char *s; @@ -803,15 +806,12 @@ openvzGenerateContainerVethName(int veid) } /* set new name */ - ignore_value(virAsprintf(&name, "eth%d", max + 1)); + if (virAsprintf(&name, "eth%d", max + 1) < 0) + virReportOOMError(); } VIR_FREE(temp); - if (name == NULL) { - virReportOOMError(); - } - return name; } @@ -821,7 +821,7 @@ openvzDomainSetNetwork(virConnectPtr conn, const char *vpsid, virBufferPtr configBuf) { int rc = 0, narg; - const char *prog[OPENVZ_MAX_ARG]; + char *prog[OPENVZ_MAX_ARG]; char macaddr[VIR_MAC_STRING_BUFLEN]; virMacAddr host_mac; char host_macaddr[VIR_MAC_STRING_BUFLEN]; @@ -830,9 +830,9 @@ openvzDomainSetNetwork(virConnectPtr conn, const char *vpsid, #define ADD_ARG_LIT(thisarg) \ do { \ - if (narg >= OPENVZ_MAX_ARG) \ + if (narg >= OPENVZ_MAX_ARG) \ goto no_memory; \ - if ((prog[narg++] = strdup(thisarg)) == NULL) \ + if (VIR_STRDUP(prog[narg++], thisarg) < 0) \ goto no_memory; \ } while (0) @@ -928,7 +928,7 @@ openvzDomainSetNetwork(virConnectPtr conn, const char *vpsid, if (prog[0] != NULL) { ADD_ARG_LIT("--save"); - if (virRun(prog, NULL) < 0) { + if (virRun((const char * const*) prog, NULL) < 0) { rc = -1; goto exit; } @@ -1642,7 +1642,7 @@ static int openvzConnectListDefinedDomains(virConnectPtr conn ATTRIBUTE_UNUSED, continue; } snprintf(vpsname, sizeof(vpsname), "%d", veid); - if (!(names[got] = strdup(vpsname))) { + if (VIR_STRDUP(names[got], vpsname) < 0) { virReportOOMError(); goto out; } -- 1.8.1.5

--- src/parallels/parallels_driver.c | 34 +++++++++++++++++----------------- src/parallels/parallels_network.c | 12 ++++++------ src/parallels/parallels_storage.c | 38 +++++++++++++++----------------------- 3 files changed, 38 insertions(+), 46 deletions(-) diff --git a/src/parallels/parallels_driver.c b/src/parallels/parallels_driver.c index c29a5ba..fd3e3bc 100644 --- a/src/parallels/parallels_driver.c +++ b/src/parallels/parallels_driver.c @@ -186,7 +186,7 @@ parallelsGetSerialInfo(virDomainChrDefPtr chr, return -1; } - if (!(chr->source.data.file.path = strdup(tmp))) + if (VIR_STRDUP(chr->source.data.file.path, tmp) < 0) goto no_memory; } else if (virJSONValueObjectHasKey(value, "socket")) { chr->source.type = VIR_DOMAIN_CHR_TYPE_UNIX; @@ -197,7 +197,7 @@ parallelsGetSerialInfo(virDomainChrDefPtr chr, return -1; } - if (!(chr->source.data.nix.path = strdup(tmp))) + if (VIR_STRDUP(chr->source.data.nix.path, tmp) < 0) goto no_memory; chr->source.data.nix.listen = false; } else if (virJSONValueObjectHasKey(value, "real")) { @@ -209,7 +209,7 @@ parallelsGetSerialInfo(virDomainChrDefPtr chr, return -1; } - if (!(chr->source.data.file.path = strdup(tmp))) + if (VIR_STRDUP(chr->source.data.file.path, tmp) < 0) goto no_memory; } else { parallelsParseError(); @@ -318,7 +318,7 @@ parallelsGetHddInfo(virDomainDefPtr def, return -1; } - if (!(disk->src = strdup(tmp))) { + if (VIR_STRDUP(disk->src, tmp) < 0) { virReportOOMError(); return -1; } @@ -330,7 +330,7 @@ parallelsGetHddInfo(virDomainDefPtr def, return -1; } - if (!(disk->src = strdup(tmp))) { + if (VIR_STRDUP(disk->src, tmp) < 0) { virReportOOMError(); return -1; } @@ -454,7 +454,7 @@ parallelsGetNetInfo(virDomainNetDefPtr net, /* use device name, shown by prlctl as target device * for identifying network adapter in virDomainDefineXML */ - if (!(net->ifname = strdup(key))) { + if (VIR_STRDUP(net->ifname, key) < 0) { virReportOOMError(); goto error; } @@ -478,7 +478,7 @@ parallelsGetNetInfo(virDomainNetDefPtr net, goto error; } - if (!(net->data.network.name = strdup(tmp))) { + if (VIR_STRDUP(net->data.network.name, tmp) < 0) { virReportOOMError(); goto error; } @@ -493,7 +493,7 @@ parallelsGetNetInfo(virDomainNetDefPtr net, goto error; } - if (!(net->data.network.name = strdup(PARALLELS_ROUTED_NETWORK_NAME))) { + if (VIR_STRDUP(net->data.network.name, PARALLELS_ROUTED_NETWORK_NAME) < 0) { virReportOOMError(); goto error; } @@ -641,7 +641,7 @@ parallelsAddVNCInfo(virDomainDefPtr def, virJSONValuePtr jobj_root) gr->nListens = 1; - if (!(gr->listens[0].address = strdup(tmp))) + if (VIR_STRDUP(gr->listens[0].address, tmp) < 0) goto no_memory; gr->listens[0].type = VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS; @@ -686,7 +686,7 @@ parallelsLoadDomain(parallelsConnPtr privconn, virJSONValuePtr jobj) parallelsParseError(); goto cleanup; } - if (!(def->name = strdup(tmp))) + if (VIR_STRDUP(def->name, tmp) < 0) goto no_memory; if (!(tmp = virJSONValueObjectGetString(jobj, "ID"))) { @@ -704,7 +704,7 @@ parallelsLoadDomain(parallelsConnPtr privconn, virJSONValuePtr jobj) parallelsParseError(); goto cleanup; } - if (!(def->description = strdup(tmp))) + if (VIR_STRDUP(def->description, tmp) < 0) goto no_memory; if (!(jobj2 = virJSONValueObjectGet(jobj, "Hardware"))) { @@ -771,12 +771,12 @@ parallelsLoadDomain(parallelsConnPtr privconn, virJSONValuePtr jobj) } if (STREQ(tmp, "CT")) { - if (!(def->os.type = strdup("exe"))) + if (VIR_STRDUP(def->os.type, "exe") < 0) goto no_memory; - if (!(def->os.init = strdup("/sbin/init"))) + if (VIR_STRDUP(def->os.init, "/sbin/init") < 0) goto no_memory; } else if (STREQ(tmp, "VM")) { - if (!(def->os.type = strdup("hvm"))) + if (VIR_STRDUP(def->os.type, "hvm") < 0) goto no_memory; } @@ -792,7 +792,7 @@ parallelsLoadDomain(parallelsConnPtr privconn, virJSONValuePtr jobj) parallelsParseError(); goto cleanup; } - if (!(pdom->uuid = strdup(tmp))) + if (VIR_STRDUP(pdom->uuid, tmp) < 0) goto no_memory; if (!(tmp = virJSONValueObjectGetString(jobj, "Home"))) { @@ -800,7 +800,7 @@ parallelsLoadDomain(parallelsConnPtr privconn, virJSONValuePtr jobj) goto cleanup; } - if (!(pdom->home = strdup(tmp))) + if (VIR_STRDUP(pdom->home, tmp) < 0) goto no_memory; if (!(state = virJSONValueObjectGetString(jobj, "State"))) { @@ -1239,7 +1239,7 @@ parallelsDomainGetOSType(virDomainPtr domain) goto cleanup; } - if (!(ret = strdup(privdom->def->os.type))) + if (VIR_STRDUP(ret, privdom->def->os.type) < 0) virReportOOMError(); cleanup: diff --git a/src/parallels/parallels_network.c b/src/parallels/parallels_network.c index 23109d3..29e0e99 100644 --- a/src/parallels/parallels_network.c +++ b/src/parallels/parallels_network.c @@ -66,7 +66,7 @@ static int parallelsGetBridgedNetInfo(virNetworkDefPtr def, virJSONValuePtr jobj goto cleanup; } - if (!(def->bridge = strdup(last_component(bridgePath)))) { + if (VIR_STRDUP(def->bridge, last_component(bridgePath)) < 0) { virReportOOMError(); goto cleanup; } @@ -130,7 +130,7 @@ static int parallelsGetHostOnlyNetInfo(virNetworkDefPtr def, const char *name) goto cleanup; } - if (!(def->ips[0].family = strdup("ipv4"))) { + if (VIR_STRDUP(def->ips[0].family, "ipv4") < 0) { virReportOOMError(); goto cleanup; }; @@ -207,7 +207,7 @@ parallelsLoadNetwork(parallelsConnPtr privconn, virJSONValuePtr jobj) goto cleanup; } - if (!(def->name = strdup(tmp))) + if (VIR_STRDUP(def->name, tmp) < 0) goto no_memory; /* Network names are unique in Parallels Cloud Server, so we can make @@ -264,7 +264,7 @@ parallelsAddRoutedNetwork(parallelsConnPtr privconn) def->forward.type = VIR_NETWORK_FORWARD_ROUTE; - if (!(def->name = strdup(PARALLELS_ROUTED_NETWORK_NAME))) + if (VIR_STRDUP(def->name, PARALLELS_ROUTED_NETWORK_NAME) < 0) goto no_memory; if (virUUIDParse(PARALLELS_ROUTED_NETWORK_UUID, def->uuid) < 0) { @@ -390,7 +390,7 @@ static int parallelsConnectListNetworks(virConnectPtr conn, for (i = 0 ; i < privconn->networks.count && got < nnames ; i++) { virNetworkObjLock(privconn->networks.objs[i]); if (virNetworkObjIsActive(privconn->networks.objs[i])) { - if (!(names[got] = strdup(privconn->networks.objs[i]->def->name))) { + if (VIR_STRDUP(names[got], privconn->networks.objs[i]->def->name) < 0) { virNetworkObjUnlock(privconn->networks.objs[i]); virReportOOMError(); goto cleanup; @@ -438,7 +438,7 @@ static int parallelsConnectListDefinedNetworks(virConnectPtr conn, for (i = 0 ; i < privconn->networks.count && got < nnames ; i++) { virNetworkObjLock(privconn->networks.objs[i]); if (!virNetworkObjIsActive(privconn->networks.objs[i])) { - if (!(names[got] = strdup(privconn->networks.objs[i]->def->name))) { + if (VIR_STRDUP(names[got], privconn->networks.objs[i]->def->name) < 0) { virNetworkObjUnlock(privconn->networks.objs[i]); virReportOOMError(); goto cleanup; diff --git a/src/parallels/parallels_storage.c b/src/parallels/parallels_storage.c index 4c98e43..97e2206 100644 --- a/src/parallels/parallels_storage.c +++ b/src/parallels/parallels_storage.c @@ -136,17 +136,13 @@ static char *parallelsMakePoolName(virConnectPtr conn, const char *path) bool found = false; int j; - if (!(name = strdup(path))) { + if (VIR_STRDUP(name, path) < 0) { virReportOOMError(); return NULL; } - if (i == 0) - name = strdup(path); - else - ignore_value(virAsprintf(&name, "%s-%u", path, i)); - - if (!name) { + if ((!i && VIR_STRDUP(name, path) < 0) || + (i && virAsprintf(&name, "%s-%u", path, i) < 0)) { virReportOOMError(); return 0; } @@ -195,7 +191,8 @@ parallelsPoolCreateByPath(virConnectPtr conn, const char *path) } def->type = VIR_STORAGE_POOL_DIR; - def->target.path = strdup(path); + if (VIR_STRDUP(def->target.path, path) < 0) + goto no_memory; if (!(pool = virStoragePoolObjAssignDef(pools, def))) goto error; @@ -231,8 +228,7 @@ parallelsPoolAddByDomain(virConnectPtr conn, virDomainObjPtr dom) virStoragePoolObjPtr pool = NULL; int j; - poolPath = mdir_name(pdom->home); - if (!poolPath) { + if (VIR_STRDUP(poolPath, mdir_name(pdom->home)) < 0) { virReportOOMError(); return NULL; } @@ -324,7 +320,7 @@ static int parallelsAddDiskVolume(virStoragePoolObjPtr pool, if (!(def->target.path = realpath(diskPath, NULL))) goto no_memory; - if (!(def->key = strdup(def->target.path))) + if (VIR_STRDUP(def->key, def->target.path) < 0) goto no_memory; if (VIR_REALLOC_N(pool->volumes.objs, pool->volumes.count + 1) < 0) @@ -425,7 +421,7 @@ static int parallelsLoadPools(virConnectPtr conn) char *base = NULL; size_t i; - if ((base = strdup(SYSCONFDIR "/libvirt")) == NULL) + if (VIR_STRDUP(base, SYSCONFDIR "/libvirt") < 0) goto out_of_memory; /* Configuration path is /etc/libvirt/parallels-storage/... . */ @@ -540,7 +536,7 @@ parallelsConnectListStoragePools(virConnectPtr conn, char **const names, int nna for (i = 0; i < privconn->pools.count && n < nnames; i++) { virStoragePoolObjLock(privconn->pools.objs[i]); if (virStoragePoolObjIsActive(privconn->pools.objs[i]) && - !(names[n++] = strdup(privconn->pools.objs[i]->def->name))) { + VIR_STRDUP(names[n++], privconn->pools.objs[i]->def->name) < 0) { virStoragePoolObjUnlock(privconn->pools.objs[i]); goto no_memory; } @@ -590,7 +586,7 @@ parallelsConnectListDefinedStoragePools(virConnectPtr conn, for (i = 0; i < privconn->pools.count && n < nnames; i++) { virStoragePoolObjLock(privconn->pools.objs[i]); if (!virStoragePoolObjIsActive(privconn->pools.objs[i]) && - !(names[n++] = strdup(privconn->pools.objs[i]->def->name))) { + VIR_STRDUP(names[n++], privconn->pools.objs[i]->def->name) < 0) { virStoragePoolObjUnlock(privconn->pools.objs[i]); goto no_memory; } @@ -758,8 +754,7 @@ parallelsStoragePoolDefineXML(virConnectPtr conn, } def = NULL; - pool->configFile = strdup("\0"); - if (!pool->configFile) { + if (VIR_STRDUP(pool->configFile, "\0") < 0) { virReportOOMError(); goto cleanup; } @@ -1085,7 +1080,7 @@ parallelsStoragePoolListVolumes(virStoragePoolPtr pool, } for (i = 0; i < privpool->volumes.count && n < maxnames; i++) { - if ((names[n++] = strdup(privpool->volumes.objs[i]->name)) == NULL) { + if (VIR_STRDUP(names[n++], privpool->volumes.objs[i]->name) < 0) { virReportOOMError(); goto error; } @@ -1271,8 +1266,7 @@ parallelsStorageVolDefineXML(virStoragePoolObjPtr pool, goto cleanup; } - privvol->key = strdup(privvol->target.path); - if (privvol->key == NULL) { + if (VIR_STRDUP(privvol->key, privvol->target.path) < 0) { virReportOOMError(); goto cleanup; } @@ -1412,8 +1406,7 @@ parallelsStorageVolCreateXMLFrom(virStoragePoolPtr pool, goto cleanup; } - privvol->key = strdup(privvol->target.path); - if (privvol->key == NULL) { + if (VIR_STRDUP(privvol->key, privvol->target.path) < 0) { virReportOOMError(); goto cleanup; } @@ -1659,8 +1652,7 @@ parallelsStorageVolGetPath(virStorageVolPtr vol) goto cleanup; } - ret = strdup(privvol->target.path); - if (ret == NULL) + if (VIR_STRDUP(ret, privvol->target.path) < 0) virReportOOMError(); cleanup: -- 1.8.1.5

--- src/phyp/phyp_driver.c | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index 85eb650..1cb92d2 100644 --- a/src/phyp/phyp_driver.c +++ b/src/phyp/phyp_driver.c @@ -954,9 +954,7 @@ openSSHSession(virConnectPtr conn, virConnectAuthPtr auth, } if (conn->uri->user != NULL) { - username = strdup(conn->uri->user); - - if (username == NULL) { + if (VIR_STRDUP(username, conn->uri->user) < 0) { virReportOOMError(); goto err; } @@ -1141,12 +1139,10 @@ phypConnectOpen(virConnectPtr conn, if (conn->uri->path) { /* need to shift one byte in order to remove the first "/" of URI component */ - if (conn->uri->path[0] == '/') - managed_system = strdup(conn->uri->path + 1); - else - managed_system = strdup(conn->uri->path); - - if (!managed_system) { + if ((conn->uri->path[0] == '/' && + VIR_STRDUP(managed_system, conn->uri->path + 1) < 0) || + (conn->uri->path[0] != '/' && + VIR_STRDUP(managed_system, conn->uri->path) < 0)) { virReportOOMError(); goto failure; } @@ -1498,9 +1494,7 @@ phypGetBackingDevice(virConnectPtr conn, const char *managed_system, else goto cleanup; - backing_device = strdup(char_ptr); - - if (backing_device == NULL) { + if (VIR_STRDUP(backing_device, char_ptr) < 0) { virReportOOMError(); goto cleanup; } @@ -1731,9 +1725,7 @@ phypDomainAttachDevice(virDomainPtr domain, const char *xml) goto cleanup; } - def->os.type = strdup("aix"); - - if (def->os.type == NULL) { + if (VIR_STRDUP(def->os.type, "aix") < 0) { virReportOOMError(); goto cleanup; } @@ -2281,9 +2273,7 @@ phypStorageVolGetXMLDesc(virStorageVolPtr vol, unsigned int flags) goto cleanup; } - voldef.key = strdup(vol->key); - - if (voldef.key == NULL) { + if (VIR_STRDUP(voldef.key, vol->key) < 0) { virReportOOMError(); goto cleanup; } @@ -2399,7 +2389,7 @@ phypStoragePoolListVolumes(virStoragePoolPtr pool, char **const volumes, if (char_ptr) { *char_ptr = '\0'; - if ((volumes[got++] = strdup(volumes_list)) == NULL) { + if (VIR_STRDUP(volumes[got++], volumes_list) < 0) { virReportOOMError(); goto cleanup; } @@ -2600,7 +2590,7 @@ phypConnectListStoragePools(virConnectPtr conn, char **const pools, int npools) if (char_ptr) { *char_ptr = '\0'; - if ((pools[got++] = strdup(storage_pools)) == NULL) { + if (VIR_STRDUP(pools[got++], storage_pools) < 0) { virReportOOMError(); goto cleanup; } @@ -3067,7 +3057,7 @@ phypConnectListInterfaces(virConnectPtr conn, char **const names, int nnames) if (char_ptr) { *char_ptr = '\0'; - if ((names[got++] = strdup(networks)) == NULL) { + if (VIR_STRDUP(names[got++], networks) < 0) { virReportOOMError(); goto cleanup; } @@ -3234,7 +3224,7 @@ phypConnectListDefinedDomains(virConnectPtr conn, char **const names, int nnames if (char_ptr) { *char_ptr = '\0'; - if ((names[got++] = strdup(domains)) == NULL) { + if (VIR_STRDUP(names[got++], domains) < 0) { virReportOOMError(); goto cleanup; } -- 1.8.1.5

This requires some changes to libvirt,h,in and remote driver as well for const correctness sake. --- include/libvirt/libvirt.h.in | 10 +- src/qemu/qemu_capabilities.c | 37 +++--- src/qemu/qemu_cgroup.c | 3 +- src/qemu/qemu_command.c | 281 +++++++++++++++++-------------------------- src/qemu/qemu_conf.c | 32 +++-- src/qemu/qemu_domain.c | 16 +-- src/qemu/qemu_driver.c | 91 +++++++------- src/qemu/qemu_hotplug.c | 8 +- src/qemu/qemu_migration.c | 14 +-- src/qemu/qemu_monitor_json.c | 40 +++--- src/qemu/qemu_monitor_text.c | 9 +- src/qemu/qemu_process.c | 56 +++++---- src/remote/remote_driver.c | 2 +- 13 files changed, 258 insertions(+), 341 deletions(-) diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in index 693b834..9a8090d 100644 --- a/include/libvirt/libvirt.h.in +++ b/include/libvirt/libvirt.h.in @@ -1294,7 +1294,7 @@ typedef enum { struct _virConnectCredential { int type; /* One of virConnectCredentialType constants */ - const char *prompt; /* Prompt to show to user */ + char *prompt; /* Prompt to show to user */ const char *challenge; /* Additional challenge to show */ const char *defresult; /* Optional default result */ char *result; /* Result to be filled with user response (or defresult) */ @@ -4504,8 +4504,8 @@ typedef enum { */ struct _virDomainEventGraphicsAddress { int family; /* Address family, virDomainEventGraphicsAddressType */ - const char *node; /* Address of node (eg IP address, or UNIX path) */ - const char *service; /* Service name/number (eg TCP port, or NULL) */ + char *node; /* Address of node (eg IP address, or UNIX path) */ + char *service; /* Service name/number (eg TCP port, or NULL) */ }; typedef struct _virDomainEventGraphicsAddress virDomainEventGraphicsAddress; typedef virDomainEventGraphicsAddress *virDomainEventGraphicsAddressPtr; @@ -4520,8 +4520,8 @@ typedef virDomainEventGraphicsAddress *virDomainEventGraphicsAddressPtr; * some examples are 'x509dname' and 'saslUsername'. */ struct _virDomainEventGraphicsSubjectIdentity { - const char *type; /* Type of identity */ - const char *name; /* Identity value */ + char *type; /* Type of identity */ + char *name; /* Identity value */ }; typedef struct _virDomainEventGraphicsSubjectIdentity virDomainEventGraphicsSubjectIdentity; typedef virDomainEventGraphicsSubjectIdentity *virDomainEventGraphicsSubjectIdentityPtr; diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index a3a8d1f..0c7d237 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -362,7 +362,7 @@ virQEMUCapsParseMachineTypesStr(const char *output, if (!(t = strchr(p, ' ')) || (next && t >= next)) continue; - if (!(name = strndup(p, t - p))) + if (VIR_STRNDUP(name, p, t - p) < 0) goto no_memory; p = t; @@ -374,7 +374,7 @@ virQEMUCapsParseMachineTypesStr(const char *output, if (!(t = strchr(p, ')')) || (next && t >= next)) continue; - if (!(canonical = strndup(p, t - p))) { + if (VIR_STRNDUP(canonical, p, t - p) < 0) { VIR_FREE(name); goto no_memory; } @@ -499,7 +499,7 @@ virQEMUCapsParseX86Models(const char *output, len -= 2; } - if (!(qemuCaps->cpuDefinitions[qemuCaps->ncpuDefinitions - 1] = strndup(p, len))) { + if (VIR_STRNDUP(qemuCaps->cpuDefinitions[qemuCaps->ncpuDefinitions - 1], p, len) < 0) { virReportOOMError(); goto cleanup; } @@ -552,7 +552,7 @@ virQEMUCapsParsePPCModels(const char *output, len = t - p - 1; - if (!(qemuCaps->cpuDefinitions[qemuCaps->ncpuDefinitions - 1] = strndup(p, len))) { + if (VIR_STRNDUP(qemuCaps->cpuDefinitions[qemuCaps->ncpuDefinitions - 1], p, len) < 0) { virReportOOMError(); goto cleanup; } @@ -1498,7 +1498,7 @@ virQEMUCapsParseDeviceStrObjectTypes(const char *str, virReportOOMError(); goto cleanup; } - if (!(typelist[ntypelist-1] = strndup(tmp, end-tmp))) { + if (VIR_STRNDUP(typelist[ntypelist-1], tmp, end-tmp) < 0) { virReportOOMError(); goto cleanup; } @@ -1555,7 +1555,7 @@ virQEMUCapsParseDeviceStrObjectProps(const char *str, virReportOOMError(); goto cleanup; } - if (!(proplist[nproplist-1] = strndup(tmp, end-tmp))) { + if (VIR_STRNDUP(proplist[nproplist-1], tmp, end-tmp) < 0) { virReportOOMError(); goto cleanup; } @@ -1726,7 +1726,7 @@ virQEMUCapsPtr virQEMUCapsNewCopy(virQEMUCapsPtr qemuCaps) goto no_memory; ret->ncpuDefinitions = qemuCaps->ncpuDefinitions; for (i = 0 ; i < qemuCaps->ncpuDefinitions ; i++) { - if (!(ret->cpuDefinitions[i] = strdup(qemuCaps->cpuDefinitions[i]))) + if (VIR_STRDUP(ret->cpuDefinitions[i], qemuCaps->cpuDefinitions[i]) < 0) goto no_memory; } @@ -1736,10 +1736,10 @@ virQEMUCapsPtr virQEMUCapsNewCopy(virQEMUCapsPtr qemuCaps) goto no_memory; ret->nmachineTypes = qemuCaps->nmachineTypes; for (i = 0 ; i < qemuCaps->nmachineTypes ; i++) { - if (!(ret->machineTypes[i] = strdup(qemuCaps->machineTypes[i]))) + if (VIR_STRDUP(ret->machineTypes[i], qemuCaps->machineTypes[i]) < 0) goto no_memory; if (qemuCaps->machineAliases[i] && - !(ret->machineAliases[i] = strdup(qemuCaps->machineAliases[i]))) + VIR_STRDUP(ret->machineAliases[i], qemuCaps->machineAliases[i]) < 0) goto no_memory; } @@ -1848,8 +1848,9 @@ unsigned int virQEMUCapsGetKVMVersion(virQEMUCapsPtr qemuCaps) int virQEMUCapsAddCPUDefinition(virQEMUCapsPtr qemuCaps, const char *name) { - char *tmp = strdup(name); - if (!tmp) { + char *tmp; + + if (VIR_STRDUP(tmp, name) < 0) { virReportOOMError(); return -1; } @@ -1897,12 +1898,12 @@ int virQEMUCapsGetMachineTypesCaps(virQEMUCapsPtr qemuCaps, if (VIR_ALLOC(mach) < 0) goto no_memory; if (qemuCaps->machineAliases[i]) { - if (!(mach->name = strdup(qemuCaps->machineAliases[i]))) + if (VIR_STRDUP(mach->name, qemuCaps->machineAliases[i]) < 0) goto no_memory; - if (!(mach->canonical = strdup(qemuCaps->machineTypes[i]))) + if (VIR_STRDUP(mach->canonical, qemuCaps->machineTypes[i]) < 0) goto no_memory; } else { - if (!(mach->name = strdup(qemuCaps->machineTypes[i]))) + if (VIR_STRDUP(mach->name, qemuCaps->machineTypes[i]) < 0) goto no_memory; } (*machines)[i] = mach; @@ -2092,12 +2093,12 @@ virQEMUCapsProbeQMPMachineTypes(virQEMUCapsPtr qemuCaps, for (i = 0 ; i < nmachines ; i++) { if (machines[i]->alias) { - if (!(qemuCaps->machineAliases[i] = strdup(machines[i]->alias))) { + if (VIR_STRDUP(qemuCaps->machineAliases[i], machines[i]->alias) < 0) { virReportOOMError(); goto cleanup; } } - if (!(qemuCaps->machineTypes[i] = strdup(machines[i]->name))) { + if (VIR_STRDUP(qemuCaps->machineTypes[i], machines[i]->name) < 0) { virReportOOMError(); goto cleanup; } @@ -2590,7 +2591,7 @@ virQEMUCapsPtr virQEMUCapsNewForBinary(const char *binary, struct stat sb; int rv; - if (!(qemuCaps->binary = strdup(binary))) + if (VIR_STRDUP(qemuCaps->binary, binary) < 0) goto no_memory; /* We would also want to check faccessat if we cared about ACLs, @@ -2672,7 +2673,7 @@ virQEMUCapsCacheNew(const char *libDir, if (!(cache->binaries = virHashCreate(10, virQEMUCapsHashDataFree))) goto error; - if (!(cache->libDir = strdup(libDir))) { + if (VIR_STRDUP(cache->libDir, libDir) < 0) { virReportOOMError(); goto error; } diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index 386751b..7a25db1 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -31,6 +31,7 @@ #include "viralloc.h" #include "virerror.h" #include "domain_audit.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_QEMU @@ -235,7 +236,7 @@ int qemuInitCgroup(virQEMUDriverPtr driver, goto cleanup; } - if (!(res->partition = strdup("/machine"))) { + if (VIR_STRDUP(res->partition, "/machine") < 0) { virReportOOMError(); VIR_FREE(res); goto cleanup; diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index e2201ec..74fb9eb 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -322,7 +322,7 @@ qemuNetworkIfaceConnect(virDomainDefPtr def, return -1; } else if (actualType == VIR_DOMAIN_NET_TYPE_BRIDGE) { - if (!(brname = strdup(virDomainNetGetActualBridgeName(net)))) { + if (VIR_STRDUP(brname, virDomainNetGetActualBridgeName(net)) < 0) { virReportOOMError(); return -1; } @@ -337,7 +337,7 @@ qemuNetworkIfaceConnect(virDomainDefPtr def, STRPREFIX(net->ifname, VIR_NET_GENERATED_PREFIX) || strchr(net->ifname, '%')) { VIR_FREE(net->ifname); - if (!(net->ifname = strdup(VIR_NET_GENERATED_PREFIX "%d"))) { + if (VIR_STRDUP(net->ifname, VIR_NET_GENERATED_PREFIX "%d") < 0) { virReportOOMError(); goto cleanup; } @@ -485,14 +485,15 @@ int qemuDomainNetVLAN(virDomainNetDefPtr def) static int qemuAssignDeviceDiskAliasLegacy(virDomainDiskDefPtr disk) { char *dev_name; + int rc; if (disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM && STREQ(disk->dst, "hdc")) - dev_name = strdup("cdrom"); + rc = VIR_STRDUP(dev_name, "cdrom"); else - dev_name = strdup(disk->dst); + rc = VIR_STRDUP(dev_name, disk->dst); - if (!dev_name) { + if (rc < 0) { virReportOOMError(); return -1; } @@ -513,7 +514,7 @@ char *qemuDeviceDriveHostAlias(virDomainDiskDefPtr disk, return NULL; } } else { - if (!(ret = strdup(disk->info.alias))) { + if (VIR_STRDUP(ret, disk->info.alias) < 0) { virReportOOMError(); return NULL; } @@ -2418,14 +2419,10 @@ static int qemuAddRBDHost(virDomainDiskDefPtr disk, char *hostport) if (port) { *port = '\0'; port += skip; - disk->hosts[disk->nhosts-1].port = strdup(port); - if (!disk->hosts[disk->nhosts-1].port) - goto no_memory; - } else { - disk->hosts[disk->nhosts-1].port = strdup("6789"); - if (!disk->hosts[disk->nhosts-1].port) + if (VIR_STRDUP(disk->hosts[disk->nhosts-1].port, port) < 0) goto no_memory; - } + } else if (VIR_STRDUP(disk->hosts[disk->nhosts-1].port, "6789") < 0) + goto no_memory; parts = virStringSplit(hostport, "\\:", 0); if (!parts) @@ -2455,8 +2452,7 @@ static int qemuParseRBDString(virDomainDiskDefPtr disk) p = strchr(disk->src, ':'); if (p) { - options = strdup(p + 1); - if (!options) + if (VIR_STRDUP(options, p + 1) < 0) goto no_memory; *p = '\0'; } @@ -2482,11 +2478,10 @@ static int qemuParseRBDString(virDomainDiskDefPtr disk) *e = '\0'; } - if (STRPREFIX(p, "id=")) { - disk->auth.username = strdup(p + strlen("id=")); - if (!disk->auth.username) - goto no_memory; - } + if (STRPREFIX(p, "id=") && + VIR_STRDUP(disk->auth.username, p + strlen("id=")) < 0) + goto no_memory; + if (STRPREFIX(p, "mon_host=")) { char *h, *sep; @@ -2555,8 +2550,7 @@ qemuParseDriveURIString(virDomainDiskDefPtr def, virURIPtr uri, def->nhosts = 0; /* set to 1 once everything succeeds */ if (def->hosts->transport != VIR_DOMAIN_DISK_PROTO_TRANS_UNIX) { - def->hosts->name = strdup(uri->server); - if (!def->hosts->name) + if (VIR_STRDUP(def->hosts->name, uri->server) < 0) goto no_memory; if (virAsprintf(&def->hosts->port, "%d", uri->port) < 0) @@ -2567,8 +2561,7 @@ qemuParseDriveURIString(virDomainDiskDefPtr def, virURIPtr uri, if (uri->query) { if (STRPREFIX(uri->query, "socket=")) { sock = strchr(uri->query, '=') + 1; - def->hosts->socket = strdup(sock); - if (!def->hosts->socket) + if (VIR_STRDUP(def->hosts->socket, sock) < 0) goto no_memory; } else { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -2580,8 +2573,7 @@ qemuParseDriveURIString(virDomainDiskDefPtr def, virURIPtr uri, if (uri->path) { volimg = uri->path + 1; /* skip the prefix slash */ VIR_FREE(def->src); - def->src = strdup(volimg); - if (!def->src) + if (VIR_STRDUP(def->src, volimg) < 0) goto no_memory; } else { VIR_FREE(def->src); @@ -2593,8 +2585,7 @@ qemuParseDriveURIString(virDomainDiskDefPtr def, virURIPtr uri, if (secret) *secret = '\0'; - def->auth.username = strdup(uri->user); - if (!def->auth.username) + if (VIR_STRDUP(def->auth.username, uri->user) < 0) goto no_memory; } @@ -2675,7 +2666,8 @@ qemuParseNBDString(virDomainDiskDefPtr disk) *src++ = '\0'; h->transport = VIR_DOMAIN_DISK_PROTO_TRANS_UNIX; - h->socket = strdup(host + strlen("unix:")); + if (VIR_STRDUP(h->socket, host + strlen("unix:")) < 0) + goto no_memory; } else { port = strchr(host, ':'); if (!port) { @@ -2685,22 +2677,19 @@ qemuParseNBDString(virDomainDiskDefPtr disk) } *port++ = '\0'; - h->name = strdup(host); - if (!h->name) + if (VIR_STRDUP(h->name, host) < 0) goto no_memory; src = strchr(port, ':'); if (src) *src++ = '\0'; - h->port = strdup(port); - if (!h->port) + if (VIR_STRDUP(h->port, port) < 0) goto no_memory; } if (src && STRPREFIX(src, "exportname=")) { - src = strdup(strchr(src, '=') + 1); - if (!src) + if (VIR_STRDUP(src, strchr(src, '=') + 1) < 0) goto no_memory; } else { src = NULL; @@ -2751,8 +2740,7 @@ qemuBuildDriveURIString(virConnectPtr conn, transp = virDomainDiskProtocolTransportTypeToString(disk->hosts->transport); if (disk->hosts->transport == VIR_DOMAIN_DISK_PROTO_TRANS_TCP) { - tmpscheme = strdup(scheme); - if (tmpscheme == NULL) + if (VIR_STRDUP(tmpscheme, scheme) < 0) goto no_memory; } else { if (virAsprintf(&tmpscheme, "%s+%s", scheme, transp) < 0) @@ -5454,7 +5442,7 @@ qemuBuildCpuArgStr(const virQEMUDriverPtr driver, virBufferAddLit(&buf, "host"); } else { if (VIR_ALLOC(guest) < 0 || - (cpu->vendor_id && !(guest->vendor_id = strdup(cpu->vendor_id)))) + (cpu->vendor_id && VIR_STRDUP(guest->vendor_id, cpu->vendor_id) < 0)) goto no_memory; guest->arch = host->arch; @@ -7035,10 +7023,8 @@ qemuBuildCommandLine(virConnectPtr conn, } 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 = strdup(disk->src))) { - goto no_memory; - } + } else if (VIR_STRDUP(file, disk->src) < 0) { + goto no_memory; } /* Don't start with source if the tray is open for @@ -7872,7 +7858,7 @@ qemuBuildCommandLine(virConnectPtr conn, goto error; } - if (!(optstr = strdup(model))) + if (VIR_STRDUP(optstr, model) < 0) goto no_memory; } virCommandAddArg(cmd, optstr); @@ -8308,12 +8294,14 @@ static int qemuStringToArgvEnv(const char *args, next = strchr(curr, '\n'); if (next) { - arg = strndup(curr, next-curr); + if (VIR_STRNDUP(arg, curr, next-curr) < 0) + goto no_memory; if (*next == '\'' || *next == '"') next++; } else { - arg = strdup(curr); + if (VIR_STRDUP(arg, curr) < 0) + goto no_memory; } if (!arg) @@ -8448,12 +8436,12 @@ qemuParseKeywords(const char *str, separator = endmark; } - if (!(keyword = strndup(start, separator - start))) + if (VIR_STRNDUP(keyword, start, separator - start) < 0) goto no_memory; if (separator < endmark) { separator++; - if (!(value = strndup(separator, endmark - separator))) { + if (VIR_STRNDUP(value, separator, endmark - separator) < 0) { VIR_FREE(keyword); goto no_memory; } @@ -8525,6 +8513,7 @@ qemuParseCommandLineDisk(virDomainXMLOptionPtr xmlopt, int busid = -1; int unitid = -1; int trans = VIR_DOMAIN_DISK_TRANS_DEFAULT; + int rc; if ((nkeywords = qemuParseKeywords(val, &keywords, @@ -8560,8 +8549,7 @@ qemuParseCommandLineDisk(virDomainXMLOptionPtr xmlopt, def->type = VIR_DOMAIN_DISK_TYPE_NETWORK; def->protocol = VIR_DOMAIN_DISK_PROTOCOL_RBD; - def->src = strdup(p + strlen("rbd:")); - if (!def->src) { + if (VIR_STRDUP(def->src, p + strlen("rbd:")) < 0) { virReportOOMError(); goto error; } @@ -8589,8 +8577,7 @@ qemuParseCommandLineDisk(virDomainXMLOptionPtr xmlopt, def->type = VIR_DOMAIN_DISK_TYPE_NETWORK; def->protocol = VIR_DOMAIN_DISK_PROTOCOL_SHEEPDOG; - def->src = strdup(p + strlen("sheepdog:")); - if (!def->src) { + if (VIR_STRDUP(def->src, p + strlen("sheepdog:")) < 0) { virReportOOMError(); goto error; } @@ -8612,15 +8599,13 @@ qemuParseCommandLineDisk(virDomainXMLOptionPtr xmlopt, } def->nhosts = 1; def->hosts->name = def->src; - def->hosts->port = strdup(port); - if (!def->hosts->port) { + if (VIR_STRDUP(def->hosts->port, port) < 0) { virReportOOMError(); goto error; } def->hosts->transport = VIR_DOMAIN_DISK_PROTO_TRANS_TCP; def->hosts->socket = NULL; - def->src = strdup(vdi); - if (!def->src) { + if (VIR_STRDUP(def->src, vdi) < 0) { virReportOOMError(); goto error; } @@ -8648,8 +8633,7 @@ qemuParseCommandLineDisk(virDomainXMLOptionPtr xmlopt, } else if (STREQ(values[i], "floppy")) def->device = VIR_DOMAIN_DISK_DEVICE_FLOPPY; } else if (STREQ(keywords[i], "format")) { - def->driverName = strdup("qemu"); - if (!def->driverName) { + if (VIR_STRDUP(def->driverName, "qemu") < 0) { virReportOOMError(); goto error; } @@ -8792,18 +8776,18 @@ qemuParseCommandLineDisk(virDomainXMLOptionPtr xmlopt, } if (def->bus == VIR_DOMAIN_DISK_BUS_IDE) { - def->dst = strdup("hda"); + rc = VIR_STRDUP(def->dst, "hda"); } else if (def->bus == VIR_DOMAIN_DISK_BUS_SCSI) { - def->dst = strdup("sda"); + rc = VIR_STRDUP(def->dst, "sda"); } else if (def->bus == VIR_DOMAIN_DISK_BUS_VIRTIO) { - def->dst = strdup("vda"); + rc = VIR_STRDUP(def->dst, "vda"); } else if (def->bus == VIR_DOMAIN_DISK_BUS_XEN) { - def->dst = strdup("xvda"); + rc = VIR_STRDUP(def->dst, "xvda"); } else { - def->dst = strdup("hda"); + rc = VIR_STRDUP(def->dst, "hda"); } - if (!def->dst) { + if (rc < 0) { virReportOOMError(); goto error; } @@ -9158,13 +9142,11 @@ qemuParseCommandLineChr(virDomainChrSourceDefPtr source, source->type = VIR_DOMAIN_CHR_TYPE_PTY; } else if (STRPREFIX(val, "file:")) { source->type = VIR_DOMAIN_CHR_TYPE_FILE; - source->data.file.path = strdup(val+strlen("file:")); - if (!source->data.file.path) + if (VIR_STRDUP(source->data.file.path, val+strlen("file:")) < 0) goto no_memory; } else if (STRPREFIX(val, "pipe:")) { source->type = VIR_DOMAIN_CHR_TYPE_PIPE; - source->data.file.path = strdup(val+strlen("pipe:")); - if (!source->data.file.path) + if (VIR_STRDUP(source->data.file.path, val+strlen("pipe:")) < 0) goto no_memory; } else if (STREQ(val, "stdio")) { source->type = VIR_DOMAIN_CHR_TYPE_STDIO; @@ -9177,40 +9159,30 @@ qemuParseCommandLineChr(virDomainChrSourceDefPtr source, svc2 = host2 ? strchr(host2, ':') : NULL; if (svc1 && (svc1 != val)) { - source->data.udp.connectHost = strndup(val, svc1-val); - - if (!source->data.udp.connectHost) + if (VIR_STRNDUP(source->data.udp.connectHost, val, svc1-val) < 0) goto no_memory; } if (svc1) { svc1++; - if (host2) - source->data.udp.connectService = strndup(svc1, host2-svc1); - else - source->data.udp.connectService = strdup(svc1); - - if (!source->data.udp.connectService) + if ((host2 && VIR_STRNDUP(source->data.udp.connectService, svc1, host2-svc1) < 0) || + (!host2 && VIR_STRDUP(source->data.udp.connectService, svc1) < 0)) goto no_memory; } if (host2) { host2++; if (svc2 && (svc2 != host2)) { - source->data.udp.bindHost = strndup(host2, svc2-host2); - - if (!source->data.udp.bindHost) + if (VIR_STRNDUP(source->data.udp.bindHost, host2, svc2-host2) < 0) goto no_memory; } } if (svc2) { svc2++; - if (STRNEQ(svc2, "0")) { - source->data.udp.bindService = strdup(svc2); - if (!source->data.udp.bindService) - goto no_memory; - } + if (STRNEQ(svc2, "0") && + VIR_STRDUP(source->data.udp.bindService, svc2) < 0) + goto no_memory; } } else if (STRPREFIX(val, "tcp:") || STRPREFIX(val, "telnet:")) { @@ -9232,16 +9204,11 @@ qemuParseCommandLineChr(virDomainChrSourceDefPtr source, if (opt && strstr(opt, "server")) source->data.tcp.listen = true; - source->data.tcp.host = strndup(val, svc-val); - if (!source->data.tcp.host) + if (VIR_STRNDUP(source->data.tcp.host, val, svc-val) < 0) goto no_memory; svc++; - if (opt) { - source->data.tcp.service = strndup(svc, opt-svc); - } else { - source->data.tcp.service = strdup(svc); - } - if (!source->data.tcp.service) + if ((opt && VIR_STRNDUP(source->data.tcp.service, svc, opt-svc) < 0) || + (!opt && VIR_STRDUP(source->data.tcp.service, svc) < 0)) goto no_memory; } else if (STRPREFIX(val, "unix:")) { const char *opt; @@ -9251,17 +9218,14 @@ qemuParseCommandLineChr(virDomainChrSourceDefPtr source, if (opt) { if (strstr(opt, "listen")) source->data.nix.listen = true; - source->data.nix.path = strndup(val, opt-val); - } else { - source->data.nix.path = strdup(val); - } - if (!source->data.nix.path) + if (VIR_STRNDUP(source->data.nix.path, val, opt-val) < 0) + goto no_memory; + } else if (VIR_STRDUP(source->data.nix.path, val) < 0) goto no_memory; } else if (STRPREFIX(val, "/dev")) { source->type = VIR_DOMAIN_CHR_TYPE_DEV; - source->data.file.path = strdup(val); - if (!source->data.file.path) + if (VIR_STRDUP(source->data.file.path, val) < 0) goto no_memory; } else { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -9315,12 +9279,8 @@ qemuParseCommandLineCPU(virDomainDefPtr dom, next++; if (p == val) { - if (next) - model = strndup(p, next - p - 1); - else - model = strdup(p); - - if (!model) + if ((next && VIR_STRNDUP(model, p, next - p - 1) < 0) || + (!next && VIR_STRDUP(model, p) < 0)) goto no_memory; if (!STREQ(model, "qemu32") && !STREQ(model, "qemu64")) { @@ -9344,12 +9304,8 @@ qemuParseCommandLineCPU(virDomainDefPtr dom, if (*p == '\0' || *p == ',') goto syntax; - if (next) - feature = strndup(p, next - p - 1); - else - feature = strdup(p); - - if (!feature) + if ((next && VIR_STRNDUP(feature, p, next - p - 1) < 0) || + (!next && VIR_STRDUP(feature, p) < 0)) goto no_memory; if (STREQ(feature, "kvmclock")) { @@ -9408,12 +9364,8 @@ qemuParseCommandLineCPU(virDomainDefPtr dom, if (*p == '\0' || *p == ',') goto syntax; - if (next) - feature = strndup(p, next - p - 1); - else - feature = strdup(p); - - if (!feature) + if ((next && VIR_STRNDUP(feature, p, next - p - 1) < 0) || + (!next && VIR_STRDUP(feature, p) < 0)) goto no_memory; dom->features |= (1 << VIR_DOMAIN_FEATURE_HYPERV); @@ -9632,7 +9584,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, def->onCrash = VIR_DOMAIN_LIFECYCLE_DESTROY; def->onPoweroff = VIR_DOMAIN_LIFECYCLE_DESTROY; def->virtType = VIR_DOMAIN_VIRT_QEMU; - if (!(def->emulator = strdup(progargv[0]))) + if (VIR_STRDUP(def->emulator, progargv[0]) < 0) goto no_memory; if (strstr(def->emulator, "kvm")) { @@ -9643,11 +9595,9 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, if (strstr(def->emulator, "xenner")) { def->virtType = VIR_DOMAIN_VIRT_KVM; - def->os.type = strdup("xen"); - } else { - def->os.type = strdup("hvm"); - } - if (!def->os.type) + if (VIR_STRDUP(def->os.type, "xen") < 0) + goto no_memory; + } else if (VIR_STRDUP(def->os.type, "hvm") < 0) goto no_memory; if (STRPREFIX(def->emulator, "qemu")) @@ -9711,8 +9661,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, if (STRPREFIX(val, "unix:")) { /* -vnc unix:/some/big/path */ - vnc->data.vnc.socket = strdup(val + 5); - if (!vnc->data.vnc.socket) { + if (VIR_STRDUP(vnc->data.vnc.socket, val + 5) < 0) { virDomainGraphicsDefFree(vnc); goto no_memory; } @@ -9809,8 +9758,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, disk->type = VIR_DOMAIN_DISK_TYPE_FILE; if (STREQ(arg, "-cdrom")) { disk->device = VIR_DOMAIN_DISK_DEVICE_CDROM; - disk->dst = strdup("hdc"); - if (!disk->dst) + if (VIR_STRDUP(disk->dst, "hdc") < 0) goto no_memory; disk->readonly = true; } else { @@ -9824,12 +9772,10 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, else disk->bus = VIR_DOMAIN_DISK_BUS_SCSI; } - disk->dst = strdup(arg + 1); - if (!disk->dst) + if (VIR_STRDUP(disk->dst, arg + 1) < 0) goto no_memory; } - disk->src = strdup(val); - if (!disk->src) + if (VIR_STRDUP(disk->src, val) < 0) goto no_memory; if (disk->type == VIR_DOMAIN_DISK_TYPE_NETWORK) { @@ -9863,11 +9809,9 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, goto no_memory; disk->nhosts = 1; disk->hosts->name = disk->src; - disk->hosts->port = strdup(port); - if (!disk->hosts->port) + if (VIR_STRDUP(disk->hosts->port, port) < 0) goto no_memory; - disk->src = strdup(vdi); - if (!disk->src) + if (VIR_STRDUP(disk->src, vdi) < 0) goto no_memory; } break; @@ -9915,23 +9859,23 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, def->clock.offset = VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME; } else if (STREQ(arg, "-kernel")) { WANT_VALUE(); - if (!(def->os.kernel = strdup(val))) + if (VIR_STRDUP(def->os.kernel, val) < 0) goto no_memory; } else if (STREQ(arg, "-bios")) { WANT_VALUE(); - if (!(def->os.loader = strdup(val))) + if (VIR_STRDUP(def->os.loader, val) < 0) goto no_memory; } else if (STREQ(arg, "-initrd")) { WANT_VALUE(); - if (!(def->os.initrd = strdup(val))) + if (VIR_STRDUP(def->os.initrd, val) < 0) goto no_memory; } else if (STREQ(arg, "-append")) { WANT_VALUE(); - if (!(def->os.cmdline = strdup(val))) + if (VIR_STRDUP(def->os.cmdline, val) < 0) goto no_memory; } else if (STREQ(arg, "-dtb")) { WANT_VALUE(); - if (!(def->os.dtb = strdup(val))) + if (VIR_STRDUP(def->os.dtb, val) < 0) goto no_memory; } else if (STREQ(arg, "-boot")) { const char *token = NULL; @@ -9976,10 +9920,10 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, WANT_VALUE(); process = strstr(val, ",process="); if (process == NULL) { - if (!(def->name = strdup(val))) + if (VIR_STRDUP(def->name, val) < 0) goto no_memory; } else { - if (!(def->name = strndup(val, process - val))) + if (VIR_STRNDUP(def->name, val, process - val) < 0) goto no_memory; } if (STREQ(def->name, "")) @@ -9990,10 +9934,10 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, WANT_VALUE(); params = strchr(val, ','); if (params == NULL) { - if (!(def->os.machine = strdup(val))) + if (VIR_STRDUP(def->os.machine, val) < 0) goto no_memory; } else { - if (!(def->os.machine = strndup(val, params - val))) + if (VIR_STRNDUP(def->os.machine, val, params - val) < 0) goto no_memory; while (params++) { @@ -10003,11 +9947,8 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, if (STRPREFIX(tmp, "dump-guest-core=")) { tmp += strlen("dump-guest-core="); - if (params) { - tmp = strndup(tmp, params - tmp); - if (tmp == NULL) - goto no_memory; - } + if (params && VIR_STRNDUP(tmp, tmp, params - tmp) < 0) + goto no_memory; def->mem.dump_core = virDomainMemDumpTypeFromString(tmp); if (def->mem.dump_core <= 0) def->mem.dump_core = VIR_DOMAIN_MEM_DUMP_DEFAULT; @@ -10076,8 +10017,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, } else if (STRPREFIX(val, "disk:")) { if (VIR_ALLOC(disk) < 0) goto no_memory; - disk->src = strdup(val + strlen("disk:")); - if (!disk->src) + if (VIR_STRDUP(disk->src, val + strlen("disk:")) < 0) goto no_memory; if (STRPREFIX(disk->src, "/dev/")) disk->type = VIR_DOMAIN_DISK_TYPE_BLOCK; @@ -10085,7 +10025,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, disk->type = VIR_DOMAIN_DISK_TYPE_FILE; disk->device = VIR_DOMAIN_DISK_DEVICE_DISK; disk->bus = VIR_DOMAIN_DISK_BUS_USB; - if (!(disk->dst = strdup("sda")) || + if (VIR_STRDUP(disk->dst, "sda") < 0 || VIR_REALLOC_N(def->disks, def->ndisks+1) < 0) goto no_memory; def->disks[def->ndisks++] = disk; @@ -10188,8 +10128,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, def->watchdog->action = action; } else if (STREQ(arg, "-bootloader")) { WANT_VALUE(); - def->os.bootloader = strdup(val); - if (!def->os.bootloader) + if (VIR_STRDUP(def->os.bootloader, val) < 0) goto no_memory; } else if (STREQ(arg, "-vmwarevga")) { video = VIR_DOMAIN_VIDEO_TYPE_VMVGA; @@ -10223,7 +10162,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, } else if (STREQ(arg, "-pidfile")) { WANT_VALUE(); if (pidfile) - if (!(*pidfile = strdup(val))) + if (VIR_STRDUP(*pidfile, val) < 0) goto no_memory; } else if (STREQ(arg, "-incoming")) { WANT_VALUE(); @@ -10306,8 +10245,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, arg); if (VIR_REALLOC_N(cmd->args, cmd->num_args+1) < 0) goto no_memory; - cmd->args[cmd->num_args] = strdup(arg); - if (cmd->args[cmd->num_args] == NULL) + if (VIR_STRDUP(cmd->args[cmd->num_args], arg) < 0) goto no_memory; cmd->num_args++; } @@ -10337,8 +10275,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, _("could not parse CEPH_ARGS '%s'"), ceph_args); goto error; } - hosts = strdup(strchr(ceph_args, ' ') + 1); - if (!hosts) + if (VIR_STRDUP(hosts, strchr(ceph_args, ' ') + 1) < 0) goto no_memory; first_rbd_disk->nhosts = 0; token = strtok_r(hosts, ",", &saveptr); @@ -10350,15 +10287,13 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, port = strchr(token, ':'); if (port) { *port++ = '\0'; - port = strdup(port); - if (!port) { + if (VIR_STRDUP(port, port) < 0) { VIR_FREE(hosts); goto no_memory; } } first_rbd_disk->hosts[first_rbd_disk->nhosts].port = port; - first_rbd_disk->hosts[first_rbd_disk->nhosts].name = strdup(token); - if (!first_rbd_disk->hosts[first_rbd_disk->nhosts].name) { + if (VIR_STRDUP(first_rbd_disk->hosts[first_rbd_disk->nhosts].name, token) < 0) { VIR_FREE(hosts); goto no_memory; } @@ -10384,7 +10319,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, def->os.arch, virDomainVirtTypeToString(def->virtType)); if (defaultMachine != NULL) - if (!(def->os.machine = strdup(defaultMachine))) + if (VIR_STRDUP(def->os.machine, defaultMachine) < 0) goto no_memory; } @@ -10397,12 +10332,12 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, sdl->type = VIR_DOMAIN_GRAPHICS_TYPE_SDL; sdl->data.sdl.fullscreen = fullscreen; if (display && - !(sdl->data.sdl.display = strdup(display))) { + VIR_STRDUP(sdl->data.sdl.display, display) < 0) { VIR_FREE(sdl); goto no_memory; } if (xauth && - !(sdl->data.sdl.xauth = strdup(xauth))) { + VIR_STRDUP(sdl->data.sdl.xauth, xauth) < 0) { VIR_FREE(sdl); goto no_memory; } @@ -10513,7 +10448,7 @@ cleanup: static int qemuParseProcFileStrings(int pid_value, const char *name, - const char ***list) + char ***list) { char *path = NULL; int ret = -1; @@ -10521,7 +10456,7 @@ static int qemuParseProcFileStrings(int pid_value, ssize_t len; char *tmp; size_t nstr = 0; - const char **str = NULL; + char **str = NULL; int i; if (virAsprintf(&path, "/proc/%d/%s", pid_value, name) < 0) { @@ -10539,7 +10474,7 @@ static int qemuParseProcFileStrings(int pid_value, goto cleanup; } - if (!(str[nstr-1] = strdup(tmp))) { + if (VIR_STRDUP(str[nstr-1], tmp) < 0) { virReportOOMError(); goto cleanup; } @@ -10578,8 +10513,8 @@ virDomainDefPtr qemuParseCommandLinePid(virCapsPtr qemuCaps, bool *monJSON) { virDomainDefPtr def = NULL; - const char **progargv = NULL; - const char **progenv = NULL; + char **progargv = NULL; + char **progenv = NULL; char *exepath = NULL; char *emulator; int i; @@ -10591,7 +10526,9 @@ virDomainDefPtr qemuParseCommandLinePid(virCapsPtr qemuCaps, qemuParseProcFileStrings(pid, "environ", &progenv) < 0) goto cleanup; - if (!(def = qemuParseCommandLine(qemuCaps, xmlopt, progenv, progargv, + if (!(def = qemuParseCommandLine(qemuCaps, xmlopt, + (const char **) progenv, + (const char **) progargv, pidfile, monConfig, monJSON))) goto cleanup; diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index c16b90d..384516b 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -140,7 +140,7 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged) "%s/log/libvirt/qemu", LOCALSTATEDIR) < 0) goto no_memory; - if ((cfg->configBaseDir = strdup(SYSCONFDIR "/libvirt")) == NULL) + if (VIR_STRDUP(cfg->configBaseDir, SYSCONFDIR "/libvirt") < 0) goto no_memory; if (virAsprintf(&cfg->stateDir, @@ -210,18 +210,16 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged) goto no_memory; - if (!(cfg->vncListen = strdup("127.0.0.1"))) + if (VIR_STRDUP(cfg->vncListen, "127.0.0.1") < 0) goto no_memory; - if (!(cfg->vncTLSx509certdir - = strdup(SYSCONFDIR "/pki/libvirt-vnc"))) + if (VIR_STRDUP(cfg->vncTLSx509certdir, SYSCONFDIR "/pki/libvirt-vnc") < 0) goto no_memory; - if (!(cfg->spiceListen = strdup("127.0.0.1"))) + if (VIR_STRDUP(cfg->spiceListen, "127.0.0.1") < 0) goto no_memory; - if (!(cfg->spiceTLSx509certdir - = strdup(SYSCONFDIR "/pki/libvirt-spice"))) + if (VIR_STRDUP(cfg->spiceTLSx509certdir, SYSCONFDIR "/pki/libvirt-spice") < 0) goto no_memory; cfg->remotePortMin = QEMU_REMOTE_PORT_MIN; @@ -240,7 +238,7 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged) } } #endif - if (!(cfg->bridgeHelperName = strdup("/usr/libexec/qemu-bridge-helper"))) + if (VIR_STRDUP(cfg->bridgeHelperName, "/usr/libexec/qemu-bridge-helper") < 0) goto no_memory; cfg->clearEmulatorCapabilities = true; @@ -347,7 +345,7 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg, CHECK_TYPE(NAME, VIR_CONF_STRING); \ if (p && p->str) { \ VIR_FREE(VAR); \ - if (!(VAR = strdup(p->str))) \ + if (VIR_STRDUP(VAR, p->str) < 0) \ goto no_memory; \ } @@ -379,7 +377,7 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg, goto no_memory; for (i = 0, pp = p->list; pp; i++, pp = pp->next) { - if (!(cfg->securityDriverNames[i] = strdup(pp->str))) + if (VIR_STRDUP(cfg->securityDriverNames[i], pp->str) < 0) goto no_memory; } cfg->securityDriverNames[len] = NULL; @@ -387,7 +385,7 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg, CHECK_TYPE("security_driver", VIR_CONF_STRING); if (p && p->str) { if (VIR_ALLOC_N(cfg->securityDriverNames, 2) < 0 || - !(cfg->securityDriverNames[0] = strdup(p->str))) + VIR_STRDUP(cfg->securityDriverNames[0], p->str) < 0) goto no_memory; cfg->securityDriverNames[1] = NULL; @@ -486,7 +484,7 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg, "list of strings")); goto cleanup; } - if (!(cfg->cgroupDeviceACL[i] = strdup(pp->str))) + if (VIR_STRDUP(cfg->cgroupDeviceACL[i], pp->str) < 0) goto no_memory; } cfg->cgroupDeviceACL[i] = NULL; @@ -586,9 +584,9 @@ virCapsPtr virQEMUDriverCreateCapabilities(virQEMUDriverPtr driver) for (i = 0; sec_managers[i]; i++) { doi = virSecurityManagerGetDOI(sec_managers[i]); model = virSecurityManagerGetModel(sec_managers[i]); - if (!(caps->host.secModels[i].model = strdup(model))) + if (VIR_STRDUP(caps->host.secModels[i].model, model) < 0) goto no_memory; - if (!(caps->host.secModels[i].doi = strdup(doi))) + if (VIR_STRDUP(caps->host.secModels[i].doi, doi) < 0) goto no_memory; VIR_DEBUG("Initialized caps for security driver \"%s\" with " "DOI \"%s\"", model, doi); @@ -1070,7 +1068,7 @@ qemuSharedDiskEntryCopy(const qemuSharedDiskEntryPtr entry) } for (i = 0; i < entry->ref; i++) { - if (!(ret->domains[i] = strdup(entry->domains[i]))) { + if (VIR_STRDUP(ret->domains[i], entry->domains[i]) < 0) { virReportOOMError(); goto cleanup; } @@ -1135,7 +1133,7 @@ qemuAddSharedDisk(virQEMUDriverPtr driver, goto cleanup; if ((VIR_EXPAND_N(new_entry->domains, new_entry->ref, 1) < 0) || - !(new_entry->domains[new_entry->ref - 1] = strdup(name))) { + VIR_STRDUP(new_entry->domains[new_entry->ref - 1], name) < 0) { qemuSharedDiskEntryFree(new_entry, NULL); virReportOOMError(); goto cleanup; @@ -1148,7 +1146,7 @@ qemuAddSharedDisk(virQEMUDriverPtr driver, } else { if ((VIR_ALLOC(entry) < 0) || (VIR_ALLOC_N(entry->domains, 1) < 0) || - !(entry->domains[0] = strdup(name))) { + VIR_STRDUP(entry->domains[0], name) < 0) { qemuSharedDiskEntryFree(entry, NULL); virReportOOMError(); goto cleanup; diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index e31141a..0b08dae 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -731,13 +731,13 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, dev->data.net->type != VIR_DOMAIN_NET_TYPE_HOSTDEV && !dev->data.net->model) { if (def->os.arch == VIR_ARCH_S390 || - def->os.arch == VIR_ARCH_S390X) - dev->data.net->model = strdup("virtio"); - else - dev->data.net->model = strdup("rtl8139"); - - if (!dev->data.net->model) - goto no_memory; + def->os.arch == VIR_ARCH_S390X) { + if (VIR_STRDUP(dev->data.net->model, "virtio") < 0) + goto no_memory; + } else { + if (VIR_STRDUP(dev->data.net->model, "rtl8139") < 0) + goto no_memory; + } } /* set default disk types and drivers */ @@ -761,7 +761,7 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, } else { /* default driver if probing is forbidden */ if (!disk->driverName && - !(disk->driverName = strdup("qemu"))) + VIR_STRDUP(disk->driverName, "qemu") < 0) goto no_memory; /* default disk format for drives */ diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 1e184dd..47ecccf 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -1441,7 +1441,7 @@ qemuCanonicalizeMachine(virDomainDefPtr def, virQEMUCapsPtr qemuCaps) if (STRNEQ(canon, def->os.machine)) { char *tmp; - if (!(tmp = strdup(canon))) { + if (VIR_STRDUP(tmp, canon) < 0) { virReportOOMError(); return -1; } @@ -2014,7 +2014,7 @@ static char *qemuDomainGetOSType(virDomainPtr dom) { if (!(vm = qemuDomObjFromDomain(dom))) goto cleanup; - if (!(type = strdup(vm->def->os.type))) + if (VIR_STRDUP(type, vm->def->os.type) < 0) virReportOOMError(); cleanup: @@ -3386,14 +3386,18 @@ qemuDomainScreenshot(virDomainPtr dom, goto endjob; } + if (VIR_STRDUP(ret, "image/x-portable-pixmap") < 0) { + virReportOOMError(); + goto endjob; + } + if (virFDStreamOpenFile(st, tmp, 0, 0, O_RDONLY) < 0) { virReportError(VIR_ERR_OPERATION_FAILED, "%s", _("unable to open stream")); + VIR_FREE(ret); goto endjob; } - ret = strdup("image/x-portable-pixmap"); - endjob: VIR_FORCE_CLOSE(tmp_fd); if (unlink_tmp) @@ -5140,8 +5144,7 @@ static char *qemuConnectDomainXMLFromNative(virConnectPtr conn, if (!def) goto cleanup; - if (!def->name && - !(def->name = strdup("unnamed"))) { + if (!def->name && VIR_STRDUP(def->name, "unnamed") < 0) { virReportOOMError(); goto cleanup; } @@ -5210,8 +5213,8 @@ static char *qemuConnectDomainXMLToNative(virConnectPtr conn, if ((actualType == VIR_DOMAIN_NET_TYPE_BRIDGE) && (brname = virDomainNetGetActualBridgeName(net))) { - char *brnamecopy = strdup(brname); - if (!brnamecopy) { + char *brnamecopy; + if (VIR_STRDUP(brnamecopy, brname) < 0) { virReportOOMError(); goto cleanup; } @@ -6631,8 +6634,7 @@ static char *qemuDomainGetSchedulerType(virDomainPtr dom, *nparams = 5; } - ret = strdup("posix"); - if (!ret) + if (VIR_STRDUP(ret, "posix") < 0) virReportOOMError(); cleanup: @@ -6691,8 +6693,7 @@ qemuDomainParseDeviceWeightStr(char *deviceWeightStr, if (!p) goto error; - result[i].path = strndup(temp, p - temp); - if (!result[i].path) { + if (VIR_STRNDUP(result[i].path, temp, p - temp) < 0) { virReportOOMError(); goto cleanup; } @@ -7059,12 +7060,9 @@ qemuDomainGetBlkioParameters(virDomainPtr dom, } param->value.s = virBufferContentAndReset(&buf); } - if (!param->value.s) { - param->value.s = strdup(""); - if (!param->value.s) { - virReportOOMError(); - goto cleanup; - } + if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0) { + virReportOOMError(); + goto cleanup; } param->type = VIR_TYPED_PARAM_STRING; if (virStrcpyStatic(param->field, @@ -7587,8 +7585,10 @@ qemuDomainGetNumaParameters(virDomainPtr dom, case 1: /* fill numa nodeset here */ if (flags & VIR_DOMAIN_AFFECT_CONFIG) { nodeset = virBitmapFormat(persistentDef->numatune.memory.nodemask); - if (!nodeset) - nodeset = strdup(""); + if (!nodeset && VIR_STRDUP(nodeset, "") < 0) { + virReportOOMError(); + goto cleanup; + } } else { rc = virCgroupGetCpusetMems(priv->cgroup, &nodeset); if (rc != 0) { @@ -10579,7 +10579,7 @@ qemuDomainSnapshotCreateInactiveExternal(virQEMUDriverPtr driver, if (snapdisk->snapshot == VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL) { VIR_FREE(defdisk->src); - if (!(defdisk->src = strdup(snapdisk->file))) { + if (VIR_STRDUP(defdisk->src, snapdisk->file) < 0) { /* we cannot rollback here in a sane way */ virReportOOMError(); goto cleanup; @@ -10870,9 +10870,9 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver, } if (virAsprintf(&device, "drive-%s", disk->info.alias) < 0 || - !(source = strdup(snap->file)) || + VIR_STRDUP(source, snap->file) < 0 || (persistDisk && - !(persistSource = strdup(source)))) { + VIR_STRDUP(persistSource, source) < 0)) { virReportOOMError(); goto cleanup; } @@ -10949,9 +10949,9 @@ qemuDomainSnapshotUndoSingleDiskActive(virQEMUDriverPtr driver, char *persistSource = NULL; struct stat st; - if (!(source = strdup(origdisk->src)) || + if (VIR_STRDUP(source, origdisk->src) < 0 || (persistDisk && - !(persistSource = strdup(source)))) { + VIR_STRDUP(persistSource, source) < 0)) { virReportOOMError(); goto cleanup; } @@ -11558,12 +11558,10 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain, if (update_current) snap->def->current = true; if (vm->current_snapshot) { - if (!(flags & VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE)) { - snap->def->parent = strdup(vm->current_snapshot->def->name); - if (snap->def->parent == NULL) { - virReportOOMError(); - goto cleanup; - } + if (!(flags & VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE) && + VIR_STRDUP(snap->def->parent, vm->current_snapshot->def->name) < 0) { + virReportOOMError(); + goto cleanup; } if (update_current) { vm->current_snapshot->def->current = false; @@ -12343,14 +12341,11 @@ qemuDomainSnapshotReparentChildren(void *payload, VIR_FREE(snap->def->parent); snap->parent = rep->parent; - if (rep->parent->def) { - snap->def->parent = strdup(rep->parent->def->name); - - if (snap->def->parent == NULL) { - virReportOOMError(); - rep->err = -1; - return; - } + if (rep->parent->def && + VIR_STRDUP(snap->def->parent, rep->parent->def->name) < 0) { + virReportOOMError(); + rep->err = -1; + return; } if (!snap->sibling) @@ -13257,7 +13252,7 @@ qemuDomainBlockCopy(virDomainPtr dom, const char *path, } if (!format && disk->mirrorFormat > 0) format = virStorageFileFormatTypeToString(disk->mirrorFormat); - if (!(mirror = strdup(dest))) { + if (VIR_STRDUP(mirror, dest) < 0) { virReportOOMError(); goto endjob; } @@ -13891,7 +13886,7 @@ qemuDomainGetDiskErrors(virDomainPtr dom, if (n == nerrors) break; - if (!(errors[n].disk = strdup(disk->dst))) { + if (VIR_STRDUP(errors[n].disk, disk->dst) < 0) { virReportOOMError(); goto endjob; } @@ -13951,14 +13946,12 @@ qemuDomainSetMetadata(virDomainPtr dom, switch ((virDomainMetadataType) type) { case VIR_DOMAIN_METADATA_DESCRIPTION: VIR_FREE(vm->def->description); - if (metadata && - !(vm->def->description = strdup(metadata))) + if (metadata && VIR_STRDUP(vm->def->description, metadata) < 0) goto no_memory; break; case VIR_DOMAIN_METADATA_TITLE: VIR_FREE(vm->def->title); - if (metadata && - !(vm->def->title = strdup(metadata))) + if (metadata && VIR_STRDUP(vm->def->title, metadata) < 0) goto no_memory; break; case VIR_DOMAIN_METADATA_ELEMENT: @@ -13979,14 +13972,12 @@ qemuDomainSetMetadata(virDomainPtr dom, switch ((virDomainMetadataType) type) { case VIR_DOMAIN_METADATA_DESCRIPTION: VIR_FREE(persistentDef->description); - if (metadata && - !(persistentDef->description = strdup(metadata))) + if (metadata && VIR_STRDUP(persistentDef->description, metadata) < 0) goto no_memory; break; case VIR_DOMAIN_METADATA_TITLE: VIR_FREE(persistentDef->title); - if (metadata && - !(persistentDef->title = strdup(metadata))) + if (metadata && VIR_STRDUP(persistentDef->title, metadata) < 0) goto no_memory; break; case VIR_DOMAIN_METADATA_ELEMENT: @@ -14073,7 +14064,7 @@ qemuDomainGetMetadata(virDomainPtr dom, goto cleanup; } - if (!(ret = strdup(field))) { + if (VIR_STRDUP(ret, field) < 0) { virReportOOMError(); goto cleanup; } diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 24ff142..8416a25 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1292,7 +1292,7 @@ qemuDomainNetGetBridgeName(virConnectPtr conn, virDomainNetDefPtr net) goto cleanup; } /* we need a copy, not just a pointer to the original */ - if (!(brname = strdup(tmpbr))) { + if (VIR_STRDUP(brname, tmpbr) < 0) { virReportOOMError(); goto cleanup; } @@ -1548,8 +1548,7 @@ qemuDomainChangeNet(virQEMUDriverPtr driver, } /* ifname: check if it's set in newdev. If not, retain the autogenerated one */ - if (!(newdev->ifname || - (newdev->ifname = strdup(olddev->ifname)))) { + if (!newdev->ifname && VIR_STRDUP(newdev->ifname, olddev->ifname) < 0) { virReportOOMError(); goto cleanup; } @@ -1577,8 +1576,7 @@ qemuDomainChangeNet(virQEMUDriverPtr driver, goto cleanup; } /* grab alias from olddev if not set in newdev */ - if (!(newdev->info.alias || - (newdev->info.alias = strdup(olddev->info.alias)))) { + if (!newdev->info.alias && VIR_STRDUP(newdev->info.alias, olddev->info.alias) < 0) { virReportOOMError(); goto cleanup; } diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 0732614..97639fd 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -316,7 +316,7 @@ qemuMigrationCookieGraphicsAlloc(virQEMUDriverPtr driver, goto error; #endif } - if (!(mig->listen = strdup(listenAddr))) + if (VIR_STRDUP(mig->listen, listenAddr) < 0) goto no_memory; virObjectUnref(cfg); @@ -400,7 +400,7 @@ qemuMigrationCookieNew(virDomainObjPtr dom) name = priv->origname; else name = dom->def->name; - if (!(mig->name = strdup(name))) + if (VIR_STRDUP(mig->name, name) < 0) goto no_memory; memcpy(mig->uuid, dom->def->uuid, VIR_UUID_BUFLEN); @@ -460,15 +460,14 @@ qemuMigrationCookieAddLockstate(qemuMigrationCookiePtr mig, } if (virDomainObjGetState(dom, NULL) == VIR_DOMAIN_PAUSED) { - if (priv->lockState && - !(mig->lockState = strdup(priv->lockState))) + if (priv->lockState && VIR_STRDUP(mig->lockState, priv->lockState) < 0) return -1; } else { if (virDomainLockProcessInquire(driver->lockManager, dom, &mig->lockState) < 0) return -1; } - if (!(mig->lockDriver = strdup(virLockManagerPluginGetName(driver->lockManager)))) { + if (VIR_STRDUP(mig->lockDriver, virLockManagerPluginGetName(driver->lockManager)) < 0) { VIR_FREE(mig->lockState); return -1; } @@ -2050,8 +2049,7 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver, /* Target domain name, maybe renamed. */ if (dname) { origname = def->name; - def->name = strdup(dname); - if (def->name == NULL) + if (VIR_STRDUP(def->name, dname) < 0) goto cleanup; } @@ -2101,7 +2099,7 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver, /* QEMU will be started with -incoming stdio * (which qemu_command might convert to exec:cat or fd:n) */ - if (!(migrateFrom = strdup("stdio"))) { + if (VIR_STRDUP(migrateFrom, "stdio") < 0) { virReportOOMError(); goto cleanup; } diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 6fdd650..37beea0 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -201,8 +201,9 @@ int qemuMonitorJSONIOProcess(qemuMonitorPtr mon, if (nl) { int got = nl - (data + used); - char *line = strndup(data + used, got); - if (!line) { + char *line; + + if (VIR_STRNDUP(line, data + used, got) < 0) { virReportOOMError(); return -1; } @@ -956,14 +957,8 @@ qemuMonitorJSONHumanCommandWithFd(qemuMonitorPtr mon, } if (reply_str) { - const char *data; - - if ((data = virJSONValueGetString(obj))) - *reply_str = strdup(data); - else - *reply_str = strdup(""); - - if (!*reply_str) { + const char *data = virJSONValueGetString(obj); + if (VIR_STRDUP(*reply_str, data ? data : "") < 0) { virReportOOMError(); goto cleanup; } @@ -2946,8 +2941,9 @@ static int qemuMonitorJSONExtractPtyPaths(virJSONValuePtr reply, } if (STRPREFIX(type, "pty:")) { - char *path = strdup(type + strlen("pty:")); - if (!path) { + char *path; + + if (VIR_STRDUP(path, type + strlen("pty:")) < 0) { virReportOOMError(); goto cleanup; } @@ -3925,7 +3921,7 @@ int qemuMonitorJSONGetVersion(qemuMonitorPtr mon, _("query-version reply was missing 'package' version")); goto cleanup; } - if (!(*package = strdup(tmp))) { + if (VIR_STRDUP(*package, tmp) < 0) { virReportOOMError(); goto cleanup; } @@ -4001,7 +3997,7 @@ int qemuMonitorJSONGetMachines(qemuMonitorPtr mon, goto cleanup; } - if (!(info->name = strdup(tmp))) { + if (VIR_STRDUP(info->name, tmp) < 0) { virReportOOMError(); goto cleanup; } @@ -4019,7 +4015,7 @@ int qemuMonitorJSONGetMachines(qemuMonitorPtr mon, _("query-machines reply has malformed 'alias' data")); goto cleanup; } - if (!(info->alias = strdup(tmp))) { + if (VIR_STRDUP(info->alias, tmp) < 0) { virReportOOMError(); goto cleanup; } @@ -4106,7 +4102,7 @@ int qemuMonitorJSONGetCPUDefinitions(qemuMonitorPtr mon, goto cleanup; } - if (!(cpulist[i] = strdup(tmp))) { + if (VIR_STRDUP(cpulist[i], tmp) < 0) { virReportOOMError(); goto cleanup; } @@ -4180,7 +4176,7 @@ int qemuMonitorJSONGetCommands(qemuMonitorPtr mon, goto cleanup; } - if (!(commandlist[i] = strdup(tmp))) { + if (VIR_STRDUP(commandlist[i], tmp) < 0) { virReportOOMError(); goto cleanup; } @@ -4259,7 +4255,7 @@ int qemuMonitorJSONGetEvents(qemuMonitorPtr mon, goto cleanup; } - if (!(eventlist[i] = strdup(tmp))) { + if (VIR_STRDUP(eventlist[i], tmp) < 0) { virReportOOMError(); goto cleanup; } @@ -4384,7 +4380,7 @@ int qemuMonitorJSONGetObjectTypes(qemuMonitorPtr mon, goto cleanup; } - if (!(typelist[i] = strdup(tmp))) { + if (VIR_STRDUP(typelist[i], tmp) < 0) { virReportOOMError(); goto cleanup; } @@ -4466,7 +4462,7 @@ int qemuMonitorJSONGetObjectProps(qemuMonitorPtr mon, goto cleanup; } - if (!(proplist[i] = strdup(tmp))) { + if (VIR_STRDUP(proplist[i], tmp) < 0) { virReportOOMError(); goto cleanup; } @@ -4520,7 +4516,7 @@ qemuMonitorJSONGetTargetArch(qemuMonitorPtr mon) goto cleanup; } - if (!(ret = strdup(arch))) { + if (VIR_STRDUP(ret, arch) < 0) { virReportOOMError(); goto cleanup; } @@ -4817,7 +4813,7 @@ qemuMonitorJSONGetStringArray(qemuMonitorPtr mon, const char *qmpCmd, goto cleanup; } - if (!(list[i] = strdup(tmp))) { + if (VIR_STRDUP(list[i], tmp) < 0) { virReportOOMError(); goto cleanup; } diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c index 696961b..eda9ed4 100644 --- a/src/qemu/qemu_monitor_text.c +++ b/src/qemu/qemu_monitor_text.c @@ -258,8 +258,7 @@ qemuMonitorTextCommandWithHandler(qemuMonitorPtr mon, if (msg.rxBuffer) { *reply = msg.rxBuffer; } else { - *reply = strdup(""); - if (!*reply) { + if (VIR_STRDUP(*reply, "") < 0) { virReportOOMError(); return -1; } @@ -330,7 +329,7 @@ qemuMonitorSendDiskPassphrase(qemuMonitorPtr mon, /* Extra the path */ pathStart += strlen(DISK_ENCRYPTION_PREFIX); - if (!(path = strndup(pathStart, pathEnd - pathStart))) { + if (VIR_STRNDUP(path, pathStart, pathEnd - pathStart) < 0) { virReportOOMError(); return -1; } @@ -2283,8 +2282,8 @@ int qemuMonitorTextGetPtyPaths(qemuMonitorPtr mon, /* Path is everything after needle to the end of the line */ *eol = '\0'; - char *path = strdup(needle + strlen(NEEDLE)); - if (path == NULL) { + char *path; + if (VIR_STRDUP(path, needle + strlen(NEEDLE)) < 0) { virReportOOMError(); goto cleanup; } diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 54a55b9..13371f3 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -1000,15 +1000,15 @@ qemuProcessHandleGraphics(qemuMonitorPtr mon ATTRIBUTE_UNUSED, if (VIR_ALLOC(localAddr) < 0) goto no_memory; localAddr->family = localFamily; - if (!(localAddr->service = strdup(localService)) || - !(localAddr->node = strdup(localNode))) + if (VIR_STRDUP(localAddr->service, localService) < 0 || + VIR_STRDUP(localAddr->node, localNode) < 0) goto no_memory; if (VIR_ALLOC(remoteAddr) < 0) goto no_memory; remoteAddr->family = remoteFamily; - if (!(remoteAddr->service = strdup(remoteService)) || - !(remoteAddr->node = strdup(remoteNode))) + if (VIR_STRDUP(remoteAddr->service, remoteService) < 0 || + VIR_STRDUP(remoteAddr->node, remoteNode) < 0) goto no_memory; if (VIR_ALLOC(subject) < 0) @@ -1017,16 +1017,16 @@ qemuProcessHandleGraphics(qemuMonitorPtr mon ATTRIBUTE_UNUSED, if (VIR_REALLOC_N(subject->identities, subject->nidentity+1) < 0) goto no_memory; subject->nidentity++; - if (!(subject->identities[subject->nidentity-1].type = strdup("x509dname")) || - !(subject->identities[subject->nidentity-1].name = strdup(x509dname))) + if (VIR_STRDUP(subject->identities[subject->nidentity-1].type, "x509dname") < 0 || + VIR_STRDUP(subject->identities[subject->nidentity-1].name, x509dname) < 0) goto no_memory; } if (saslUsername) { if (VIR_REALLOC_N(subject->identities, subject->nidentity+1) < 0) goto no_memory; subject->nidentity++; - if (!(subject->identities[subject->nidentity-1].type = strdup("saslUsername")) || - !(subject->identities[subject->nidentity-1].name = strdup(saslUsername))) + if (VIR_STRDUP(subject->identities[subject->nidentity-1].type, "saslUsername") < 0 || + VIR_STRDUP(subject->identities[subject->nidentity-1].name, saslUsername) < 0) goto no_memory; } @@ -1480,8 +1480,7 @@ qemuProcessExtractTTYPath(const char *haystack, */ while (*tmp) { if (c_isspace(*tmp)) { - *path = strndup(dev, tmp-dev); - if (*path == NULL) { + if (VIR_STRNDUP(*path, dev, tmp-dev) < 0) { virReportOOMError(); return -1; } @@ -1539,9 +1538,7 @@ qemuProcessLookupPTYs(virDomainChrDefPtr *devices, } VIR_FREE(chr->source.data.file.path); - chr->source.data.file.path = strdup(path); - - if (chr->source.data.file.path == NULL) { + if (VIR_STRDUP(chr->source.data.file.path, path) < 0) { virReportOOMError(); return -1; } @@ -2666,12 +2663,18 @@ qemuProcessUpdateState(virQEMUDriverPtr driver, virDomainObjPtr vm) if (state == VIR_DOMAIN_PAUSED && running) { newState = VIR_DOMAIN_RUNNING; newReason = VIR_DOMAIN_RUNNING_UNPAUSED; - msg = strdup("was unpaused"); + if (VIR_STRDUP(msg, "was unpaused") < 0) { + virReportOOMError(); + return -1; + } } else if (state == VIR_DOMAIN_RUNNING && !running) { if (reason == VIR_DOMAIN_PAUSED_SHUTTING_DOWN) { newState = VIR_DOMAIN_SHUTDOWN; newReason = VIR_DOMAIN_SHUTDOWN_UNKNOWN; - msg = strdup("shutdown"); + if (VIR_STRDUP(msg, "shutdown") < 0) { + virReportOOMError(); + return -1; + } } else { newState = VIR_DOMAIN_PAUSED; newReason = reason; @@ -2681,15 +2684,13 @@ qemuProcessUpdateState(virQEMUDriverPtr driver, virDomainObjPtr vm) } else if (state == VIR_DOMAIN_SHUTOFF && running) { newState = VIR_DOMAIN_RUNNING; newReason = VIR_DOMAIN_RUNNING_BOOTED; - msg = strdup("finished booting"); - } - - if (newState != VIR_DOMAIN_NOSTATE) { - if (!msg) { + if (VIR_STRDUP(msg, "finished booting") < 0) { virReportOOMError(); return -1; } + } + if (newState != VIR_DOMAIN_NOSTATE) { VIR_DEBUG("Domain %s %s while its monitor was disconnected;" " changing state to %s (%s)", vm->def->name, @@ -3462,11 +3463,9 @@ int qemuProcessStart(virConnectPtr conn, goto cleanup; } graphics->listens[0].type = VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS; - if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC) - graphics->listens[0].address = strdup(cfg->vncListen); - else - graphics->listens[0].address = strdup(cfg->spiceListen); - if (!graphics->listens[0].address) { + if (VIR_STRDUP(graphics->listens[0].address, + graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC ? + cfg->vncListen : cfg->spiceListen) < 0) { VIR_SHRINK_N(graphics->listens, graphics->nListens, 1); virReportOOMError(); goto cleanup; @@ -4234,8 +4233,7 @@ int qemuProcessAttach(virConnectPtr conn ATTRIBUTE_UNUSED, } VIR_FREE(priv->pidfile); - if (pidfile && - !(priv->pidfile = strdup(pidfile))) + if (pidfile && VIR_STRDUP(priv->pidfile, pidfile) < 0) goto no_memory; VIR_DEBUG("Detect security driver config"); @@ -4257,10 +4255,10 @@ int qemuProcessAttach(virConnectPtr conn ATTRIBUTE_UNUSED, vm->def, vm->pid, seclabel) < 0) goto cleanup; - if (!(seclabeldef->model = strdup(model))) + if (VIR_STRDUP(seclabeldef->model, model) < 0) goto no_memory; - if (!(seclabeldef->label = strdup(seclabel->label))) + if (VIR_STRDUP(seclabeldef->label, seclabel->label) < 0) goto no_memory; VIR_FREE(seclabel); } diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 13212d0..97be2a0 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -3733,7 +3733,7 @@ static int remoteAuthMakeCredentials(sasl_interact_t *interact, } if (interact[*ncred].challenge) (*cred)[*ncred].challenge = interact[ninteract].challenge; - (*cred)[*ncred].prompt = interact[ninteract].prompt; + (*cred)[*ncred].prompt = (char *) interact[ninteract].prompt; if (interact[*ncred].defresult) (*cred)[*ncred].defresult = interact[ninteract].defresult; (*cred)[*ncred].result = NULL; -- 1.8.1.5

--- src/remote/remote_driver.c | 79 ++++++++++++++++++++-------------------------- 1 file changed, 34 insertions(+), 45 deletions(-) diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 97be2a0..89e0e96 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -368,7 +368,7 @@ 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 = strdup(var->value))) \ + if (VIR_STRDUP(ARG_VAR, var->value) < 0) \ goto no_memory; \ var->ignore = 1; \ continue; \ @@ -497,23 +497,20 @@ doRemoteOpen(virConnectPtr conn, if (virAsprintf(&port, "%d", conn->uri->port) < 0) goto no_memory; } else if (transport == trans_tls) { - if (!(port = strdup(LIBVIRTD_TLS_PORT))) + if (VIR_STRDUP(port, LIBVIRTD_TLS_PORT) < 0) goto no_memory; } else if (transport == trans_tcp) { - if (!(port = strdup(LIBVIRTD_TCP_PORT))) + if (VIR_STRDUP(port, LIBVIRTD_TCP_PORT) < 0) goto no_memory; } /* Port not used for unix, ext., default for ssh */ - if (conn->uri && conn->uri->server) - priv->hostname = strdup(conn->uri->server); - else - priv->hostname = strdup("localhost"); - - if (!priv->hostname) + if (VIR_STRDUP(priv->hostname, + conn->uri && conn->uri->server ? + conn->uri->server : "localhost") < 0) goto no_memory; if (conn->uri && conn->uri->user && - !(username = strdup(conn->uri->user))) + VIR_STRDUP(username, conn->uri->user) < 0) goto no_memory; /* Get the variables from the query string. @@ -557,7 +554,7 @@ doRemoteOpen(virConnectPtr conn, (STREQ(conn->uri->scheme, "remote") || STRPREFIX(conn->uri->scheme, "remote+"))) { /* Allow remote serve to probe */ - if (!(name = strdup(""))) + if (VIR_STRDUP(name, "") < 0) goto no_memory; } else { virURI tmpuri = { @@ -587,7 +584,7 @@ doRemoteOpen(virConnectPtr conn, } } else { /* Probe URI server side */ - if (!(name = strdup(""))) + if (VIR_STRDUP(name, "") < 0) goto no_memory; } @@ -636,12 +633,10 @@ doRemoteOpen(virConnectPtr conn, case trans_libssh2: if (!sockname) { - if (flags & VIR_DRV_OPEN_REMOTE_RO) - sockname = strdup(LIBVIRTD_PRIV_UNIX_SOCKET_RO); - else - sockname = strdup(LIBVIRTD_PRIV_UNIX_SOCKET); - - if (sockname == NULL) + if (VIR_STRDUP(sockname, + flags & VIR_DRV_OPEN_REMOTE_RO ? + LIBVIRTD_PRIV_UNIX_SOCKET_RO : + LIBVIRTD_PRIV_UNIX_SOCKET) < 0) goto no_memory; } @@ -678,11 +673,10 @@ doRemoteOpen(virConnectPtr conn, } VIR_FREE(userdir); } else { - if (flags & VIR_DRV_OPEN_REMOTE_RO) - sockname = strdup(LIBVIRTD_PRIV_UNIX_SOCKET_RO); - else - sockname = strdup(LIBVIRTD_PRIV_UNIX_SOCKET); - if (sockname == NULL) + if (VIR_STRDUP(sockname, + flags & VIR_DRV_OPEN_REMOTE_RO ? + LIBVIRTD_PRIV_UNIX_SOCKET_RO : + LIBVIRTD_PRIV_UNIX_SOCKET) < 0) goto no_memory; } VIR_DEBUG("Proceeding with sockname %s", sockname); @@ -705,15 +699,14 @@ doRemoteOpen(virConnectPtr conn, break; case trans_ssh: - if (!command && !(command = strdup("ssh"))) + if (!command && VIR_STRDUP(command, "ssh") < 0) goto no_memory; if (!sockname) { - if (flags & VIR_DRV_OPEN_REMOTE_RO) - sockname = strdup(LIBVIRTD_PRIV_UNIX_SOCKET_RO); - else - sockname = strdup(LIBVIRTD_PRIV_UNIX_SOCKET); - if (!sockname) + if (VIR_STRDUP(sockname, + flags & VIR_DRV_OPEN_REMOTE_RO ? + LIBVIRTD_PRIV_UNIX_SOCKET_RO : + LIBVIRTD_PRIV_UNIX_SOCKET) < 0) goto no_memory; } @@ -1493,8 +1486,7 @@ remoteSerializeTypedParameters(virTypedParameterPtr params, for (i = 0; i < nparams; ++i) { /* call() will free this: */ - val[i].field = strdup(params[i].field); - if (val[i].field == NULL) { + if (VIR_STRDUP(val[i].field, params[i].field) < 0) { virReportOOMError(); goto cleanup; } @@ -1519,8 +1511,7 @@ remoteSerializeTypedParameters(virTypedParameterPtr params, val[i].value.remote_typed_param_value_u.b = params[i].value.b; break; case VIR_TYPED_PARAM_STRING: - val[i].value.remote_typed_param_value_u.s = strdup(params[i].value.s); - if (val[i].value.remote_typed_param_value_u.s == NULL) { + if (VIR_STRDUP(val[i].value.remote_typed_param_value_u.s, params[i].value.s) < 0) { virReportOOMError(); goto cleanup; } @@ -1608,9 +1599,8 @@ remoteDeserializeTypedParameters(remote_typed_param *ret_params_val, ret_param->value.remote_typed_param_value_u.b; break; case VIR_TYPED_PARAM_STRING: - param->value.s = - strdup(ret_param->value.remote_typed_param_value_u.s); - if (!param->value.s) { + if (VIR_STRDUP(param->value.s, + ret_param->value.remote_typed_param_value_u.s) < 0) { virReportOOMError(); goto cleanup; } @@ -1653,7 +1643,7 @@ remoteDeserializeDomainDiskErrors(remote_domain_disk_error *ret_errors_val, } for (i = 0; i < ret_errors_len; i++) { - if (!(errors[i].disk = strdup(ret_errors_val[i].disk))) { + if (VIR_STRDUP(errors[i].disk, ret_errors_val[i].disk) < 0) { virReportOOMError(); goto error; } @@ -4472,15 +4462,15 @@ remoteDomainBuildEventGraphics(virNetClientProgramPtr prog ATTRIBUTE_UNUSED, if (VIR_ALLOC(localAddr) < 0) goto no_memory; localAddr->family = msg->local.family; - if (!(localAddr->service = strdup(msg->local.service)) || - !(localAddr->node = strdup(msg->local.node))) + if (VIR_STRDUP(localAddr->service, msg->local.service) < 0 || + VIR_STRDUP(localAddr->node, msg->local.node) < 0) goto no_memory; if (VIR_ALLOC(remoteAddr) < 0) goto no_memory; remoteAddr->family = msg->remote.family; - if (!(remoteAddr->service = strdup(msg->remote.service)) || - !(remoteAddr->node = strdup(msg->remote.node))) + if (VIR_STRDUP(remoteAddr->service, msg->remote.service) < 0 || + VIR_STRDUP(remoteAddr->node, msg->remote.node) < 0) goto no_memory; if (VIR_ALLOC(subject) < 0) @@ -4489,8 +4479,8 @@ remoteDomainBuildEventGraphics(virNetClientProgramPtr prog ATTRIBUTE_UNUSED, goto no_memory; subject->nidentity = msg->subject.subject_len; for (i = 0 ; i < subject->nidentity ; i++) { - if (!(subject->identities[i].type = strdup(msg->subject.subject_val[i].type)) || - !(subject->identities[i].name = strdup(msg->subject.subject_val[i].name))) + if (VIR_STRDUP(subject->identities[i].type, msg->subject.subject_val[i].type) < 0 || + VIR_STRDUP(subject->identities[i].name, msg->subject.subject_val[i].name) < 0) goto no_memory; } @@ -5100,8 +5090,7 @@ remoteDomainQemuMonitorCommand(virDomainPtr domain, const char *cmd, (xdrproc_t) xdr_qemu_domain_monitor_command_ret, (char *) &ret) == -1) goto done; - *result = strdup(ret.result); - if (*result == NULL) { + if (VIR_STRDUP(*result, ret.result) < 0) { virReportOOMError(); goto cleanup; } -- 1.8.1.5

--- src/rpc/gendispatch.pl | 13 +++++-------- src/rpc/virnetclient.c | 8 ++++---- src/rpc/virnetmessage.c | 11 ++++++----- src/rpc/virnetsaslcontext.c | 3 ++- src/rpc/virnetserver.c | 4 ++-- src/rpc/virnetserverclient.c | 6 ++---- src/rpc/virnetservermdns.c | 4 ++-- src/rpc/virnetsocket.c | 6 ++++-- src/rpc/virnetsshsession.c | 22 +++++++++++----------- src/rpc/virnettlscontext.c | 13 ++++++------- 10 files changed, 44 insertions(+), 46 deletions(-) diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl index 7b93062..f1ddeed 100755 --- a/src/rpc/gendispatch.pl +++ b/src/rpc/gendispatch.pl @@ -610,9 +610,9 @@ elsif ($mode eq "server") { # SPECIAL: virConnectGetType returns a constant string that must # not be freed. Therefore, duplicate the string here. push(@vars_list, "const char *$1"); - push(@ret_list, "/* We have to strdup because remoteDispatchClientRequest will"); + 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 = strdup(type))) {"); + push(@ret_list, "if (VIR_STRDUP(ret->type, type) < 0) {"); push(@ret_list, " virReportOOMError();"); push(@ret_list, " goto cleanup;"); push(@ret_list, "}"); @@ -636,8 +636,7 @@ elsif ($mode eq "server") { " goto cleanup;\n" . " }\n" . " \n" . - " *$1_p = strdup($1);\n" . - " if (*$1_p == NULL) {\n" . + " if (VIR_STRDUP(*$1_p, $1) < 0) {\n" . " virReportOOMError();\n" . " goto cleanup;\n" . " }\n"); @@ -1562,12 +1561,10 @@ elsif ($mode eq "client") { print "\n"; print " /* This call is caller-frees (although that isn't clear from\n"; print " * the documentation). However xdr_free will free up both the\n"; - print " * names and the list of pointers, so we have to strdup the\n"; + print " * names and the list of pointers, so we have to VIR_STRDUP the\n"; print " * names here. */\n"; print " for (i = 0; i < ret.$single_ret_list_name.${single_ret_list_name}_len; ++i) {\n"; - print " ${single_ret_list_name}[i] = strdup(ret.$single_ret_list_name.${single_ret_list_name}_val[i]);\n"; - print "\n"; - print " if (${single_ret_list_name}[i] == NULL) {\n"; + print " if (VIR_STRDUP(${single_ret_list_name}[i], ret.$single_ret_list_name.${single_ret_list_name}_val[i]) < 0) {\n"; print " for (--i; i >= 0; --i)\n"; print " VIR_FREE(${single_ret_list_name}[i]);\n"; print "\n"; diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c index 1d228f0..edeb597 100644 --- a/src/rpc/virnetclient.c +++ b/src/rpc/virnetclient.c @@ -36,6 +36,7 @@ #include "virlog.h" #include "virutil.h" #include "virerror.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_RPC @@ -317,8 +318,7 @@ static virNetClientPtr virNetClientNew(virNetSocketPtr sock, client->wakeupSendFD = wakeupFD[1]; wakeupFD[0] = wakeupFD[1] = -1; - if (hostname && - !(client->hostname = strdup(hostname))) + if (hostname && VIR_STRDUP(client->hostname, hostname) < 0) goto no_memory; PROBE(RPC_CLIENT_NEW, @@ -414,7 +414,7 @@ virNetClientPtr virNetClientNewLibSSH2(const char *host, goto no_memory; } } else { - if (!(knownhosts = strdup(knownHostsPath))) + if (VIR_STRDUP(knownhosts, knownHostsPath) < 0) goto no_memory; } } @@ -438,7 +438,7 @@ virNetClientPtr virNetClientNewLibSSH2(const char *host, VIR_FREE(privkey); } } else { - if (!(privkey = strdup(privkeyPath))) + if (VIR_STRDUP(privkey, privkeyPath) < 0) goto no_memory; } } diff --git a/src/rpc/virnetmessage.c b/src/rpc/virnetmessage.c index 647fef7..6b2aa47 100644 --- a/src/rpc/virnetmessage.c +++ b/src/rpc/virnetmessage.c @@ -29,6 +29,7 @@ #include "virlog.h" #include "virfile.h" #include "virutil.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_RPC @@ -485,21 +486,21 @@ void virNetMessageSaveError(virNetMessageErrorPtr rerr) rerr->code = verr->code; rerr->domain = verr->domain; if (verr->message && VIR_ALLOC(rerr->message) == 0) - *rerr->message = strdup(verr->message); + ignore_value(VIR_STRDUP_QUIET(*rerr->message , verr->message)); rerr->level = verr->level; if (verr->str1 && VIR_ALLOC(rerr->str1) == 0) - *rerr->str1 = strdup(verr->str1); + ignore_value(VIR_STRDUP_QUIET(*rerr->str1, verr->str1)); if (verr->str2 && VIR_ALLOC(rerr->str2) == 0) - *rerr->str2 = strdup(verr->str2); + ignore_value(VIR_STRDUP_QUIET(*rerr->str2, verr->str2)); if (verr->str3 && VIR_ALLOC(rerr->str3) == 0) - *rerr->str3 = strdup(verr->str3); + ignore_value(VIR_STRDUP_QUIET(*rerr->str3, verr->str3)); rerr->int1 = verr->int1; rerr->int2 = verr->int2; } else { rerr->code = VIR_ERR_INTERNAL_ERROR; rerr->domain = VIR_FROM_RPC; if (VIR_ALLOC(rerr->message) == 0) - *rerr->message = strdup(_("Library function returned error but did not set virError")); + ignore_value(VIR_STRDUP_QUIET(*rerr->message, _("Library function returned error but did not set virError"))); rerr->level = VIR_ERR_ERROR; } } diff --git a/src/rpc/virnetsaslcontext.c b/src/rpc/virnetsaslcontext.c index 6943216..9edb870 100644 --- a/src/rpc/virnetsaslcontext.c +++ b/src/rpc/virnetsaslcontext.c @@ -29,6 +29,7 @@ #include "viralloc.h" #include "virthread.h" #include "virlog.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_RPC @@ -385,7 +386,7 @@ char *virNetSASLSessionListMechanisms(virNetSASLSessionPtr sasl) err, sasl_errdetail(sasl->conn)); goto cleanup; } - if (!(ret = strdup(mechlist))) { + if (VIR_STRDUP(ret, mechlist) < 0) { virReportOOMError(); goto cleanup; } diff --git a/src/rpc/virnetserver.c b/src/rpc/virnetserver.c index e536cc3..292b7b6 100644 --- a/src/rpc/virnetserver.c +++ b/src/rpc/virnetserver.c @@ -37,6 +37,7 @@ #include "virfile.h" #include "virnetservermdns.h" #include "virdbus.h" +#include "virstring.h" #ifndef SA_SIGINFO # define SA_SIGINFO 0 @@ -387,8 +388,7 @@ virNetServerPtr virNetServerNew(size_t min_workers, srv->privileged = geteuid() == 0; srv->autoShutdownInhibitFd = -1; - if (mdnsGroupName && - !(srv->mdnsGroupName = strdup(mdnsGroupName))) { + if (mdnsGroupName && VIR_STRDUP(srv->mdnsGroupName, mdnsGroupName) < 0) { virReportOOMError(); goto error; } diff --git a/src/rpc/virnetserverclient.c b/src/rpc/virnetserverclient.c index 2bde5c7..caa6824 100644 --- a/src/rpc/virnetserverclient.c +++ b/src/rpc/virnetserverclient.c @@ -681,8 +681,7 @@ virNetServerClientCreateIdentity(virNetServerClientPtr client) #if WITH_SASL if (client->sasl) { const char *identity = virNetSASLSessionGetIdentity(client->sasl); - if (identity && - !(saslname = strdup(identity))) { + if (identity && VIR_STRDUP(saslname, identity) < 0) { virReportOOMError(); goto cleanup; } @@ -692,8 +691,7 @@ virNetServerClientCreateIdentity(virNetServerClientPtr client) #if WITH_GNUTLS if (client->tls) { const char *identity = virNetTLSSessionGetX509DName(client->tls); - if (identity && - !(x509dname = strdup(identity))) { + if (identity && VIR_STRDUP(x509dname, identity) < 0) { virReportOOMError(); goto cleanup; } diff --git a/src/rpc/virnetservermdns.c b/src/rpc/virnetservermdns.c index 26e24d5..eb24390 100644 --- a/src/rpc/virnetservermdns.c +++ b/src/rpc/virnetservermdns.c @@ -479,7 +479,7 @@ virNetServerMDNSGroupPtr virNetServerMDNSAddGroup(virNetServerMDNS *mdns, return NULL; } - if (!(group->name = strdup(name))) { + if (VIR_STRDUP(group->name, name) < 0) { VIR_FREE(group); virReportOOMError(); return NULL; @@ -525,7 +525,7 @@ virNetServerMDNSEntryPtr virNetServerMDNSAddEntry(virNetServerMDNSGroupPtr group } entry->port = port; - if (!(entry->type = strdup(type))) { + if (VIR_STRDUP(entry->type, type) < 0) { VIR_FREE(entry); virReportOOMError(); return NULL; diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c index e950d7f..10f0b28 100644 --- a/src/rpc/virnetsocket.c +++ b/src/rpc/virnetsocket.c @@ -800,11 +800,13 @@ virNetSocketNewConnectLibSSH2(const char *host, if (virNetSSHSessionSetChannelCommand(sess, command) != 0) goto error; - if (!(authMethodNext = authMethodsCopy = strdup(authMethods))) { + if (VIR_STRDUP(authMethodNext, authMethods) < 0) { virReportOOMError(); goto error; } + authMethodsCopy = authMethodNext; + while ((authMethod = strsep(&authMethodNext, ","))) { if (STRCASEEQ(authMethod, "keyboard-interactive")) ret = virNetSSHSessionAuthAddKeyboardAuth(sess, username, -1); @@ -1180,7 +1182,7 @@ int virNetSocketGetSecurityContext(virNetSocketPtr sock, goto cleanup; } - if (!(*context = strdup(seccon))) { + if (VIR_STRDUP(*context, seccon) < 0) { virReportOOMError(); goto cleanup; } diff --git a/src/rpc/virnetsshsession.c b/src/rpc/virnetsshsession.c index 27750fc..c134d76 100644 --- a/src/rpc/virnetsshsession.c +++ b/src/rpc/virnetsshsession.c @@ -233,7 +233,7 @@ virNetSSHKbIntCb(const char *name ATTRIBUTE_UNUSED, /* fill data structures for auth callback */ for (i = 0; i < num_prompts; i++) { - if (!(askcred[i].prompt = strdup(prompts[i].text))) { + if (VIR_STRDUP(askcred[i].prompt, prompts[i].text) < 0) { priv->authCbErr = VIR_NET_SSH_AUTHCB_OOM; goto cleanup; } @@ -959,8 +959,8 @@ virNetSSHSessionAuthAddPasswordAuth(virNetSSHSessionPtr sess, virObjectLock(sess); - if (!(user = strdup(username)) || - !(pass = strdup(password))) + if (VIR_STRDUP(user, username) < 0 || + VIR_STRDUP(pass, password) < 0) goto no_memory; if (!(auth = virNetSSHSessionAuthMethodNew(sess))) @@ -997,7 +997,7 @@ virNetSSHSessionAuthAddAgentAuth(virNetSSHSessionPtr sess, virObjectLock(sess); - if (!(user = strdup(username))) + if (VIR_STRDUP(user, username) < 0) goto no_memory; if (!(auth = virNetSSHSessionAuthMethodNew(sess))) @@ -1037,11 +1037,11 @@ virNetSSHSessionAuthAddPrivKeyAuth(virNetSSHSessionPtr sess, virObjectLock(sess); - if (!(user = strdup(username)) || - !(file = strdup(keyfile))) + if (VIR_STRDUP(user, username) < 0 || + VIR_STRDUP(file, keyfile) < 0) goto no_memory; - if (password && !(pass = strdup(password))) + if (password && VIR_STRDUP(pass, password) < 0) goto no_memory; if (!(auth = virNetSSHSessionAuthMethodNew(sess))) @@ -1081,7 +1081,7 @@ virNetSSHSessionAuthAddKeyboardAuth(virNetSSHSessionPtr sess, virObjectLock(sess); - if (!(user = strdup(username))) + if (VIR_STRDUP(user, username) < 0) goto no_memory; if (!(auth = virNetSSHSessionAuthMethodNew(sess))) @@ -1111,7 +1111,7 @@ virNetSSHSessionSetChannelCommand(virNetSSHSessionPtr sess, VIR_FREE(sess->channelCommand); - if (command && !(sess->channelCommand = strdup(command))) { + if (command && VIR_STRDUP(sess->channelCommand, command) < 0) { virReportOOMError(); ret = -1; } @@ -1137,7 +1137,7 @@ virNetSSHSessionSetHostKeyVerification(virNetSSHSessionPtr sess, VIR_FREE(sess->hostname); - if (hostname && !(sess->hostname = strdup(hostname))) + if (hostname && VIR_STRDUP(sess->hostname, hostname) < 0) goto no_memory; /* load the known hosts file */ @@ -1162,7 +1162,7 @@ virNetSSHSessionSetHostKeyVerification(virNetSSHSessionPtr sess, /* set filename only if writing to the known hosts file is requested */ if (!(flags & VIR_NET_SSH_HOSTKEY_FILE_READONLY)) { VIR_FREE(sess->knownHostsFile); - if (!(sess->knownHostsFile = strdup(hostsfile))) + if (VIR_STRDUP(sess->knownHostsFile, hostsfile) < 0) goto no_memory; } } diff --git a/src/rpc/virnettlscontext.c b/src/rpc/virnettlscontext.c index 7f5975d..a80aefe 100644 --- a/src/rpc/virnettlscontext.c +++ b/src/rpc/virnettlscontext.c @@ -836,22 +836,22 @@ static int virNetTLSContextLocateCredentials(const char *pkipath, */ if (!*cacert) { VIR_DEBUG("Using default TLS CA certificate path"); - if (!(*cacert = strdup(LIBVIRT_CACERT))) + if (VIR_STRDUP(*cacert, LIBVIRT_CACERT) < 0) goto out_of_memory; } if (!*cacrl) { VIR_DEBUG("Using default TLS CA revocation list path"); - if (!(*cacrl = strdup(LIBVIRT_CACRL))) + if (VIR_STRDUP(*cacrl, LIBVIRT_CACRL) < 0) goto out_of_memory; } if (!*key && !*cert) { VIR_DEBUG("Using default TLS key/certificate path"); - if (!(*key = strdup(isServer ? LIBVIRT_SERVERKEY : LIBVIRT_CLIENTKEY))) + if (VIR_STRDUP(*key, isServer ? LIBVIRT_SERVERKEY : LIBVIRT_CLIENTKEY) < 0) goto out_of_memory; - if (!(*cert = strdup(isServer ? LIBVIRT_SERVERCERT : LIBVIRT_CLIENTCERT))) + if (VIR_STRDUP(*cert, isServer ? LIBVIRT_SERVERCERT : LIBVIRT_CLIENTCERT) < 0) goto out_of_memory; } @@ -1028,7 +1028,7 @@ static int virNetTLSContextValidCertificate(virNetTLSContextPtr ctxt, "[session]", gnutls_strerror(ret)); goto authfail; } - if (!(sess->x509dname = strdup(dname))) { + if (VIR_STRDUP(sess->x509dname, dname) < 0) { virReportOOMError(); goto authfail; } @@ -1168,8 +1168,7 @@ virNetTLSSessionPtr virNetTLSSessionNew(virNetTLSContextPtr ctxt, if (!(sess = virObjectLockableNew(virNetTLSSessionClass))) return NULL; - if (hostname && - !(sess->hostname = strdup(hostname))) { + if (hostname && VIR_STRDUP(sess->hostname, hostname) < 0) { virReportOOMError(); goto error; } -- 1.8.1.5

--- src/secret/secret_driver.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/secret/secret_driver.c b/src/secret/secret_driver.c index 377b9f4..cfd5b6a 100644 --- a/src/secret/secret_driver.c +++ b/src/secret/secret_driver.c @@ -1097,8 +1097,7 @@ secretStateInitialize(bool privileged, secretDriverLock(driverState); if (privileged) { - base = strdup(SYSCONFDIR "/libvirt"); - if (base == NULL) + if (VIR_STRDUP(base, SYSCONFDIR "/libvirt") < 0) goto out_of_memory; } else { base = virGetUserConfigDirectory(); -- 1.8.1.5

--- src/security/security_apparmor.c | 11 ++++----- src/security/security_dac.c | 6 ++--- src/security/security_nop.c | 4 ++-- src/security/security_selinux.c | 49 ++++++++++++++++------------------------ src/security/virt-aa-helper.c | 4 ++-- 5 files changed, 30 insertions(+), 44 deletions(-) diff --git a/src/security/security_apparmor.c b/src/security/security_apparmor.c index a2deafb..e75886e 100644 --- a/src/security/security_apparmor.c +++ b/src/security/security_apparmor.c @@ -446,21 +446,18 @@ AppArmorGenSecurityLabel(virSecurityManagerPtr mgr ATTRIBUTE_UNUSED, if ((profile_name = get_profile_name(def)) == NULL) return rc; - secdef->label = strndup(profile_name, strlen(profile_name)); - if (!secdef->label) { + if (VIR_STRNDUP(secdef->label, profile_name, strlen(profile_name)) < 0) { virReportOOMError(); goto clean; } /* set imagelabel the same as label (but we won't use it) */ - secdef->imagelabel = strndup(profile_name, - strlen(profile_name)); - if (!secdef->imagelabel) { + if (VIR_STRNDUP(secdef->imagelabel, profile_name, strlen(profile_name)) < 0) { virReportOOMError(); goto err; } - if (!secdef->model && !(secdef->model = strdup(SECURITY_APPARMOR_NAME))) { + if (!secdef->model && VIR_STRDUP(secdef->model, SECURITY_APPARMOR_NAME) < 0) { virReportOOMError(); goto err; } @@ -931,7 +928,7 @@ AppArmorGetMountOptions(virSecurityManagerPtr mgr ATTRIBUTE_UNUSED, { char *opts; - if (!(opts = strdup(""))) { + if (VIR_STRDUP(opts, "") < 0) { virReportOOMError(); return NULL; } diff --git a/src/security/security_dac.c b/src/security/security_dac.c index 4143495..850b9d4 100644 --- a/src/security/security_dac.c +++ b/src/security/security_dac.c @@ -76,8 +76,7 @@ int parseIds(const char *label, uid_t *uidPtr, gid_t *gidPtr) char *owner = NULL; char *group = NULL; - tmp_label = strdup(label); - if (tmp_label == NULL) { + if (VIR_STRDUP(tmp_label, label) < 0) { virReportOOMError(); goto cleanup; } @@ -1051,8 +1050,7 @@ virSecurityDACGenLabel(virSecurityManagerPtr mgr, if (!seclabel->norelabel) { if (seclabel->imagelabel == NULL && seclabel->label != NULL) { - seclabel->imagelabel = strdup(seclabel->label); - if (seclabel->imagelabel == NULL) { + if (VIR_STRDUP(seclabel->imagelabel, seclabel->label) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot generate dac user and group id " "for domain %s"), def->name); diff --git a/src/security/security_nop.c b/src/security/security_nop.c index 2b9767e..00f4d67 100644 --- a/src/security/security_nop.c +++ b/src/security/security_nop.c @@ -20,7 +20,7 @@ #include <config.h> #include "security_nop.h" - +#include "virstring.h" #include "virerror.h" #define VIR_FROM_THIS VIR_FROM_SECURITY @@ -182,7 +182,7 @@ static char *virSecurityDomainGetMountOptionsNop(virSecurityManagerPtr mgr ATTRI { char *opts; - if (!(opts = strdup(""))) { + if (VIR_STRDUP(opts, "") < 0) { virReportOOMError(); return NULL; } diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c index 201fff6..13f0601 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -202,7 +202,7 @@ virSecuritySELinuxMCSGetProcessRange(char **sens, goto cleanup; } - if (!(*sens = strdup(context_range_get(ourContext)))) { + if (VIR_STRDUP(*sens, context_range_get(ourContext)) < 0) { virReportOOMError(); goto cleanup; } @@ -312,7 +312,7 @@ virSecuritySELinuxContextAddRange(security_context_t src, goto cleanup; } - if (!(ret = strdup(str))) { + if (VIR_STRDUP(ret, str) < 0) { virReportOOMError(); goto cleanup; } @@ -385,7 +385,7 @@ virSecuritySELinuxGenNewContext(const char *basecontext, _("Unable to format SELinux context")); goto cleanup; } - if (!(ret = strdup(str))) { + if (VIR_STRDUP(ret, str) < 0) { virReportOOMError(); goto cleanup; } @@ -451,12 +451,9 @@ virSecuritySELinuxLXCInitialize(virSecurityManagerPtr mgr) goto error; } - data->domain_context = strdup(scon->str); - data->file_context = strdup(tcon->str); - data->content_context = strdup(dcon->str); - if (!data->domain_context || - !data->file_context || - !data->content_context) { + if (VIR_STRDUP(data->domain_context, scon->str) < 0 || + VIR_STRDUP(data->file_context, tcon->str) < 0 || + VIR_STRDUP(data->content_context, dcon->str) < 0) { virReportSystemError(errno, _("cannot allocate memory for LXC SELinux contexts '%s'"), selinux_lxc_contexts_path()); @@ -520,8 +517,7 @@ virSecuritySELinuxQEMUInitialize(virSecurityManagerPtr mgr) *ptr = '\0'; ptr++; if (*ptr != '\0') { - data->alt_domain_context = strdup(ptr); - if (!data->alt_domain_context) { + if (VIR_STRDUP(data->alt_domain_context, ptr) < 0) { virReportOOMError(); goto error; } @@ -544,8 +540,7 @@ virSecuritySELinuxQEMUInitialize(virSecurityManagerPtr mgr) ptr = strchrnul(data->file_context, '\n'); if (ptr && *ptr == '\n') { *ptr = '\0'; - data->content_context = strdup(ptr+1); - if (!data->content_context) { + if (VIR_STRDUP(data->content_context, ptr+1) < 0) { virReportOOMError(); goto error; } @@ -643,8 +638,7 @@ virSecuritySELinuxGenSecurityLabel(virSecurityManagerPtr mgr, } range = context_range_get(ctx); - if (!range || - !(mcs = strdup(range))) { + if (!range || VIR_STRDUP(mcs, range) < 0) { virReportOOMError(); goto cleanup; } @@ -710,8 +704,7 @@ virSecuritySELinuxGenSecurityLabel(virSecurityManagerPtr mgr, goto cleanup; } - if (!seclabel->model && - !(seclabel->model = strdup(SECURITY_SELINUX_NAME))) { + if (!seclabel->model && VIR_STRDUP(seclabel->model, SECURITY_SELINUX_NAME) < 0) { virReportOOMError(); goto cleanup; } @@ -1390,7 +1383,7 @@ virSecuritySELinuxSetSecurityHostdevCapsLabel(virDomainDefPtr def, return -1; } } else { - if (!(path = strdup(dev->source.caps.u.storage.block))) { + if (VIR_STRDUP(path, dev->source.caps.u.storage.block) < 0) { virReportOOMError(); return -1; } @@ -1408,7 +1401,7 @@ virSecuritySELinuxSetSecurityHostdevCapsLabel(virDomainDefPtr def, return -1; } } else { - if (!(path = strdup(dev->source.caps.u.misc.chardev))) { + if (VIR_STRDUP(path, dev->source.caps.u.misc.chardev) < 0) { virReportOOMError(); return -1; } @@ -1557,7 +1550,7 @@ virSecuritySELinuxRestoreSecurityHostdevCapsLabel(virSecurityManagerPtr mgr, return -1; } } else { - if (!(path = strdup(dev->source.caps.u.storage.block))) { + if (VIR_STRDUP(path, dev->source.caps.u.storage.block) < 0) { virReportOOMError(); return -1; } @@ -1575,7 +1568,7 @@ virSecuritySELinuxRestoreSecurityHostdevCapsLabel(virSecurityManagerPtr mgr, return -1; } } else { - if (!(path = strdup(dev->source.caps.u.misc.chardev))) { + if (VIR_STRDUP(path, dev->source.caps.u.misc.chardev) < 0) { virReportOOMError(); return -1; } @@ -2364,7 +2357,7 @@ virSecuritySELinuxGenImageLabel(virSecurityManagerPtr mgr, const char *range; context_t ctx = NULL; char *label = NULL; - const char *mcs = NULL; + char *mcs = NULL; secdef = virDomainDefGetSecurityLabelDef(def, SECURITY_SELINUX_NAME); if (secdef == NULL) @@ -2378,8 +2371,7 @@ virSecuritySELinuxGenImageLabel(virSecurityManagerPtr mgr, } range = context_range_get(ctx); if (range) { - mcs = strdup(range); - if (!mcs) { + if (VIR_STRDUP(mcs, range) < 0) { virReportOOMError(); goto cleanup; } @@ -2390,9 +2382,9 @@ virSecuritySELinuxGenImageLabel(virSecurityManagerPtr mgr, } cleanup: - context_free(ctx); - VIR_FREE(mcs); - return label; + context_free(ctx); + VIR_FREE(mcs); + return label; } static char * @@ -2415,8 +2407,7 @@ virSecuritySELinuxGetSecurityMountOptions(virSecurityManagerPtr mgr, } } - if (!opts && - !(opts = strdup(""))) { + if (!opts && VIR_STRDUP(opts, "") < 0) { virReportOOMError(); return NULL; } diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index b526919..7ead3d0 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -773,7 +773,7 @@ vah_add_file(virBufferPtr buf, const char *path, const char *perms) return rc; } } else - if ((tmp = strdup(path)) == NULL) + if (VIR_STRDUP(tmp, path) < 0) return rc; if (strchr(perms, 'w') != NULL) @@ -1103,7 +1103,7 @@ vahParseArgv(vahControl * ctl, int argc, char **argv) break; case 'f': case 'F': - if ((ctl->newfile = strdup(optarg)) == NULL) + if (VIR_STRDUP(ctl->newfile, optarg) < 0) vah_error(ctl, 1, _("could not allocate memory for disk")); ctl->append = arg == 'F'; break; -- 1.8.1.5

--- src/storage/parthelper.c | 7 ++++--- src/storage/storage_backend.c | 16 ++++++---------- src/storage/storage_backend_disk.c | 14 +++++++------- src/storage/storage_backend_fs.c | 17 ++++++++--------- src/storage/storage_backend_iscsi.c | 14 ++++++-------- src/storage/storage_backend_logical.c | 24 ++++++++++++------------ src/storage/storage_backend_mpath.c | 3 +-- src/storage/storage_backend_rbd.c | 3 +-- src/storage/storage_backend_scsi.c | 16 +++++++--------- src/storage/storage_driver.c | 11 +++++------ 10 files changed, 57 insertions(+), 68 deletions(-) diff --git a/src/storage/parthelper.c b/src/storage/parthelper.c index c4af48f..a1fd516 100644 --- a/src/storage/parthelper.c +++ b/src/storage/parthelper.c @@ -44,6 +44,9 @@ #include "virutil.h" #include "c-ctype.h" #include "configmake.h" +#include "virstring.h" + +#define VIR_FROM_THIS VIR_FROM_NONE /* we don't need to include the full internal.h just for this */ #define STREQ(a,b) (strcmp(a,b) == 0) @@ -86,10 +89,8 @@ int main(int argc, char **argv) path = argv[1]; if (virIsDevMapperDevice(path)) { partsep = "p"; - canonical_path = strdup(path); - if (canonical_path == NULL) { + if (VIR_STRDUP(canonical_path, path) < 0) return 2; - } } else { if (virFileResolveLink(path, &canonical_path) != 0) { return 2; diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c index b85a5a9..f14de87 100644 --- a/src/storage/storage_backend.c +++ b/src/storage/storage_backend.c @@ -486,8 +486,7 @@ virStorageGenerateQcowEncryption(virConnectPtr conn, goto cleanup; def->usage_type = VIR_SECRET_USAGE_TYPE_VOLUME; - def->usage.volume = strdup(vol->target.path); - if (def->usage.volume == NULL) { + if (VIR_STRDUP(def->usage.volume, vol->target.path) < 0) { virReportOOMError(); goto cleanup; } @@ -1261,12 +1260,12 @@ virStorageBackendUpdateVolTargetInfoFD(virStorageVolTargetPtr target, target->perms.label = NULL; } } else { - target->perms.label = strdup(filecon); - freecon(filecon); - if (target->perms.label == NULL) { + if (VIR_STRDUP(target->perms.label, filecon) < 0) { + freecon(filecon); virReportOOMError(); return -1; } + freecon(filecon); } #else target->perms.label = NULL; @@ -1451,9 +1450,7 @@ virStorageBackendStablePath(virStoragePoolObjPtr pool, * the original non-stable dev path */ - stablepath = strdup(devpath); - - if (stablepath == NULL) + if (VIR_STRDUP(stablepath, devpath) < 0) virReportOOMError(); return stablepath; @@ -1556,8 +1553,7 @@ virStorageBackendRunProgRegex(virStoragePoolObjPtr pool, for (j = 0 ; j < nvars[i] ; j++) { /* NB vars[0] is the full pattern, so we offset j by 1 */ p[vars[j+1].rm_eo] = '\0'; - if ((groups[ngroup++] = - strdup(p + vars[j+1].rm_so)) == NULL) { + if (VIR_STRDUP(groups[ngroup++], p + vars[j+1].rm_so) < 0) { virReportOOMError(); goto cleanup; } diff --git a/src/storage/storage_backend_disk.c b/src/storage/storage_backend_disk.c index 6da2d12..c996416 100644 --- a/src/storage/storage_backend_disk.c +++ b/src/storage/storage_backend_disk.c @@ -66,14 +66,14 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr pool, * strip the path to form a reasonable pool-unique name */ tmp = strrchr(groups[0], '/'); - if ((vol->name = strdup(tmp ? tmp + 1 : groups[0])) == NULL) { + if (VIR_STRDUP(vol->name, tmp ? tmp + 1 : groups[0]) < 0) { virReportOOMError(); return -1; } } if (vol->target.path == NULL) { - if ((devpath = strdup(groups[0])) == NULL) { + if (VIR_STRDUP(devpath, groups[0]) < 0) { virReportOOMError(); return -1; } @@ -92,7 +92,7 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr pool, if (vol->key == NULL) { /* XXX base off a unique key of the underlying disk */ - if ((vol->key = strdup(vol->target.path)) == NULL) { + if (VIR_STRDUP(vol->key, vol->target.path) < 0) { virReportOOMError(); return -1; } @@ -119,8 +119,8 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr pool, return -1; } - if ((vol->source.extents[0].path = - strdup(pool->def->source.devices[0].path)) == NULL) { + if (VIR_STRDUP(vol->source.extents[0].path, + pool->def->source.devices[0].path) < 0) { virReportOOMError(); return -1; } @@ -485,7 +485,7 @@ virStorageBackendDiskPartFormat(virStoragePoolObjPtr pool, return -1; } } - if ((*partFormat = strdup(partedFormat)) == NULL) { + if (VIR_STRDUP(*partFormat, partedFormat) < 0) { virReportOOMError(); return -1; } @@ -527,7 +527,7 @@ virStorageBackendDiskPartFormat(virStoragePoolObjPtr pool, } } } else { - if ((*partFormat = strdup("primary")) == NULL) { + if (VIR_STRDUP(*partFormat, "primary") < 0) { virReportOOMError(); return -1; } diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c index 8288b1e..e93da4c 100644 --- a/src/storage/storage_backend_fs.c +++ b/src/storage/storage_backend_fs.c @@ -207,8 +207,8 @@ virStorageBackendFileSystemNetFindPoolSourcesFunc(virStoragePoolObjPtr pool ATTR } src->nhost = 1; - if (!(src->hosts[0].name = strdup(state->host)) || - !(src->dir = strdup(path))) { + if (VIR_STRDUP(src->hosts[0].name, state->host) < 0 || + VIR_STRDUP(src->dir, path) < 0) { virReportOOMError(); goto cleanup; } @@ -395,7 +395,7 @@ virStorageBackendFileSystemMount(virStoragePoolObjPtr pool) { } } else { - if ((src = strdup(pool->def->source.devices[0].path)) == NULL) { + if (VIR_STRDUP(src, pool->def->source.devices[0].path) < 0) { virReportOOMError(); return -1; } @@ -571,7 +571,7 @@ virStorageBackendFileSystemProbe(const char *device, goto error; } - if ((libblkid_format = strdup(format)) == NULL) { + if (VIR_STRDUP(libblkid_format, format) < 0) { virReportOOMError(); goto error; } @@ -749,7 +749,7 @@ virStorageBackendFileSystemBuild(virConnectPtr conn ATTRIBUTE_UNUSED, goto error; } - if ((parent = strdup(pool->def->target.path)) == NULL) { + if (VIR_STRDUP(parent, pool->def->target.path) < 0) { virReportOOMError(); goto error; } @@ -833,7 +833,7 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn ATTRIBUTE_UNUSED, if (VIR_ALLOC(vol) < 0) goto no_memory; - if ((vol->name = strdup(ent->d_name)) == NULL) + if (VIR_STRDUP(vol->name, ent->d_name) < 0) goto no_memory; vol->type = VIR_STORAGE_VOL_FILE; @@ -843,7 +843,7 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn ATTRIBUTE_UNUSED, vol->name) == -1) goto no_memory; - if ((vol->key = strdup(vol->target.path)) == NULL) + if (VIR_STRDUP(vol->key, vol->target.path) < 0) goto no_memory; if ((ret = virStorageBackendProbeTarget(&vol->target, @@ -1011,8 +1011,7 @@ virStorageBackendFileSystemVolCreate(virConnectPtr conn ATTRIBUTE_UNUSED, } VIR_FREE(vol->key); - vol->key = strdup(vol->target.path); - if (vol->key == NULL) { + if (VIR_STRDUP(vol->key, vol->target.path) < 0) { virReportOOMError(); return -1; } diff --git a/src/storage/storage_backend_iscsi.c b/src/storage/storage_backend_iscsi.c index cf25919..355f690 100644 --- a/src/storage/storage_backend_iscsi.c +++ b/src/storage/storage_backend_iscsi.c @@ -125,11 +125,10 @@ virStorageBackendISCSIExtractSession(virStoragePoolObjPtr pool, { char **session = data; - if (STREQ(groups[1], pool->def->source.devices[0].path)) { - if ((*session = strdup(groups[0])) == NULL) { - virReportOOMError(); - return -1; - } + if (STREQ(groups[1], pool->def->source.devices[0].path) && + VIR_STRDUP(*session, groups[0]) < 0) { + virReportOOMError(); + return -1; } return 0; @@ -247,8 +246,7 @@ virStorageBackendIQNFound(const char *initiatoriqn, "of '%s'"), ISCSIADM); goto out; } - *ifacename = strndup(line, token - line); - if (*ifacename == NULL) { + if (VIR_STRNDUP(*ifacename, line, token - line) < 0) { ret = IQN_ERROR; virReportOOMError(); goto out; @@ -499,7 +497,7 @@ virStorageBackendISCSIGetTargets(virStoragePoolObjPtr pool ATTRIBUTE_UNUSED, struct virStorageBackendISCSITargetList *list = data; char *target; - if (!(target = strdup(groups[1]))) { + if (VIR_STRDUP(target, groups[1]) < 0) { virReportOOMError(); return -1; } diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c index 316043f..77bc83b 100644 --- a/src/storage/storage_backend_logical.c +++ b/src/storage/storage_backend_logical.c @@ -100,7 +100,7 @@ virStorageBackendLogicalMakeVol(virStoragePoolObjPtr pool, is_new_vol = true; vol->type = VIR_STORAGE_VOL_BLOCK; - if ((vol->name = strdup(groups[0])) == NULL) { + if (VIR_STRDUP(vol->name, groups[0]) < 0) { virReportOOMError(); goto cleanup; } @@ -137,8 +137,7 @@ virStorageBackendLogicalMakeVol(virStoragePoolObjPtr pool, vol->backingStore.format = VIR_STORAGE_POOL_LOGICAL_LVM2; } - if (vol->key == NULL && - (vol->key = strdup(groups[2])) == NULL) { + if (vol->key == NULL && VIR_STRDUP(vol->key, groups[2]) < 0) { virReportOOMError(); goto cleanup; } @@ -179,7 +178,10 @@ virStorageBackendLogicalMakeVol(virStoragePoolObjPtr pool, } /* Now parse the "devices" field separately */ - regex = strdup(regex_unit); + if (VIR_STRDUP(regex, regex_unit) < 0) { + virReportOOMError(); + goto cleanup; + } for (i = 1; i < nextents; i++) { if (VIR_REALLOC_N(regex, strlen(regex) + strlen(regex_unit) + 2) < 0) { @@ -229,20 +231,20 @@ virStorageBackendLogicalMakeVol(virStoragePoolObjPtr pool, /* vars[0] is skipped */ for (i = 0; i < nextents; i++) { int j, len; - const char *offset_str = NULL; + char *offset_str = NULL; j = (i * 2) + 1; len = vars[j].rm_eo - vars[j].rm_so; p[vars[j].rm_eo] = '\0'; - if ((vol->source.extents[vol->source.nextent].path = - strndup(p + vars[j].rm_so, len)) == NULL) { + if (VIR_STRNDUP(vol->source.extents[vol->source.nextent].path, + p + vars[j].rm_so, len) < 0) { virReportOOMError(); goto cleanup; } len = vars[j + 1].rm_eo - vars[j + 1].rm_so; - if (!(offset_str = strndup(p + vars[j + 1].rm_so, len))) { + if (VIR_STRNDUP(offset_str, p + vars[j + 1].rm_so, len) < 0) { virReportOOMError(); goto cleanup; } @@ -358,10 +360,8 @@ virStorageBackendLogicalFindPoolSourcesFunc(virStoragePoolObjPtr pool ATTRIBUTE_ virStoragePoolSourceDevicePtr dev; virStoragePoolSource *thisSource; - pvname = strdup(groups[0]); - vgname = strdup(groups[1]); - - if (pvname == NULL || vgname == NULL) { + if (VIR_STRDUP(pvname, groups[0]) < 0 || + VIR_STRDUP(vgname, groups[1]) < 0) { virReportOOMError(); goto err_no_memory; } diff --git a/src/storage/storage_backend_mpath.c b/src/storage/storage_backend_mpath.c index 6e742f7..9545d54 100644 --- a/src/storage/storage_backend_mpath.c +++ b/src/storage/storage_backend_mpath.c @@ -99,8 +99,7 @@ virStorageBackendMpathNewVol(virStoragePoolObjPtr pool, } /* XXX should use logical unit's UUID instead */ - vol->key = strdup(vol->target.path); - if (vol->key == NULL) { + if (VIR_STRDUP(vol->key, vol->target.path) < 0) { virReportOOMError(); goto cleanup; } diff --git a/src/storage/storage_backend_rbd.c b/src/storage/storage_backend_rbd.c index ca23d4b..3bdd73a 100644 --- a/src/storage/storage_backend_rbd.c +++ b/src/storage/storage_backend_rbd.c @@ -333,8 +333,7 @@ static int virStorageBackendRBDRefreshPool(virConnectPtr conn ATTRIBUTE_UNUSED, if (VIR_ALLOC(vol) < 0) goto out_of_memory; - vol->name = strdup(name); - if (vol->name == NULL) { + if (VIR_STRDUP(vol->name, name) < 0) { VIR_FREE(vol); goto out_of_memory; } diff --git a/src/storage/storage_backend_scsi.c b/src/storage/storage_backend_scsi.c index 154a56a..ac8a156 100644 --- a/src/storage/storage_backend_scsi.c +++ b/src/storage/storage_backend_scsi.c @@ -188,7 +188,7 @@ virStorageBackendSCSISerial(const char *dev) *nl = '\0'; } else { VIR_FREE(serial); - if (!(serial = strdup(dev))) + if (VIR_STRDUP(serial, dev) < 0) virReportOOMError(); } @@ -333,9 +333,7 @@ getNewStyleBlockDevice(const char *lun_path, continue; } - *block_device = strdup(block_dirent->d_name); - - if (*block_device == NULL) { + if (VIR_STRDUP(*block_device, block_dirent->d_name) < 0) { virReportOOMError(); closedir(block_dir); retval = -1; @@ -373,9 +371,7 @@ getOldStyleBlockDevice(const char *lun_path ATTRIBUTE_UNUSED, retval = -1; } else { blockp++; - *block_device = strdup(blockp); - - if (*block_device == NULL) { + if (VIR_STRDUP(*block_device, blockp) < 0) { virReportOOMError(); retval = -1; goto out; @@ -630,8 +626,10 @@ getAdapterName(virStoragePoolSourceAdapter adapter) { char *name = NULL; - if (adapter.type != VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_FC_HOST) - return strdup(adapter.data.name); + if (adapter.type != VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_FC_HOST) { + ignore_value(VIR_STRDUP(name, adapter.data.name)); + return name; + } if (!(name = virGetFCHostNameByWWN(NULL, adapter.data.fchost.wwnn, diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index 990f0b1..824f501 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -144,7 +144,7 @@ storageStateInitialize(bool privileged, storageDriverLock(driverState); if (privileged) { - if ((base = strdup(SYSCONFDIR "/libvirt")) == NULL) + if (VIR_STRDUP(base, SYSCONFDIR "/libvirt") < 0) goto out_of_memory; } else { base = virGetUserConfigDirectory(); @@ -336,7 +336,7 @@ storageConnectListStoragePools(virConnectPtr conn, for (i = 0 ; i < driver->pools.count && got < nnames ; i++) { virStoragePoolObjLock(driver->pools.objs[i]); if (virStoragePoolObjIsActive(driver->pools.objs[i])) { - if (!(names[got] = strdup(driver->pools.objs[i]->def->name))) { + if (VIR_STRDUP(names[got], driver->pools.objs[i]->def->name) < 0) { virStoragePoolObjUnlock(driver->pools.objs[i]); virReportOOMError(); goto cleanup; @@ -384,7 +384,7 @@ storageConnectListDefinedStoragePools(virConnectPtr conn, for (i = 0 ; i < driver->pools.count && got < nnames ; i++) { virStoragePoolObjLock(driver->pools.objs[i]); if (!virStoragePoolObjIsActive(driver->pools.objs[i])) { - if (!(names[got] = strdup(driver->pools.objs[i]->def->name))) { + if (VIR_STRDUP(names[got], driver->pools.objs[i]->def->name) < 0) { virStoragePoolObjUnlock(driver->pools.objs[i]); virReportOOMError(); goto cleanup; @@ -1117,7 +1117,7 @@ storagePoolListVolumes(virStoragePoolPtr obj, } for (i = 0 ; i < pool->volumes.count && n < maxnames ; i++) { - if ((names[n++] = strdup(pool->volumes.objs[i]->name)) == NULL) { + if (VIR_STRDUP(names[n++], pool->volumes.objs[i]->name) < 0) { virReportOOMError(); goto cleanup; } @@ -2340,8 +2340,7 @@ storageVolGetPath(virStorageVolPtr obj) { goto cleanup; } - ret = strdup(vol->target.path); - if (ret == NULL) + if (VIR_STRDUP(ret, vol->target.path) < 0) virReportOOMError(); cleanup: -- 1.8.1.5

On 04/29/2013 09:50 AM, Michal Privoznik wrote:
--- src/storage/parthelper.c | 7 ++++--- src/storage/storage_backend.c | 16 ++++++---------- src/storage/storage_backend_disk.c | 14 +++++++------- src/storage/storage_backend_fs.c | 17 ++++++++--------- src/storage/storage_backend_iscsi.c | 14 ++++++-------- src/storage/storage_backend_logical.c | 24 ++++++++++++------------ src/storage/storage_backend_mpath.c | 3 +-- src/storage/storage_backend_rbd.c | 3 +-- src/storage/storage_backend_scsi.c | 16 +++++++--------- src/storage/storage_driver.c | 11 +++++------ 10 files changed, 57 insertions(+), 68 deletions(-)
...
diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c index b85a5a9..f14de87 100644 --- a/src/storage/storage_backend.c +++ b/src/storage/storage_backend.c ...
@@ -1556,8 +1553,7 @@ virStorageBackendRunProgRegex(virStoragePoolObjPtr pool, for (j = 0 ; j < nvars[i] ; j++) { /* NB vars[0] is the full pattern, so we offset j by 1 */ p[vars[j+1].rm_eo] = '\0'; - if ((groups[ngroup++] = - strdup(p + vars[j+1].rm_so)) == NULL) { + if (VIR_STRDUP(groups[ngroup++], p + vars[j+1].rm_so) < 0) {
Here's somewhere that we do the auto-increment inside the VIR_STRDUP() - just as a note/followup to 12/37 w/r/t Eric's comment about auto increment inside an all-caps macro. Not a problem, but just pointing just in case it's felt that no autoincrement should be done inside the macro... ...
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index 990f0b1..824f501 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c
...
@@ -1117,7 +1117,7 @@ storagePoolListVolumes(virStoragePoolPtr obj, }
for (i = 0 ; i < pool->volumes.count && n < maxnames ; i++) { - if ((names[n++] = strdup(pool->volumes.objs[i]->name)) == NULL) { + if (VIR_STRDUP(names[n++], pool->volumes.objs[i]->name) < 0) {
And another...

--- src/test/test_driver.c | 82 +++++++++++++++++++++++--------------------------- 1 file changed, 37 insertions(+), 45 deletions(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index f60f106..b7c121e 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -219,12 +219,10 @@ testBuildCapabilities(virConnectPtr conn) { caps->host.nsecModels = 1; if (VIR_ALLOC_N(caps->host.secModels, caps->host.nsecModels) < 0) goto no_memory; - caps->host.secModels[0].model = strdup("testSecurity"); - if (!caps->host.secModels[0].model) + if (VIR_STRDUP(caps->host.secModels[0].model, "testSecurity") < 0) goto no_memory; - caps->host.secModels[0].doi = strdup(""); - if (!caps->host.secModels[0].doi) + if (VIR_STRDUP(caps->host.secModels[0].doi, "") < 0) goto no_memory; return caps; @@ -673,10 +671,14 @@ static char *testBuildFilename(const char *relativeTo, const char *filename) { char *offset; int baseLen; + char *ret = NULL; + if (!filename || filename[0] == '\0') return NULL; - if (filename[0] == '/') - return strdup(filename); + if (filename[0] == '/') { + ignore_value(VIR_STRDUP(ret, filename)); + return ret; + } offset = strrchr(relativeTo, '/'); if ((baseLen = (offset-relativeTo+1))) { @@ -691,7 +693,8 @@ static char *testBuildFilename(const char *relativeTo, strcat(absFile, filename); return absFile; } else { - return strdup(filename); + ignore_value(VIR_STRDUP(ret, filename)); + return ret; } } @@ -754,12 +757,9 @@ static int testOpenVolumesForPool(xmlDocPtr xml, } } - if (def->key == NULL) { - def->key = strdup(def->target.path); - if (def->key == NULL) { - virReportOOMError(); - goto error; - } + if (!def->key && VIR_STRDUP(def->key, def->target.path) < 0) { + virReportOOMError(); + goto error; } pool->def->allocation += def->allocation; @@ -826,7 +826,7 @@ static int testOpenFromFile(virConnectPtr conn, privconn->nextDomID = 1; privconn->numCells = 0; - if ((privconn->path = strdup(file)) == NULL) { + if (VIR_STRDUP(privconn->path, file) < 0) { virReportOOMError(); goto error; } @@ -2060,8 +2060,9 @@ cleanup: } static char *testDomainGetOSType(virDomainPtr dom ATTRIBUTE_UNUSED) { - char *ret = strdup("linux"); - if (!ret) + char *ret; + + if (VIR_STRDUP(ret, "linux") < 0) virReportOOMError(); return ret; } @@ -2720,8 +2721,7 @@ static char *testDomainGetSchedulerType(virDomainPtr domain ATTRIBUTE_UNUSED, if (nparams) *nparams = 1; - type = strdup("fair"); - if (!type) + if (VIR_STRDUP(type, "fair") < 0) virReportOOMError(); return type; @@ -3020,7 +3020,7 @@ static int testConnectListNetworks(virConnectPtr conn, char **const names, int n for (i = 0 ; i < privconn->networks.count && n < nnames ; i++) { virNetworkObjLock(privconn->networks.objs[i]); if (virNetworkObjIsActive(privconn->networks.objs[i]) && - !(names[n++] = strdup(privconn->networks.objs[i]->def->name))) { + VIR_STRDUP(names[n++], privconn->networks.objs[i]->def->name) < 0) { virNetworkObjUnlock(privconn->networks.objs[i]); goto no_memory; } @@ -3063,7 +3063,7 @@ static int testConnectListDefinedNetworks(virConnectPtr conn, char **const names for (i = 0 ; i < privconn->networks.count && n < nnames ; i++) { virNetworkObjLock(privconn->networks.objs[i]); if (!virNetworkObjIsActive(privconn->networks.objs[i]) && - !(names[n++] = strdup(privconn->networks.objs[i]->def->name))) { + VIR_STRDUP(names[n++], privconn->networks.objs[i]->def->name) < 0) { virNetworkObjUnlock(privconn->networks.objs[i]); goto no_memory; } @@ -3381,7 +3381,7 @@ static char *testNetworkGetBridgeName(virNetworkPtr network) { goto cleanup; } - if (!(bridge = strdup(privnet->def->bridge))) { + if (VIR_STRDUP(bridge, privnet->def->bridge) < 0) { virReportOOMError(); goto cleanup; } @@ -3494,7 +3494,7 @@ static int testConnectListInterfaces(virConnectPtr conn, char **const names, int for (i = 0 ; (i < privconn->ifaces.count) && (n < nnames); i++) { virInterfaceObjLock(privconn->ifaces.objs[i]); if (virInterfaceObjIsActive(privconn->ifaces.objs[i])) { - if (!(names[n++] = strdup(privconn->ifaces.objs[i]->def->name))) { + if (VIR_STRDUP(names[n++], privconn->ifaces.objs[i]->def->name) < 0) { virInterfaceObjUnlock(privconn->ifaces.objs[i]); goto no_memory; } @@ -3540,7 +3540,7 @@ static int testConnectListDefinedInterfaces(virConnectPtr conn, char **const nam for (i = 0 ; (i < privconn->ifaces.count) && (n < nnames); i++) { virInterfaceObjLock(privconn->ifaces.objs[i]); if (!virInterfaceObjIsActive(privconn->ifaces.objs[i])) { - if (!(names[n++] = strdup(privconn->ifaces.objs[i]->def->name))) { + if (VIR_STRDUP(names[n++], privconn->ifaces.objs[i]->def->name) < 0) { virInterfaceObjUnlock(privconn->ifaces.objs[i]); goto no_memory; } @@ -3880,8 +3880,7 @@ static int testStoragePoolObjSetDefaults(virStoragePoolObjPtr pool) { pool->def->allocation = defaultPoolAlloc; pool->def->available = defaultPoolCap - defaultPoolAlloc; - pool->configFile = strdup("\0"); - if (!pool->configFile) { + if (VIR_STRDUP(pool->configFile, "\0") < 0) { virReportOOMError(); return -1; } @@ -3989,7 +3988,7 @@ testConnectListStoragePools(virConnectPtr conn, for (i = 0 ; i < privconn->pools.count && n < nnames ; i++) { virStoragePoolObjLock(privconn->pools.objs[i]); if (virStoragePoolObjIsActive(privconn->pools.objs[i]) && - !(names[n++] = strdup(privconn->pools.objs[i]->def->name))) { + VIR_STRDUP(names[n++], privconn->pools.objs[i]->def->name) < 0) { virStoragePoolObjUnlock(privconn->pools.objs[i]); goto no_memory; } @@ -4036,7 +4035,7 @@ testConnectListDefinedStoragePools(virConnectPtr conn, for (i = 0 ; i < privconn->pools.count && n < nnames ; i++) { virStoragePoolObjLock(privconn->pools.objs[i]); if (!virStoragePoolObjIsActive(privconn->pools.objs[i]) && - !(names[n++] = strdup(privconn->pools.objs[i]->def->name))) { + VIR_STRDUP(names[n++], privconn->pools.objs[i]->def->name) < 0) { virStoragePoolObjUnlock(privconn->pools.objs[i]); goto no_memory; } @@ -4178,8 +4177,7 @@ testConnectFindStoragePoolSources(virConnectPtr conn ATTRIBUTE_UNUSED, switch (pool_type) { case VIR_STORAGE_POOL_LOGICAL: - ret = strdup(defaultPoolSourcesLogicalXML); - if (!ret) + if (VIR_STRDUP(ret, defaultPoolSourcesLogicalXML) < 0) virReportOOMError(); break; @@ -4648,7 +4646,7 @@ testStoragePoolListVolumes(virStoragePoolPtr pool, } for (i = 0 ; i < privpool->volumes.count && n < maxnames ; i++) { - if ((names[n++] = strdup(privpool->volumes.objs[i]->name)) == NULL) { + if (VIR_STRDUP(names[n++], privpool->volumes.objs[i]->name) < 0) { virReportOOMError(); goto cleanup; } @@ -4910,8 +4908,7 @@ testStorageVolCreateXML(virStoragePoolPtr pool, goto cleanup; } - privvol->key = strdup(privvol->target.path); - if (privvol->key == NULL) { + if (VIR_STRDUP(privvol->key, privvol->target.path) < 0) { virReportOOMError(); goto cleanup; } @@ -5005,8 +5002,7 @@ testStorageVolCreateXMLFrom(virStoragePoolPtr pool, goto cleanup; } - privvol->key = strdup(privvol->target.path); - if (privvol->key == NULL) { + if (VIR_STRDUP(privvol->key, privvol->target.path) < 0) { virReportOOMError(); goto cleanup; } @@ -5233,8 +5229,7 @@ testStorageVolGetPath(virStorageVolPtr vol) { goto cleanup; } - ret = strdup(privvol->target.path); - if (ret == NULL) + if (VIR_STRDUP(ret, privvol->target.path) < 0) virReportOOMError(); cleanup: @@ -5302,7 +5297,7 @@ testNodeListDevices(virConnectPtr conn, virNodeDeviceObjLock(driver->devs.objs[i]); if (cap == NULL || virNodeDeviceHasCap(driver->devs.objs[i], cap)) { - if ((names[ndevs++] = strdup(driver->devs.objs[i]->def->name)) == NULL) { + if (VIR_STRDUP(names[ndevs++], driver->devs.objs[i]->def->name) < 0) { virNodeDeviceObjUnlock(driver->devs.objs[i]); goto failure; } @@ -5393,8 +5388,7 @@ testNodeDeviceGetParent(virNodeDevicePtr dev) } if (obj->def->parent) { - ret = strdup(obj->def->parent); - if (!ret) + if (VIR_STRDUP(ret, obj->def->parent) < 0) virReportOOMError(); } else { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -5460,8 +5454,7 @@ testNodeDeviceListCaps(virNodeDevicePtr dev, char **const names, int maxnames) } for (caps = obj->def->caps; caps && ncaps < maxnames; caps = caps->next) { - names[ncaps] = strdup(virNodeDevCapTypeToString(caps->type)); - if (names[ncaps++] == NULL) + if (VIR_STRDUP(names[ncaps], virNodeDevCapTypeToString(caps->type)) < 0) goto cleanup; } ret = ncaps; @@ -5514,7 +5507,7 @@ 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 = strdup(wwpn))) { + if (VIR_STRDUP(def->name, wwpn) < 0) { virReportOOMError(); goto cleanup; } @@ -5568,8 +5561,7 @@ testNodeDeviceDestroy(virNodeDevicePtr dev) goto out; } - parent_name = strdup(obj->def->parent); - if (parent_name == NULL) { + if (VIR_STRDUP(parent_name, obj->def->parent) < 0) { virReportOOMError(); goto out; } @@ -5778,7 +5770,7 @@ testDomainScreenshot(virDomainPtr dom ATTRIBUTE_UNUSED, virCheckFlags(0, NULL); - if (!(ret = strdup("image/png"))) { + if (VIR_STRDUP(ret, "image/png") < 0) { virReportOOMError(); return NULL; } -- 1.8.1.5

--- src/uml/uml_conf.c | 4 ++-- src/uml/uml_driver.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/uml/uml_conf.c b/src/uml/uml_conf.c index a55b5b1..47e0fc0 100644 --- a/src/uml/uml_conf.c +++ b/src/uml/uml_conf.c @@ -114,7 +114,7 @@ umlConnectTapDevice(virConnectPtr conn, STRPREFIX(net->ifname, VIR_NET_GENERATED_PREFIX) || strchr(net->ifname, '%')) { VIR_FREE(net->ifname); - if (!(net->ifname = strdup(VIR_NET_GENERATED_PREFIX "%d"))) + if (VIR_STRDUP(net->ifname, VIR_NET_GENERATED_PREFIX "%d") < 0) goto no_memory; /* avoid exposing vnet%d in getXMLDesc or error outputs */ template_ifname = true; @@ -463,7 +463,7 @@ virCommandPtr umlBuildCommandLine(virConnectPtr conn, if (vm->def->os.cmdline) { char *args, *next_arg; char *cmdline; - if ((cmdline = strdup(vm->def->os.cmdline)) == NULL) + if (VIR_STRDUP(cmdline, vm->def->os.cmdline) < 0) goto no_memory; args = cmdline; diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c index 66c00b2..709edf1 100644 --- a/src/uml/uml_driver.c +++ b/src/uml/uml_driver.c @@ -248,7 +248,7 @@ requery: if (res && STRPREFIX(res, "pts:")) { VIR_FREE(def->source.data.file.path); - if ((def->source.data.file.path = strdup(res + 4)) == NULL) { + if (VIR_STRDUP(def->source.data.file.path, res + 4) < 0) { virReportOOMError(); VIR_FREE(res); VIR_FREE(cmd); @@ -491,7 +491,7 @@ umlStateInitialize(bool privileged, "%s/log/libvirt/uml", LOCALSTATEDIR) == -1) goto out_of_memory; - if ((base = strdup(SYSCONFDIR "/libvirt")) == NULL) + if (VIR_STRDUP(base, SYSCONFDIR "/libvirt") < 0) goto out_of_memory; if (virAsprintf(¨_driver->monitorDir, @@ -1665,7 +1665,7 @@ static char *umlDomainGetOSType(virDomainPtr dom) { goto cleanup; } - if (!(type = strdup(vm->def->os.type))) + if (VIR_STRDUP(type, vm->def->os.type) < 0) virReportOOMError(); cleanup: -- 1.8.1.5

--- src/util/virauth.c | 8 +- src/util/virauthconfig.c | 4 +- src/util/virbitmap.c | 9 ++- src/util/vircgroup.c | 31 +++----- src/util/vircommand.c | 29 +++---- src/util/virconf.c | 21 ++--- src/util/virdnsmasq.c | 4 +- src/util/virebtables.c | 34 ++++---- src/util/virerror.c | 18 ++--- src/util/virhash.c | 5 +- src/util/viridentity.c | 9 ++- src/util/virinitctl.c | 2 +- src/util/viriptables.c | 4 +- src/util/virjson.c | 17 ++-- src/util/virkeyfile.c | 7 +- src/util/virlockspace.c | 13 ++- src/util/virlog.c | 18 ++--- src/util/virnetdevmacvlan.c | 9 ++- src/util/virnetdevtap.c | 5 +- src/util/virnetdevvportprofile.c | 3 +- src/util/virobject.c | 5 +- src/util/virpci.c | 5 +- src/util/virsexpr.c | 25 ++---- src/util/virsocketaddr.c | 4 +- src/util/virstoragefile.c | 11 +-- src/util/virstring.c | 6 +- src/util/virsysinfo.c | 168 ++++++++++++++++----------------------- src/util/virtypedparam.c | 8 +- src/util/viruri.c | 18 ++--- src/util/virutil.c | 59 +++++++------- src/util/virxml.c | 6 +- 31 files changed, 252 insertions(+), 313 deletions(-) diff --git a/src/util/virauth.c b/src/util/virauth.c index fdcefe1..fcd4d3a 100644 --- a/src/util/virauth.c +++ b/src/util/virauth.c @@ -51,7 +51,7 @@ int virAuthGetConfigFilePath(virConnectPtr conn, if (authenv) { VIR_DEBUG("Using path from env '%s'", authenv); - if (!(*path = strdup(authenv))) + if (VIR_STRDUP(*path, authenv) < 0) goto no_memory; return 0; } @@ -62,7 +62,7 @@ int virAuthGetConfigFilePath(virConnectPtr conn, conn->uri->params[i].value) { VIR_DEBUG("Using path from URI '%s'", conn->uri->params[i].value); - if (!(*path = strdup(conn->uri->params[i].value))) + if (VIR_STRDUP(*path, conn->uri->params[i].value) < 0) goto no_memory; return 0; } @@ -81,7 +81,7 @@ int virAuthGetConfigFilePath(virConnectPtr conn, VIR_FREE(*path); - if (!(*path = strdup(SYSCONFDIR "/libvirt/auth.conf"))) + if (VIR_STRDUP(*path, SYSCONFDIR "/libvirt/auth.conf") < 0) goto no_memory; VIR_DEBUG("Checking for readability of '%s'", *path); @@ -137,7 +137,7 @@ virAuthGetCredential(virConnectPtr conn, goto cleanup; if (tmp && - !(*value = strdup(tmp))) { + VIR_STRDUP(*value, tmp) < 0) { virReportOOMError(); goto cleanup; } diff --git a/src/util/virauthconfig.c b/src/util/virauthconfig.c index 4259cb3..978be5d 100644 --- a/src/util/virauthconfig.c +++ b/src/util/virauthconfig.c @@ -47,7 +47,7 @@ virAuthConfigPtr virAuthConfigNew(const char *path) goto error; } - if (!(auth->path = strdup(path))) { + if (VIR_STRDUP(auth->path, path) < 0) { virReportOOMError(); goto error; } @@ -77,7 +77,7 @@ virAuthConfigPtr virAuthConfigNewData(const char *path, goto error; } - if (!(auth->path = strdup(path))) { + if (VIR_STRDUP(auth->path, path) < 0) { virReportOOMError(); goto error; } diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c index c81555a..cf6a099 100644 --- a/src/util/virbitmap.c +++ b/src/util/virbitmap.c @@ -37,6 +37,8 @@ #include "count-one-bits.h" #include "virstring.h" +#define VIR_FROM_THIS VIR_FROM_NONE + struct _virBitmap { size_t max_bit; size_t map_len; @@ -226,8 +228,11 @@ char *virBitmapFormat(virBitmapPtr bitmap) return NULL; cur = virBitmapNextSetBit(bitmap, -1); - if (cur < 0) - return strdup(""); + if (cur < 0) { + char *ret; + ignore_value(VIR_STRDUP(ret, "")); + return ret; + } start = prev = cur; while (prev >= 0) { diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index b05fc45..bf54b2a 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -116,19 +116,14 @@ static int virCgroupCopyMounts(virCgroupPtr group, if (!parent->controllers[i].mountPoint) continue; - group->controllers[i].mountPoint = - strdup(parent->controllers[i].mountPoint); - - if (!group->controllers[i].mountPoint) + if (VIR_STRDUP(group->controllers[i].mountPoint, + parent->controllers[i].mountPoint) < 0) return -ENOMEM; - if (parent->controllers[i].linkPoint) { - group->controllers[i].linkPoint = - strdup(parent->controllers[i].linkPoint); - - if (!group->controllers[i].linkPoint) - return -ENOMEM; - } + if (parent->controllers[i].linkPoint && + VIR_STRDUP(group->controllers[i].linkPoint, + parent->controllers[i].linkPoint) < 0) + return -ENOMEM; } return 0; } @@ -177,7 +172,7 @@ static int virCgroupDetectMounts(virCgroupPtr group) struct stat sb; char *tmp2; - if (!(group->controllers[i].mountPoint = strdup(entry.mnt_dir))) + if (VIR_STRDUP(group->controllers[i].mountPoint, entry.mnt_dir) < 0) goto no_memory; tmp2 = strrchr(entry.mnt_dir, '/'); @@ -239,7 +234,7 @@ static int virCgroupCopyPlacement(virCgroupPtr group, continue; if (path[0] == '/') { - if (!(group->controllers[i].placement = strdup(path))) + if (VIR_STRDUP(group->controllers[i].placement, path) < 0) return -ENOMEM; } else { /* @@ -821,7 +816,7 @@ static int virCgroupNew(const char *path, } if (path[0] == '/' || !parent) { - if (!((*group)->path = strdup(path))) { + if (VIR_STRDUP((*group)->path, path) < 0) { rc = -ENOMEM; goto err; } @@ -1253,7 +1248,7 @@ int virCgroupNewPartition(const char *path, if (STRNEQ(newpath, "/")) { char *tmp; - if (!(parentPath = strdup(newpath))) { + if (VIR_STRDUP(parentPath, newpath) < 0) { rc = -ENOMEM; goto cleanup; } @@ -2543,12 +2538,12 @@ static char *virCgroupIdentifyRoot(virCgroupPtr group) } tmp[0] = '\0'; - ret = strdup(group->controllers[i].mountPoint); - tmp[0] = '/'; - if (!ret) { + if (VIR_STRDUP(ret, group->controllers[i].mountPoint) < 0) { + tmp[0] = '/'; virReportOOMError(); return NULL; } + tmp[0] = '/'; return ret; } diff --git a/src/util/vircommand.c b/src/util/vircommand.c index f6f27d9..460e25b 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -946,7 +946,7 @@ virCommandSetPidFile(virCommandPtr cmd, const char *pidfile) return; VIR_FREE(cmd->pidfile); - if (!(cmd->pidfile = strdup(pidfile))) { + if (VIR_STRDUP(cmd->pidfile, pidfile) < 0) { cmd->has_error = ENOMEM; } } @@ -1049,7 +1049,7 @@ virCommandSetSELinuxLabel(virCommandPtr cmd, #if defined(WITH_SECDRIVER_SELINUX) VIR_FREE(cmd->seLinuxLabel); - if (label && !(cmd->seLinuxLabel = strdup(label))) + if (label && VIR_STRDUP(cmd->seLinuxLabel, label) < 0) cmd->has_error = ENOMEM; #endif return; @@ -1074,7 +1074,7 @@ virCommandSetAppArmorProfile(virCommandPtr cmd, #if defined(WITH_SECDRIVER_APPARMOR) VIR_FREE(cmd->appArmorProfile); - if (profile && !(cmd->appArmorProfile = strdup(profile))) + if (profile && VIR_STRDUP(cmd->appArmorProfile, profile) < 0) cmd->has_error = ENOMEM; #endif return; @@ -1205,7 +1205,7 @@ virCommandAddEnvString(virCommandPtr cmd, const char *str) if (!cmd || cmd->has_error) return; - if (!(env = strdup(str))) { + if (VIR_STRDUP(env, str) < 0) { cmd->has_error = ENOMEM; return; } @@ -1309,7 +1309,7 @@ virCommandAddArg(virCommandPtr cmd, const char *val) if (!cmd || cmd->has_error) return; - if (!(arg = strdup(val))) { + if (VIR_STRDUP(arg, val) < 0) { cmd->has_error = ENOMEM; return; } @@ -1350,9 +1350,8 @@ virCommandAddArgBuffer(virCommandPtr cmd, virBufferPtr buf) } cmd->args[cmd->nargs] = virBufferContentAndReset(buf); - if (!cmd->args[cmd->nargs]) - cmd->args[cmd->nargs] = strdup(""); - if (!cmd->args[cmd->nargs]) { + if (!cmd->args[cmd->nargs] && + VIR_STRDUP(cmd->args[cmd->nargs], "") < 0) { cmd->has_error = ENOMEM; return; } @@ -1440,8 +1439,9 @@ virCommandAddArgSet(virCommandPtr cmd, const char *const*vals) narg = 0; while (vals[narg] != NULL) { - char *arg = strdup(vals[narg++]); - if (!arg) { + char *arg; + + if (VIR_STRDUP(arg, vals[narg++]) < 0) { cmd->has_error = ENOMEM; return; } @@ -1481,8 +1481,7 @@ virCommandAddArgList(virCommandPtr cmd, ...) char *arg = va_arg(list, char *); if (!arg) break; - arg = strdup(arg); - if (!arg) { + if (VIR_STRDUP(arg, arg) < 0) { cmd->has_error = ENOMEM; va_end(list); return; @@ -1511,8 +1510,7 @@ virCommandSetWorkingDirectory(virCommandPtr cmd, const char *pwd) cmd->has_error = -1; VIR_DEBUG("cannot set directory twice"); } else { - cmd->pwd = strdup(pwd); - if (!cmd->pwd) + if (VIR_STRDUP(cmd->pwd, pwd) < 0) cmd->has_error = ENOMEM; } } @@ -1539,8 +1537,7 @@ virCommandSetInputBuffer(virCommandPtr cmd, const char *inbuf) return; } - cmd->inbuf = strdup(inbuf); - if (!cmd->inbuf) + if (VIR_STRDUP(cmd->inbuf, inbuf) < 0) cmd->has_error = ENOMEM; } diff --git a/src/util/virconf.c b/src/util/virconf.c index 16f074a..cd5f47c 100644 --- a/src/util/virconf.c +++ b/src/util/virconf.c @@ -38,6 +38,7 @@ #include "virlog.h" #include "viralloc.h" #include "virfile.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_CONF @@ -397,8 +398,7 @@ virConfParseString(virConfParserCtxtPtr ctxt) virConfError(ctxt, VIR_ERR_CONF_SYNTAX, _("unterminated string")); return NULL; } - ret = strndup(base, ctxt->cur - base); - if (ret == NULL) { + if (VIR_STRNDUP(ret, base, ctxt->cur - base) < 0) { virReportOOMError(); return NULL; } @@ -421,8 +421,7 @@ virConfParseString(virConfParserCtxtPtr ctxt) virConfError(ctxt, VIR_ERR_CONF_SYNTAX, _("unterminated string")); return NULL; } - ret = strndup(base, ctxt->cur - base); - if (ret == NULL) { + if (VIR_STRNDUP(ret, base, ctxt->cur - base) < 0) { virReportOOMError(); return NULL; } @@ -436,8 +435,7 @@ virConfParseString(virConfParserCtxtPtr ctxt) virConfError(ctxt, VIR_ERR_CONF_SYNTAX, _("unterminated string")); return NULL; } - ret = strndup(base, ctxt->cur - base); - if (ret == NULL) { + if (VIR_STRNDUP(ret, base, ctxt->cur - base) < 0) { virReportOOMError(); return NULL; } @@ -577,8 +575,7 @@ virConfParseName(virConfParserCtxtPtr ctxt) ((ctxt->conf->flags & VIR_CONF_FLAG_VMX_FORMAT) && ((CUR == ':') || (CUR == '.') || (CUR == '-'))))) NEXT; - ret = strndup(base, ctxt->cur - base); - if (ret == NULL) { + if (VIR_STRNDUP(ret, base, ctxt->cur - base) < 0) { virReportOOMError(); return NULL; } @@ -604,8 +601,7 @@ virConfParseComment(virConfParserCtxtPtr ctxt) NEXT; base = ctxt->cur; while ((ctxt->cur < ctxt->end) && (!IS_EOL(CUR))) NEXT; - comm = strndup(base, ctxt->cur - base); - if (comm == NULL) { + if (VIR_STRNDUP(comm, base, ctxt->cur - base) < 0) { virReportOOMError(); return -1; } @@ -680,8 +676,7 @@ virConfParseStatement(virConfParserCtxtPtr ctxt) NEXT; base = ctxt->cur; while ((ctxt->cur < ctxt->end) && (!IS_EOL(CUR))) NEXT; - comm = strndup(base, ctxt->cur - base); - if (comm == NULL) { + if (VIR_STRNDUP(comm, base, ctxt->cur - base) < 0) { virReportOOMError(); VIR_FREE(name); virConfFreeValue(value); @@ -905,7 +900,7 @@ virConfSetValue(virConfPtr conf, return -1; } cur->comment = NULL; - if (!(cur->name = strdup(setting))) { + if (VIR_STRDUP(cur->name, setting) < 0) { virReportOOMError(); virConfFreeValue(value); VIR_FREE(cur); diff --git a/src/util/virdnsmasq.c b/src/util/virdnsmasq.c index 4f05633..b162650 100644 --- a/src/util/virdnsmasq.c +++ b/src/util/virdnsmasq.c @@ -469,7 +469,7 @@ dnsmasqContextNew(const char *network_name, return NULL; } - if (!(ctx->config_dir = strdup(config_dir))) { + if (VIR_STRDUP(ctx->config_dir, config_dir) < 0) { virReportOOMError(); goto error; } @@ -798,7 +798,7 @@ dnsmasqCapsNewEmpty(const char *binaryPath) return NULL; if (!(caps->flags = virBitmapNew(DNSMASQ_CAPS_LAST))) goto error; - if (!(caps->binaryPath = strdup(binaryPath ? binaryPath : DNSMASQ))) + if (VIR_STRDUP(caps->binaryPath, binaryPath ? binaryPath : DNSMASQ) < 0) goto error; return caps; diff --git a/src/util/virebtables.c b/src/util/virebtables.c index 6bc6fed..13c462c 100644 --- a/src/util/virebtables.c +++ b/src/util/virebtables.c @@ -51,6 +51,8 @@ #include "virstring.h" #include "virutil.h" +#define VIR_FROM_THIS VIR_FROM_NONE + #if HAVE_FIREWALLD static char *firewall_cmd_path = NULL; @@ -186,10 +188,10 @@ ebtRulesNew(const char *table, if (VIR_ALLOC(rules) < 0) return NULL; - if (!(rules->table = strdup(table))) + if (VIR_STRDUP(rules->table, table) < 0) goto error; - if (!(rules->chain = strdup(chain))) + if (VIR_STRDUP(rules->chain, chain) < 0) goto error; rules->rules = NULL; @@ -207,7 +209,7 @@ ebtablesAddRemoveRule(ebtRules *rules, int action, const char *arg, ...) { va_list args; int retval = ENOMEM; - const char **argv; + char **argv; char *rule = NULL; const char *s; int n, command_idx; @@ -236,36 +238,36 @@ ebtablesAddRemoveRule(ebtRules *rules, int action, const char *arg, ...) #if HAVE_FIREWALLD if (firewall_cmd_path) { - if (!(argv[n++] = strdup(firewall_cmd_path))) + if (VIR_STRDUP(argv[n++], firewall_cmd_path) < 0) goto error; - if (!(argv[n++] = strdup("--direct"))) + if (VIR_STRDUP(argv[n++], "--direct") < 0) goto error; - if (!(argv[n++] = strdup("--passthrough"))) + if (VIR_STRDUP(argv[n++], "--passthrough") < 0) goto error; - if (!(argv[n++] = strdup("eb"))) + if (VIR_STRDUP(argv[n++], "eb") < 0) goto error; } else #endif - if (!(argv[n++] = strdup(EBTABLES_PATH))) + if (VIR_STRDUP(argv[n++], EBTABLES_PATH) < 0) goto error; command_idx = n; if (action == ADD || action == REMOVE) { - if (!(argv[n++] = strdup("--insert"))) + if (VIR_STRDUP(argv[n++], "--insert") < 0) goto error; - if (!(argv[n++] = strdup(rules->chain))) + if (VIR_STRDUP(argv[n++], rules->chain) < 0) goto error; } - if (!(argv[n++] = strdup(arg))) + if (VIR_STRDUP(argv[n++], arg) < 0) goto error; va_start(args, arg); while ((s = va_arg(args, const char *))) { - if (!(argv[n++] = strdup(s))) { + if (VIR_STRDUP(argv[n++], s) < 0) { va_end(args); goto error; } @@ -273,23 +275,23 @@ ebtablesAddRemoveRule(ebtRules *rules, int action, const char *arg, ...) va_end(args); - if (!(rule = virArgvToString(&argv[command_idx]))) + if (!(rule = virArgvToString((const char * const *) &argv[command_idx]))) goto error; if (action == REMOVE) { VIR_FREE(argv[command_idx]); - if (!(argv[command_idx] = strdup("--delete"))) + if (VIR_STRDUP(argv[command_idx], "--delete") < 0) goto error; } - if (virRun(argv, NULL) < 0) { + if (virRun((const char * const *) argv, NULL) < 0) { retval = errno; goto error; } if (action == ADD || action == CREATE || action == POLICY || action == INSERT) { - retval = ebtRulesAppend(rules, rule, argv, command_idx); + retval = ebtRulesAppend(rules, rule, (const char **) argv, command_idx); rule = NULL; argv = NULL; } else { diff --git a/src/util/virerror.c b/src/util/virerror.c index af4da8c..8761a72 100644 --- a/src/util/virerror.c +++ b/src/util/virerror.c @@ -164,7 +164,7 @@ virErrorGenericFailure(virErrorPtr err) err->code = VIR_ERR_INTERNAL_ERROR; err->domain = VIR_FROM_NONE; err->level = VIR_ERR_ERROR; - err->message = strdup(_("An error occurred, but the cause is unknown")); + ignore_value(VIR_STRDUP_QUIET(err->message, _("An error occurred, but the cause is unknown"))); } @@ -184,13 +184,13 @@ virCopyError(virErrorPtr from, to->code = from->code; to->domain = from->domain; to->level = from->level; - if (from->message && !(to->message = strdup(from->message))) + if (from->message && VIR_STRDUP_QUIET(to->message, from->message) < 0) ret = -1; - if (from->str1 && !(to->str1 = strdup(from->str1))) + if (from->str1 && VIR_STRDUP_QUIET(to->str1, from->str1) < 0) ret = -1; - if (from->str2 && !(to->str2 = strdup(from->str2))) + if (from->str2 && VIR_STRDUP_QUIET(to->str2, from->str2) < 0) ret = -1; - if (from->str3 && !(to->str3 = strdup(from->str3))) + if (from->str3 && VIR_STRDUP_QUIET(to->str3, from->str3) < 0) ret = -1; to->int1 = from->int1; to->int2 = from->int2; @@ -646,7 +646,7 @@ virRaiseErrorFull(const char *filename ATTRIBUTE_UNUSED, * formats the message; drop message on OOM situations */ if (fmt == NULL) { - str = strdup(_("No error message provided")); + ignore_value(VIR_STRDUP_QUIET(str, _("No error message provided"))); } else { va_list ap; va_start(ap, fmt); @@ -666,11 +666,11 @@ virRaiseErrorFull(const char *filename ATTRIBUTE_UNUSED, to->message = str; to->level = level; if (str1 != NULL) - to->str1 = strdup(str1); + ignore_value(VIR_STRDUP_QUIET(to->str1, str1)); if (str2 != NULL) - to->str2 = strdup(str2); + ignore_value(VIR_STRDUP_QUIET(to->str2, str2)); if (str3 != NULL) - to->str3 = strdup(str3); + ignore_value(VIR_STRDUP_QUIET(to->str3, str3)); to->int1 = int1; to->int2 = int2; diff --git a/src/util/virhash.c b/src/util/virhash.c index 2fe8751..bb708fc 100644 --- a/src/util/virhash.c +++ b/src/util/virhash.c @@ -30,6 +30,7 @@ #include "virlog.h" #include "virhashcode.h" #include "virrandom.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_NONE @@ -85,7 +86,9 @@ static bool virHashStrEqual(const void *namea, const void *nameb) static void *virHashStrCopy(const void *name) { - return strdup(name); + char *ret; + ignore_value(VIR_STRDUP(ret, name)); + return ret; } static void virHashStrFree(void *name) diff --git a/src/util/viridentity.c b/src/util/viridentity.c index c9efd3f..864c75a 100644 --- a/src/util/viridentity.c +++ b/src/util/viridentity.c @@ -34,6 +34,7 @@ #include "virobject.h" #include "virthread.h" #include "virutil.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_IDENTITY @@ -150,12 +151,12 @@ virIdentityPtr virIdentityGetSystem(void) _("Unable to lookup SELinux process context")); goto cleanup; } - seccontext = strdup(con); - freecon(con); - if (!seccontext) { + if (VIR_STRDUP(seccontext, con) < 0) { + freecon(con); virReportOOMError(); goto cleanup; } + freecon(con); #endif if (!(ret = virIdentityNew())) @@ -246,7 +247,7 @@ int virIdentitySetAttr(virIdentityPtr ident, goto cleanup; } - if (!(ident->attrs[attr] = strdup(value))) { + if (VIR_STRDUP(ident->attrs[attr], value) < 0) { virReportOOMError(); goto cleanup; } diff --git a/src/util/virinitctl.c b/src/util/virinitctl.c index 3322454..b9a7fbf 100644 --- a/src/util/virinitctl.c +++ b/src/util/virinitctl.c @@ -133,7 +133,7 @@ int virInitctlSetRunLevel(virInitctlRunLevel level, return -1; } } else { - if (!(path = strdup(VIR_INITCTL_FIFO))) { + if (VIR_STRDUP(path, VIR_INITCTL_FIFO) < 0) { virReportOOMError(); return -1; } diff --git a/src/util/viriptables.c b/src/util/viriptables.c index 06a1356..88c3bcd 100644 --- a/src/util/viriptables.c +++ b/src/util/viriptables.c @@ -118,10 +118,10 @@ iptRulesNew(const char *table, if (VIR_ALLOC(rules) < 0) return NULL; - if (!(rules->table = strdup(table))) + if (VIR_STRDUP(rules->table, table) < 0) goto error; - if (!(rules->chain = strdup(chain))) + if (VIR_STRDUP(rules->chain, chain) < 0) goto error; return rules; diff --git a/src/util/virjson.c b/src/util/virjson.c index 92138d3..995af90 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -107,7 +107,7 @@ virJSONValuePtr virJSONValueNewString(const char *data) return NULL; val->type = VIR_JSON_TYPE_STRING; - if (!(val->data.string = strdup(data))) { + if (VIR_STRDUP(val->data.string, data) < 0) { VIR_FREE(val); return NULL; } @@ -126,7 +126,7 @@ virJSONValuePtr virJSONValueNewStringLen(const char *data, size_t length) return NULL; val->type = VIR_JSON_TYPE_STRING; - if (!(val->data.string = strndup(data, length))) { + if (VIR_STRNDUP(val->data.string, data, length) < 0) { VIR_FREE(val); return NULL; } @@ -142,7 +142,7 @@ static virJSONValuePtr virJSONValueNewNumber(const char *data) return NULL; val->type = VIR_JSON_TYPE_NUMBER; - if (!(val->data.number = strdup(data))) { + if (VIR_STRDUP(val->data.number, data) < 0) { VIR_FREE(val); return NULL; } @@ -269,7 +269,7 @@ int virJSONValueObjectAppend(virJSONValuePtr object, const char *key, virJSONVal if (virJSONValueObjectHasKey(object, key)) return -1; - if (!(newkey = strdup(key))) + if (VIR_STRDUP(newkey, key) < 0) return -1; if (VIR_REALLOC_N(object->data.object.pairs, @@ -751,10 +751,10 @@ static int virJSONParserHandleNumber(void *ctx, yajl_size_t l) { virJSONParserPtr parser = ctx; - char *str = strndup(s, l); + char *str; virJSONValuePtr value; - if (!str) + if (VIR_STRNDUP(str, s, l) < 0) return -1; value = virJSONValueNewNumber(str); VIR_FREE(str); @@ -808,8 +808,7 @@ static int virJSONParserHandleMapKey(void *ctx, state = &parser->state[parser->nstate-1]; if (state->key) return 0; - state->key = strndup((const char *)stringVal, stringLen); - if (!state->key) + if (VIR_STRNDUP(state->key, (const char *)stringVal, stringLen) < 0) return 0; return 1; } @@ -1094,7 +1093,7 @@ char *virJSONValueToString(virJSONValuePtr object, goto cleanup; } - if (!(ret = strdup((const char *)str))) + if (VIR_STRDUP(ret, (const char *)str) < 0) virReportOOMError(); cleanup: diff --git a/src/util/virkeyfile.c b/src/util/virkeyfile.c index d77e95d..8bd930d 100644 --- a/src/util/virkeyfile.c +++ b/src/util/virkeyfile.c @@ -32,6 +32,7 @@ #include "virhash.h" #include "virkeyfile.h" #include "virerror.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_CONF @@ -121,7 +122,7 @@ static int virKeyFileParseGroup(virKeyFileParserCtxtPtr ctxt) return -1; } - if (!(ctxt->groupname = strndup(name, ctxt->cur - name))) { + if (VIR_STRNDUP(ctxt->groupname, name, ctxt->cur - name) < 0) { virReportOOMError(); return -1; } @@ -167,7 +168,7 @@ static int virKeyFileParseValue(virKeyFileParserCtxtPtr ctxt) return -1; } - if (!(key = strndup(keystart, ctxt->cur - keystart))) { + if (VIR_STRNDUP(key, keystart, ctxt->cur - keystart) < 0) { virReportOOMError(); return -1; } @@ -183,7 +184,7 @@ static int virKeyFileParseValue(virKeyFileParserCtxtPtr ctxt) len = ctxt->cur - valuestart; if (IS_EOF && !IS_EOL(CUR)) len++; - if (!(value = strndup(valuestart, len))) { + if (VIR_STRNDUP(value, valuestart, len) < 0) { virReportOOMError(); goto cleanup; } diff --git a/src/util/virlockspace.c b/src/util/virlockspace.c index 620a460..38f5669 100644 --- a/src/util/virlockspace.c +++ b/src/util/virlockspace.c @@ -70,7 +70,7 @@ static char *virLockSpaceGetResourcePath(virLockSpacePtr lockspace, return NULL; } } else { - if (!(ret = strdup(resname))) { + if (VIR_STRDUP(ret, resname) < 0) { virReportOOMError(); return NULL; } @@ -132,7 +132,7 @@ virLockSpaceResourceNew(virLockSpacePtr lockspace, res->fd = -1; res->flags = flags; - if (!(res->name = strdup(resname))) + if (VIR_STRDUP(res->name, resname) < 0) goto no_memory; if (!(res->path = virLockSpaceGetResourcePath(lockspace, resname))) @@ -262,8 +262,7 @@ virLockSpacePtr virLockSpaceNew(const char *directory) return NULL; } - if (directory && - !(lockspace->dir = strdup(directory))) + if (directory && VIR_STRDUP(lockspace->dir, directory) < 0) goto no_memory; if (!(lockspace->resources = virHashCreate(VIR_LOCKSPACE_TABLE_SIZE, @@ -324,7 +323,7 @@ virLockSpacePtr virLockSpaceNewPostExecRestart(virJSONValuePtr object) if (virJSONValueObjectHasKey(object, "directory")) { const char *dir = virJSONValueObjectGetString(object, "directory"); - if (!(lockspace->dir = strdup(dir))) { + if (VIR_STRDUP(lockspace->dir, dir) < 0) { virReportOOMError(); goto error; } @@ -362,7 +361,7 @@ virLockSpacePtr virLockSpaceNewPostExecRestart(virJSONValuePtr object) virLockSpaceResourceFree(res); goto error; } - if (!(res->name = strdup(tmp))) { + if (VIR_STRDUP(res->name, tmp) < 0) { virReportOOMError(); virLockSpaceResourceFree(res); goto error; @@ -374,7 +373,7 @@ virLockSpacePtr virLockSpaceNewPostExecRestart(virJSONValuePtr object) virLockSpaceResourceFree(res); goto error; } - if (!(res->path = strdup(tmp))) { + if (VIR_STRDUP(res->path, tmp) < 0) { virReportOOMError(); virLockSpaceResourceFree(res); goto error; diff --git a/src/util/virlog.c b/src/util/virlog.c index bd47b38..921ffc5 100644 --- a/src/util/virlog.c +++ b/src/util/virlog.c @@ -557,8 +557,7 @@ virLogDefineFilter(const char *match, } } - mdup = strdup(match); - if (mdup == NULL) { + if (VIR_STRDUP(mdup, match) < 0) { i = -1; goto cleanup; } @@ -667,8 +666,7 @@ virLogDefineOutput(virLogOutputFunc f, if (dest == VIR_LOG_TO_SYSLOG || dest == VIR_LOG_TO_FILE) { if (name == NULL) return -1; - ndup = strdup(name); - if (ndup == NULL) + if (VIR_STRDUP(ndup, name) < 0) return -1; } @@ -1047,8 +1045,7 @@ virLogAddOutputToSyslog(virLogPriority priority, * ident needs to be kept around on Solaris */ VIR_FREE(current_ident); - current_ident = strdup(ident); - if (current_ident == NULL) + if (VIR_STRDUP(current_ident, ident) < 0) return -1; openlog(current_ident, 0, 0); @@ -1329,8 +1326,7 @@ virLogParseOutputs(const char *outputs) if (str == cur) goto cleanup; #if HAVE_SYSLOG_H - name = strndup(str, cur - str); - if (name == NULL) + if (VIR_STRNDUP(name, str, cur - str) < 0) goto cleanup; if (virLogAddOutputToSyslog(prio, name) == 0) count++; @@ -1346,8 +1342,7 @@ virLogParseOutputs(const char *outputs) cur++; if (str == cur) goto cleanup; - name = strndup(str, cur - str); - if (name == NULL) + if (VIR_STRNDUP(name, str, cur - str) < 0) goto cleanup; if (virFileAbsPath(name, &abspath) < 0) { VIR_FREE(name); @@ -1424,8 +1419,7 @@ virLogParseFilters(const char *filters) cur++; if (str == cur) goto cleanup; - name = strndup(str, cur - str); - if (name == NULL) + if (VIR_STRNDUP(name, str, cur - str) < 0) goto cleanup; if (virLogDefineFilter(name, prio, flags) >= 0) count++; diff --git a/src/util/virnetdevmacvlan.c b/src/util/virnetdevmacvlan.c index 0c4fcbd..7892937 100644 --- a/src/util/virnetdevmacvlan.c +++ b/src/util/virnetdevmacvlan.c @@ -31,6 +31,7 @@ #include "virmacaddr.h" #include "virerror.h" #include "virthread.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_NET @@ -764,13 +765,13 @@ virNetDevMacVLanVPortProfileRegisterCallback(const char *ifname, if (virtPortProfile && virNetlinkEventServiceIsRunning(NETLINK_ROUTE)) { if (VIR_ALLOC(calld) < 0) goto memory_error; - if ((calld->cr_ifname = strdup(ifname)) == NULL) + if (VIR_STRDUP(calld->cr_ifname, ifname) < 0) goto memory_error; if (VIR_ALLOC(calld->virtPortProfile) < 0) goto memory_error; memcpy(calld->virtPortProfile, virtPortProfile, sizeof(*virtPortProfile)); virMacAddrSet(&calld->macaddress, macaddress); - if ((calld->linkdev = strdup(linkdev)) == NULL) + if (VIR_STRDUP(calld->linkdev, linkdev) < 0) goto memory_error; memcpy(calld->vmuuid, vmuuid, sizeof(calld->vmuuid)); @@ -927,13 +928,13 @@ create_name: VIR_FORCE_CLOSE(rc); /* sets rc to -1 */ goto disassociate_exit; } - if (!(*res_ifname = strdup(cr_ifname))) { + if (VIR_STRDUP(*res_ifname, cr_ifname) < 0) { VIR_FORCE_CLOSE(rc); /* sets rc to -1 */ virReportOOMError(); goto disassociate_exit; } } else { - if (!(*res_ifname = strdup(cr_ifname))) { + if (VIR_STRDUP(*res_ifname, cr_ifname) < 0) { virReportOOMError(); goto disassociate_exit; } diff --git a/src/util/virnetdevtap.c b/src/util/virnetdevtap.c index 0cd2e31..bcf5c39 100644 --- a/src/util/virnetdevtap.c +++ b/src/util/virnetdevtap.c @@ -64,8 +64,7 @@ virNetDevTapGetName(int tapfd, char **ifname) return -1; } - *ifname = strdup(ifr.ifr_name); - if (*ifname == NULL) { + if (VIR_STRDUP(*ifname, ifr.ifr_name) < 0) { virReportOOMError(); return -1; } @@ -204,7 +203,7 @@ int virNetDevTapCreate(char **ifname, } VIR_FREE(*ifname); - if (!(*ifname = strdup(ifr.ifr_name))) { + if (VIR_STRDUP(*ifname, ifr.ifr_name) < 0) { virReportOOMError(); goto cleanup; } diff --git a/src/util/virnetdevvportprofile.c b/src/util/virnetdevvportprofile.c index 883aa46..ba48429 100644 --- a/src/util/virnetdevvportprofile.c +++ b/src/util/virnetdevvportprofile.c @@ -1034,8 +1034,7 @@ virNetDevVPortProfileOp8021Qbh(const char *ifname, goto cleanup; } } else { - physfndev = strdup(ifname); - if (!physfndev) { + if (VIR_STRDUP(physfndev, ifname) < 0) { virReportOOMError(); rc = -1; goto cleanup; diff --git a/src/util/virobject.c b/src/util/virobject.c index 93e37e4..da5537b 100644 --- a/src/util/virobject.c +++ b/src/util/virobject.c @@ -28,6 +28,7 @@ #include "viratomic.h" #include "virerror.h" #include "virlog.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_NONE @@ -37,7 +38,7 @@ struct _virClass { virClassPtr parent; unsigned int magic; - const char *name; + char *name; size_t objectSize; virObjectDisposeCallback dispose; @@ -135,7 +136,7 @@ virClassPtr virClassNew(virClassPtr parent, goto no_memory; klass->parent = parent; - if (!(klass->name = strdup(name))) + if (VIR_STRDUP(klass->name, name) < 0) goto no_memory; klass->magic = virAtomicIntInc(&magicCounter); klass->objectSize = objectSize; diff --git a/src/util/virpci.c b/src/util/virpci.c index 6ed6a90..2160403 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -1364,7 +1364,7 @@ virPCIGetAddrString(unsigned int domain, dev = virPCIDeviceNew(domain, bus, slot, function); if (dev != NULL) { - if ((*pciConfigAddr = strdup(dev->name)) == NULL) { + if (VIR_STRDUP(*pciConfigAddr, dev->name) < 0) { virReportOOMError(); goto cleanup; } @@ -2240,8 +2240,7 @@ virPCIGetNetName(char *device_link_sysfs_path, char **netname) continue; /* Assume a single directory entry */ - *netname = strdup(entry->d_name); - if (!*netname) + if (VIR_STRDUP(*netname, entry->d_name) < 0) virReportOOMError(); else ret = 0; diff --git a/src/util/virsexpr.c b/src/util/virsexpr.c index 23b6781..d621d8e 100644 --- a/src/util/virsexpr.c +++ b/src/util/virsexpr.c @@ -118,17 +118,11 @@ sexpr_string(const char *str, ssize_t len) if (ret == NULL) return ret; - ret->kind = SEXPR_VALUE; - if (len > 0) { - ret->u.value = strndup(str, len); - } else { - ret->u.value = strdup(str); - } - if (ret->u.value == NULL) { + ret->kind = SEXPR_VALUE; + if ((len > 0 && VIR_STRNDUP(ret->u.value, str, len) < 0) || + (len <= 0 && VIR_STRDUP(ret->u.value, str) < 0)) VIR_FREE(ret); - return NULL; - } return ret; } @@ -325,8 +319,7 @@ _string2sexpr(const char *buffer, size_t * end) ptr++; } - ret->u.value = strndup(start, ptr - start); - if (ret->u.value == NULL) { + if (VIR_STRNDUP(ret->u.value, start, ptr - start) < 0) { virReportOOMError(); goto error; } @@ -341,8 +334,7 @@ _string2sexpr(const char *buffer, size_t * end) ptr++; } - ret->u.value = strndup(start, ptr - start); - if (ret->u.value == NULL) { + if (VIR_STRNDUP(ret->u.value, start, ptr - start) < 0) { virReportOOMError(); goto error; } @@ -403,9 +395,7 @@ sexpr_lookup_key(const struct sexpr *sexpr, const char *node) if ((node == NULL) || (sexpr == NULL)) return NULL; - buffer = strdup(node); - - if (buffer == NULL) { + if (VIR_STRDUP(buffer, node) < 0) { virReportOOMError(); return NULL; } @@ -528,8 +518,7 @@ int sexpr_node_copy(const struct sexpr *sexpr, const char *node, char **dst) const char *val = sexpr_node(sexpr, node); if (val && *val) { - *dst = strdup(val); - if (!(*dst)) + if (VIR_STRDUP(*dst, val) < 0) return -1; } else { *dst = NULL; diff --git a/src/util/virsocketaddr.c b/src/util/virsocketaddr.c index d6a0d93..4fac526 100644 --- a/src/util/virsocketaddr.c +++ b/src/util/virsocketaddr.c @@ -272,7 +272,7 @@ virSocketAddrFormatFull(virSocketAddrPtr addr, separator ? separator : ":") < 0) goto no_memory; } else { - if (!(addrstr = strdup("127.0.0.1"))) + if (VIR_STRDUP(addrstr, "127.0.0.1") < 0) goto no_memory; } return addrstr; @@ -293,7 +293,7 @@ virSocketAddrFormatFull(virSocketAddrPtr addr, if (virAsprintf(&addrstr, "%s%s%s", host, separator, port) == -1) goto no_memory; } else { - if (!(addrstr = strdup(host))) + if (VIR_STRDUP(addrstr, host) < 0) goto no_memory; } diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index c7bb85a..04306c1 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -228,8 +228,7 @@ cowGetBackingStore(char **res, return BACKING_STORE_OK; } - *res = strndup((const char*)buf + 4+4, COW_FILENAME_MAXLEN); - if (*res == NULL) { + if (VIR_STRNDUP(*res, (const char*)buf + 4+4, COW_FILENAME_MAXLEN) < 0) { virReportOOMError(); return BACKING_STORE_ERROR; } @@ -440,8 +439,7 @@ vmdk4GetBackingStore(char **res, goto cleanup; } *end = '\0'; - *res = strdup(start); - if (*res == NULL) { + if (VIR_STRDUP(*res, start) < 0) { virReportOOMError(); goto cleanup; } @@ -775,8 +773,7 @@ virStorageFileGetMetadataInternal(const char *path, meta->backingStoreIsFile = false; if (backing != NULL) { - meta->backingStore = strdup(backing); - if (meta->backingStore == NULL) { + if (VIR_STRDUP(meta->backingStore, backing) < 0) { virReportOOMError(); VIR_FREE(backing); goto cleanup; @@ -1096,7 +1093,7 @@ int virStorageFileIsSharedFSType(const char *path, struct statfs sb; int statfs_ret; - if ((dirpath = strdup(path)) == NULL) { + if (VIR_STRDUP(dirpath, path) < 0) { virReportOOMError(); return -1; } diff --git a/src/util/virstring.c b/src/util/virstring.c index 4a55873..2f672bc 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -85,7 +85,7 @@ char **virStringSplit(const char *string, if (VIR_RESIZE_N(tokens, maxtokens, ntokens, 1) < 0) goto no_memory; - if (!(tokens[ntokens] = strndup(remainder, len))) + if (VIR_STRNDUP(tokens[ntokens], remainder, len) < 0) goto no_memory; ntokens++; remainder = tmp + delimlen; @@ -96,7 +96,7 @@ char **virStringSplit(const char *string, if (VIR_RESIZE_N(tokens, maxtokens, ntokens, 1) < 0) goto no_memory; - if (!(tokens[ntokens] = strdup(remainder))) + if (VIR_STRDUP(tokens[ntokens], remainder) < 0) goto no_memory; ntokens++; } @@ -145,7 +145,7 @@ char *virStringJoin(const char **strings, } ret = virBufferContentAndReset(&buf); if (!ret) { - if (!(ret = strdup(""))) { + if (VIR_STRDUP(ret, "") < 0) { virReportOOMError(); return NULL; } diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c index 2efe634..2c6bbcf 100644 --- a/src/util/virsysinfo.c +++ b/src/util/virsysinfo.c @@ -144,16 +144,14 @@ virSysinfoParseSystem(const char *base, virSysinfoDefPtr ret) cur = strchr(cur, ':') + 1; eol = strchr(cur, '\n'); virSkipSpaces(&cur); - if (eol && - ((ret->system_family = strndup(cur, eol - cur)) == NULL)) + if (eol && VIR_STRNDUP(ret->system_family, cur, eol - cur) < 0) goto no_memory; if ((cur = strstr(base, "model")) != NULL) { cur = strchr(cur, ':') + 1; eol = strchr(cur, '\n'); virSkipSpaces(&cur); - if (eol && ((ret->system_serial = strndup(cur, eol - cur)) - == NULL)) + if (eol && VIR_STRNDUP(ret->system_serial, cur, eol - cur) < 0) goto no_memory; } @@ -161,8 +159,7 @@ virSysinfoParseSystem(const char *base, virSysinfoDefPtr ret) cur = strchr(cur, ':') + 1; eol = strchr(cur, '\n'); virSkipSpaces(&cur); - if (eol && ((ret->system_version = strndup(cur, eol - cur)) - == NULL)) + if (eol && VIR_STRNDUP(ret->system_version, cur, eol - cur) < 0) goto no_memory; } @@ -190,18 +187,14 @@ virSysinfoParseProcessor(const char *base, virSysinfoDefPtr ret) processor = &ret->processor[ret->nprocessor - 1]; virSkipSpaces(&cur); - if (eol && - ((processor->processor_socket_destination = strndup - (cur, eol - cur)) == NULL)) + if (eol && VIR_STRNDUP(processor->processor_socket_destination, cur, eol - cur) < 0) goto no_memory; if ((cur = strstr(base, "cpu")) != NULL) { cur = strchr(cur, ':') + 1; eol = strchr(cur, '\n'); virSkipSpaces(&cur); - if (eol && - ((processor->processor_type = strndup(cur, eol - cur)) - == NULL)) + if (eol && VIR_STRNDUP(processor->processor_type, cur, eol - cur) < 0) goto no_memory; } @@ -209,9 +202,7 @@ virSysinfoParseProcessor(const char *base, virSysinfoDefPtr ret) cur = strchr(cur, ':') + 1; eol = strchr(cur, '\n'); virSkipSpaces(&cur); - if (eol && - ((processor->processor_version = strndup(cur, eol - cur)) - == NULL)) + if (eol && VIR_STRNDUP(processor->processor_version, cur, eol - cur) < 0) goto no_memory; } @@ -271,15 +262,14 @@ virSysinfoParseSystem(const char *base, virSysinfoDefPtr ret) eol = strchr(cur, '\n'); virSkipSpaces(&cur); if (eol && - ((ret->system_family = strndup(cur, eol - cur)) == NULL)) + VIR_STRNDUP(ret->system_family, cur, eol - cur) < 0) goto no_memory; if ((cur = strstr(base, "model")) != NULL) { cur = strchr(cur, ':') + 1; eol = strchr(cur, '\n'); virSkipSpaces(&cur); - if (eol && ((ret->system_serial = strndup(cur, eol - cur)) - == NULL)) + if (eol && VIR_STRNDUP(ret->system_serial, cur, eol - cur) < 0) goto no_memory; } @@ -287,8 +277,7 @@ virSysinfoParseSystem(const char *base, virSysinfoDefPtr ret) cur = strchr(cur, ':') + 1; eol = strchr(cur, '\n'); virSkipSpaces(&cur); - if (eol && ((ret->system_version = strndup(cur, eol - cur)) - == NULL)) + if (eol && VIR_STRNDUP(ret->system_version, cur, eol - cur) < 0) goto no_memory; } @@ -313,9 +302,7 @@ virSysinfoParseProcessor(const char *base, virSysinfoDefPtr ret) eol = strchr(base, '\n'); cur = strchr(base, ':') + 1; virSkipSpaces(&cur); - if (eol && - ((processor_type = strndup(cur, eol - cur)) - == NULL)) + if (eol && VIR_STRNDUP(processor_type, cur, eol - cur) < 0) goto no_memory; base = cur; @@ -331,12 +318,11 @@ virSysinfoParseProcessor(const char *base, virSysinfoDefPtr ret) virSkipSpaces(&cur); if (eol && - ((processor->processor_socket_destination = strndup - (cur, eol - cur)) == NULL)) + VIR_STRNDUP(processor->processor_socket_destination, (cur, eol - cur) < 0) goto no_memory; if (processor_type && - !(processor->processor_type = strdup(processor_type))) + VIR_STRNDUP(processor->processor_type, processor_type) < 0) goto no_memory; base = cur; @@ -408,7 +394,7 @@ virSysinfoParseDelimited(const char *base, const char *name, char **value, start += 1; end = strchrnul(start, delim2); virSkipSpaces(&start); - if (!((*value) = strndup(start, end - start))) { + if (VIR_STRNDUP((*value), start, end - start) < 0) { virReportOOMError(); goto error; } @@ -462,7 +448,10 @@ virSysinfoParseProcessor(const char *base, virSysinfoDefPtr ret) goto cleanup; } processor = &ret->processor[ret->nprocessor - 1]; - processor->processor_manufacturer = strdup(manufacturer); + if (VIR_STRDUP(processor->processor_manufacturer, manufacturer) < 0) { + virReportOOMError(); + goto cleanup; + } if (!virSysinfoParseDelimited(procline, "version", &processor->processor_version, '=', ',') || @@ -556,25 +545,25 @@ virSysinfoParseBIOS(const char *base, virSysinfoDefPtr ret) if ((cur = strstr(base, "Vendor: ")) != NULL) { cur += 8; eol = strchr(cur, '\n'); - if ((eol) && ((ret->bios_vendor = strndup(cur, eol - cur)) == NULL)) + if (eol && VIR_STRNDUP(ret->bios_vendor, cur, eol - cur) < 0) goto no_memory; } if ((cur = strstr(base, "Version: ")) != NULL) { cur += 9; eol = strchr(cur, '\n'); - if ((eol) && ((ret->bios_version = strndup(cur, eol - cur)) == NULL)) + if (eol && VIR_STRNDUP(ret->bios_version, cur, eol - cur) < 0) goto no_memory; } if ((cur = strstr(base, "Release Date: ")) != NULL) { cur += 14; eol = strchr(cur, '\n'); - if ((eol) && ((ret->bios_date = strndup(cur, eol - cur)) == NULL)) + if (eol && VIR_STRNDUP(ret->bios_date, cur, eol - cur) < 0) goto no_memory; } if ((cur = strstr(base, "BIOS Revision: ")) != NULL) { cur += 15; eol = strchr(cur, '\n'); - if ((eol) && ((ret->bios_release = strndup(cur, eol - cur)) == NULL)) + if (eol && VIR_STRNDUP(ret->bios_release, cur, eol - cur) < 0) goto no_memory; } @@ -596,44 +585,43 @@ virSysinfoParseSystem(const char *base, virSysinfoDefPtr ret) if ((cur = strstr(base, "Manufacturer: ")) != NULL) { cur += 14; eol = strchr(cur, '\n'); - if ((eol) && - ((ret->system_manufacturer = strndup(cur, eol - cur)) == NULL)) + if (eol && VIR_STRNDUP(ret->system_manufacturer, cur, eol - cur) < 0) goto no_memory; } if ((cur = strstr(base, "Product Name: ")) != NULL) { cur += 14; eol = strchr(cur, '\n'); - if ((eol) && ((ret->system_product = strndup(cur, eol - cur)) == NULL)) + if (eol && VIR_STRNDUP(ret->system_product, cur, eol - cur) < 0) goto no_memory; } if ((cur = strstr(base, "Version: ")) != NULL) { cur += 9; eol = strchr(cur, '\n'); - if ((eol) && ((ret->system_version = strndup(cur, eol - cur)) == NULL)) + if (eol && VIR_STRNDUP(ret->system_version, cur, eol - cur) < 0) goto no_memory; } if ((cur = strstr(base, "Serial Number: ")) != NULL) { cur += 15; eol = strchr(cur, '\n'); - if ((eol) && ((ret->system_serial = strndup(cur, eol - cur)) == NULL)) + if (eol && VIR_STRNDUP(ret->system_serial, cur, eol - cur) < 0) goto no_memory; } if ((cur = strstr(base, "UUID: ")) != NULL) { cur += 6; eol = strchr(cur, '\n'); - if ((eol) && ((ret->system_uuid = strndup(cur, eol - cur)) == NULL)) + if (eol && VIR_STRNDUP(ret->system_uuid, cur, eol - cur) < 0) goto no_memory; } if ((cur = strstr(base, "SKU Number: ")) != NULL) { cur += 12; eol = strchr(cur, '\n'); - if ((eol) && ((ret->system_sku = strndup(cur, eol - cur)) == NULL)) + if (eol && VIR_STRNDUP(ret->system_sku, cur, eol - cur) < 0) goto no_memory; } if ((cur = strstr(base, "Family: ")) != NULL) { cur += 8; eol = strchr(cur, '\n'); - if ((eol) && ((ret->system_family = strndup(cur, eol - cur)) == NULL)) + if (eol && VIR_STRNDUP(ret->system_family, cur, eol - cur) < 0) goto no_memory; } @@ -663,98 +651,88 @@ virSysinfoParseProcessor(const char *base, virSysinfoDefPtr ret) cur += 20; eol = strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if ((eol) && - ((processor->processor_socket_destination - = strndup(cur, eol - cur)) == NULL)) + if (eol && + VIR_STRNDUP(processor->processor_socket_destination, cur, eol - cur) < 0) goto no_memory; } if ((cur = strstr(base, "Type: ")) != NULL) { cur += 6; eol = strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if ((eol) && - ((processor->processor_type = strndup(cur, eol - cur)) == NULL)) + if (eol && + VIR_STRNDUP(processor->processor_type, cur, eol - cur) < 0) goto no_memory; } if ((cur = strstr(base, "Family: ")) != NULL) { cur += 8; eol = strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if ((eol) && - ((processor->processor_family = strndup(cur, - eol - cur)) == NULL)) + if (eol && + VIR_STRNDUP(processor->processor_family, cur, eol - cur) < 0) goto no_memory; } if ((cur = strstr(base, "Manufacturer: ")) != NULL) { cur += 14; eol = strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if ((eol) && - ((processor->processor_manufacturer - = strndup(cur, eol - cur)) == NULL)) + if (eol && + VIR_STRNDUP(processor->processor_manufacturer, cur, eol - cur) < 0) goto no_memory; } if ((cur = strstr(base, "Signature: ")) != NULL) { cur += 11; eol = strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if ((eol) && - ((processor->processor_signature - = strndup(cur, eol - cur)) == NULL)) + if (eol && + VIR_STRNDUP(processor->processor_signature, cur, eol - cur) < 0) goto no_memory; } if ((cur = strstr(base, "Version: ")) != NULL) { cur += 9; eol = strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if ((eol) && - ((processor->processor_version = strndup(cur, - eol - cur)) == NULL)) + if (eol && + VIR_STRNDUP(processor->processor_version, cur, eol - cur) < 0) goto no_memory; } if ((cur = strstr(base, "External Clock: ")) != NULL) { cur += 16; eol = strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if ((eol) && - ((processor->processor_external_clock - = strndup(cur, eol - cur)) == NULL)) + if (eol && + VIR_STRNDUP(processor->processor_external_clock, cur, eol - cur) < 0) goto no_memory; } if ((cur = strstr(base, "Max Speed: ")) != NULL) { cur += 11; eol = strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if ((eol) && - ((processor->processor_max_speed - = strndup(cur, eol - cur)) == NULL)) + if (eol && + VIR_STRNDUP(processor->processor_max_speed, cur, eol - cur) < 0) goto no_memory; } if ((cur = strstr(base, "Status: ")) != NULL) { cur += 8; eol = strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if ((eol) && - ((processor->processor_status = strndup(cur, - eol - cur)) == NULL)) + if (eol && + VIR_STRNDUP(processor->processor_status, cur, eol - cur) < 0) goto no_memory; } if ((cur = strstr(base, "Serial Number: ")) != NULL) { cur += 15; eol = strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if ((eol) && - ((processor->processor_serial_number - = strndup(cur, eol - cur)) == NULL)) + if (eol && + VIR_STRNDUP(processor->processor_serial_number, cur, eol - cur) < 0) goto no_memory; } if ((cur = strstr(base, "Part Number: ")) != NULL) { cur += 13; eol = strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if ((eol) && - ((processor->processor_part_number - = strndup(cur, eol - cur)) == NULL)) + if (eol && + VIR_STRNDUP(processor->processor_part_number, cur, eol - cur) < 0) goto no_memory; } @@ -790,86 +768,80 @@ virSysinfoParseMemory(const char *base, virSysinfoDefPtr ret) goto next; virSkipSpacesBackwards(cur, &eol); - if ((eol) && - ((memory->memory_size = strndup(cur, eol - cur)) == NULL)) + if (eol && + VIR_STRNDUP(memory->memory_size, cur, eol - cur) < 0) goto no_memory; } if ((cur = strstr(base, "Form Factor: ")) != NULL) { cur += 13; eol = strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if ((eol) && - ((memory->memory_form_factor = strndup(cur, - eol - cur)) == NULL)) + if (eol && + VIR_STRNDUP(memory->memory_form_factor, cur, eol - cur) < 0) goto no_memory; } if ((cur = strstr(base, "Locator: ")) != NULL) { cur += 9; eol = strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if ((eol) && - ((memory->memory_locator = strndup(cur, eol - cur)) == NULL)) + if (eol && + VIR_STRNDUP(memory->memory_locator, cur, eol - cur) < 0) goto no_memory; } if ((cur = strstr(base, "Bank Locator: ")) != NULL) { cur += 14; eol = strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if ((eol) && - ((memory->memory_bank_locator = strndup(cur, - eol - cur)) == NULL)) + if (eol && + VIR_STRNDUP(memory->memory_bank_locator, cur, eol - cur) < 0) goto no_memory; } if ((cur = strstr(base, "Type: ")) != NULL) { cur += 6; eol = strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if ((eol) && - ((memory->memory_type = strndup(cur, eol - cur)) == NULL)) + if (eol && + VIR_STRNDUP(memory->memory_type, cur, eol - cur) < 0) goto no_memory; } if ((cur = strstr(base, "Type Detail: ")) != NULL) { cur += 13; eol = strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if ((eol) && - ((memory->memory_type_detail = strndup(cur, - eol - cur)) == NULL)) + if (eol && + VIR_STRNDUP(memory->memory_type_detail, cur, eol - cur) < 0) goto no_memory; } if ((cur = strstr(base, "Speed: ")) != NULL) { cur += 7; eol = strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if ((eol) && - ((memory->memory_speed = strndup(cur, eol - cur)) == NULL)) + if (eol && + VIR_STRNDUP(memory->memory_speed, cur, eol - cur) < 0) goto no_memory; } if ((cur = strstr(base, "Manufacturer: ")) != NULL) { cur += 14; eol = strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if ((eol) && - ((memory->memory_manufacturer = strndup(cur, - eol - cur)) == NULL)) + if (eol && + VIR_STRNDUP(memory->memory_manufacturer, cur, eol - cur) < 0) goto no_memory; } if ((cur = strstr(base, "Serial Number: ")) != NULL) { cur += 15; eol = strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if ((eol) && - ((memory->memory_serial_number = strndup(cur, - eol - cur)) == NULL)) + if (eol && + VIR_STRNDUP(memory->memory_serial_number, cur, eol - cur) < 0) goto no_memory; } if ((cur = strstr(base, "Part Number: ")) != NULL) { cur += 13; eol = strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); - if ((eol) && - ((memory->memory_part_number = strndup(cur, - eol - cur)) == NULL)) + if (eol && + VIR_STRNDUP(memory->memory_part_number, cur, eol - cur) < 0) goto no_memory; } diff --git a/src/util/virtypedparam.c b/src/util/virtypedparam.c index a9f8a33..cc352ff 100644 --- a/src/util/virtypedparam.c +++ b/src/util/virtypedparam.c @@ -150,9 +150,7 @@ virTypedParameterAssign(virTypedParameterPtr param, const char *name, break; case VIR_TYPED_PARAM_STRING: param->value.s = va_arg(ap, char *); - if (!param->value.s) - param->value.s = strdup(""); - if (!param->value.s) { + if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0) { virReportOOMError(); goto cleanup; } @@ -248,7 +246,7 @@ virTypedParameterAssignFromStr(virTypedParameterPtr param, const char *name, } break; case VIR_TYPED_PARAM_STRING: - if (!(param->value.s = strdup(val))) { + if (VIR_STRDUP(param->value.s, val) < 0) { virReportOOMError(); goto cleanup; } @@ -913,7 +911,7 @@ virTypedParamsAddString(virTypedParameterPtr *params, } *maxparams = max; - if (value && !(str = strdup(value))) { + if (value && VIR_STRDUP(str, value) < 0) { virReportOOMError(); goto error; } diff --git a/src/util/viruri.c b/src/util/viruri.c index 2a75425..ba46851 100644 --- a/src/util/viruri.c +++ b/src/util/viruri.c @@ -37,9 +37,9 @@ virURIParamAppend(virURIPtr uri, char *pname = NULL; char *pvalue = NULL; - if (!(pname = strdup(name))) + if (VIR_STRDUP(pname, name) < 0) goto no_memory; - if (!(pvalue = strdup(value))) + if (VIR_STRDUP(pvalue, value) < 0) goto no_memory; if (VIR_RESIZE_N(uri->params, uri->paramsAlloc, uri->paramsCount, 1) < 0) @@ -171,29 +171,29 @@ virURIParse(const char *uri) goto no_memory; if (xmluri->scheme && - !(ret->scheme = strdup(xmluri->scheme))) + VIR_STRDUP(ret->scheme, xmluri->scheme) < 0) goto no_memory; if (xmluri->server && - !(ret->server = strdup(xmluri->server))) + VIR_STRDUP(ret->server, xmluri->server) < 0) goto no_memory; ret->port = xmluri->port; if (xmluri->path && - !(ret->path = strdup(xmluri->path))) + VIR_STRDUP(ret->path, xmluri->path) < 0) goto no_memory; #ifdef HAVE_XMLURI_QUERY_RAW if (xmluri->query_raw && - !(ret->query = strdup(xmluri->query_raw))) + VIR_STRDUP(ret->query, xmluri->query_raw) < 0) goto no_memory; #else if (xmluri->query && - !(ret->query = strdup(xmluri->query))) + VIR_STRDUP(ret->query, xmluri->query) < 0) goto no_memory; #endif if (xmluri->fragment && - !(ret->fragment = strdup(xmluri->fragment))) + VIR_STRDUP(ret->fragment, xmluri->fragment) < 0) goto no_memory; if (xmluri->user && - !(ret->user = strdup(xmluri->user))) + VIR_STRDUP(ret->user, xmluri->user) < 0) goto no_memory; /* First check: does it even make sense to jump inside */ diff --git a/src/util/virutil.c b/src/util/virutil.c index dc14c15..5b3c1f3 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -547,7 +547,7 @@ virFileResolveLinkHelper(const char *linkpath, return -1; if (!S_ISLNK(st.st_mode)) { - if (!(*resultpath = strdup(linkpath))) + if (VIR_STRDUP(*resultpath, linkpath) < 0) return -1; return 0; } @@ -622,9 +622,10 @@ char *virFindFileInPath(const char *file) * copy of that path, after validating that it is executable */ if (IS_ABSOLUTE_FILE_NAME(file)) { - if (virFileIsExecutable(file)) - return strdup(file); - else + if (virFileIsExecutable(file)) { + ignore_value(VIR_STRDUP(path, file)); + return path; + } else return NULL; } @@ -640,7 +641,7 @@ char *virFindFileInPath(const char *file) /* copy PATH env so we can tweak it */ path = getenv("PATH"); - if (path == NULL || (path = strdup(path)) == NULL) + if (path == NULL || VIR_STRDUP(path, path) < 0) return NULL; /* for each path segment, append the file to search for and test for @@ -1295,7 +1296,7 @@ virFileMakePathWithMode(const char *path, int ret = -1; char *tmp; - if ((tmp = strdup(path)) == NULL) + if (VIR_STRDUP(tmp, path) < 0) goto cleanup; ret = virFileMakePathHelper(tmp, mode); @@ -1502,7 +1503,7 @@ int virFileAbsPath(const char *path, char **abspath) char *buf; if (path[0] == '/') { - if (!(*abspath = strdup(path))) + if (VIR_STRDUP(*abspath, path) < 0) return -1; } else { buf = getcwd(NULL, 0); @@ -1527,8 +1528,7 @@ virFileSanitizePath(const char *path) char *cleanpath; int idx = 0; - cleanpath = strdup(path); - if (!cleanpath) { + if (VIR_STRDUP(cleanpath, path) < 0) { virReportOOMError(); return NULL; } @@ -1962,7 +1962,7 @@ char *virGetHostname(virConnectPtr conn ATTRIBUTE_UNUSED) * string as-is; it's up to callers to check whether "localhost" * is allowed. */ - result = strdup(hostname); + r = VIR_STRDUP(result, hostname); goto check_and_return; } @@ -1977,7 +1977,7 @@ char *virGetHostname(virConnectPtr conn ATTRIBUTE_UNUSED) if (r != 0) { VIR_WARN("getaddrinfo failed for '%s': %s", hostname, gai_strerror(r)); - result = strdup(hostname); + r = VIR_STRDUP(result, hostname); goto check_and_return; } @@ -1990,15 +1990,15 @@ char *virGetHostname(virConnectPtr conn ATTRIBUTE_UNUSED) * localhost. Ignore the canonicalized name and just return the * original hostname */ - result = strdup(hostname); + r = VIR_STRDUP(result, hostname); else /* Caller frees this string. */ - result = strdup(info->ai_canonname); + r = VIR_STRDUP(result, info->ai_canonname); freeaddrinfo(info); check_and_return: - if (result == NULL) + if (r < 0) virReportOOMError(); return result; } @@ -2051,14 +2051,10 @@ static char *virGetUserEnt(uid_t uid, return NULL; } - if (field == VIR_USER_ENT_DIRECTORY) - ret = strdup(pw->pw_dir); - else - ret = strdup(pw->pw_name); - - VIR_FREE(strbuf); - if (!ret) + if (VIR_STRDUP(ret, field == VIR_USER_ENT_DIRECTORY ? + pw->pw_dir : pw->pw_name) < 0) virReportOOMError(); + VIR_FREE(strbuf); return ret; } @@ -2104,12 +2100,10 @@ static char *virGetGroupEnt(gid_t gid) return NULL; } - ret = strdup(gr->gr_name); - - VIR_FREE(strbuf); - if (!ret) + if (VIR_STRDUP(ret, gr->gr_name) < 0) virReportOOMError(); + VIR_FREE(strbuf); return ret; } @@ -2444,7 +2438,7 @@ virGetWin32SpecialFolder(int csidl, char **path) if (SHGetSpecialFolderLocation(NULL, csidl, &pidl) == S_OK) { if (SHGetPathFromIDList(pidl, buf)) { - if (!(*path = strdup(buf))) { + if (VIR_STRDUP(*path, buf) < 0) { virReportOOMError(); ret = -1; } @@ -2478,7 +2472,7 @@ virGetWin32DirectoryRoot(char **path) strcpy(windowsdir, "C:\\"); } - if (!(*path = strdup(windowsdir))) { + if (VIR_STRDUP(*path, windowsdir) < 0) { virReportOOMError(); ret = -1; } @@ -2517,7 +2511,7 @@ virGetUserDirectory(void) dir = getenv("USERPROFILE"); if (dir) { - if (!(ret = strdup(dir))) { + if (VIR_STRDUP(ret, dir) < 0) { virReportOOMError(); return NULL; } @@ -2809,7 +2803,8 @@ char *virFileFindMountPoint(const char *type) while (getmntent_r(f, &mb, mntbuf, sizeof(mntbuf))) { if (STREQ(mb.mnt_type, type)) { - ret = strdup(mb.mnt_dir); + if (VIR_STRDUP(ret, mb.mnt_dir) < 0) + virReportOOMError(); goto cleanup; } } @@ -3120,7 +3115,7 @@ virReadFCHost(const char *sysfs_prefix, else p = buf; - if (!(*result = strndup(p, sizeof(buf)))) { + if (VIR_STRNDUP(*result, p, sizeof(buf)) < 0) { virReportOOMError(); goto cleanup; } @@ -3347,7 +3342,7 @@ virGetFCHostNameByWWN(const char *sysfs_prefix, continue; } - ret = strdup(entry->d_name); + ignore_value(VIR_STRDUP(ret, entry->d_name)); break; } @@ -3432,7 +3427,7 @@ virFindFCHostCapableVport(const char *sysfs_prefix) if ((strlen(max_vports) >= strlen(vports)) || ((strlen(max_vports) == strlen(vports)) && strcmp(max_vports, vports) > 0)) { - ret = strdup(entry->d_name); + ignore_value(VIR_STRDUP(ret, entry->d_name)); goto cleanup; } diff --git a/src/util/virxml.c b/src/util/virxml.c index 26120b6..0d8584d 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -87,11 +87,9 @@ virXPathString(const char *xpath, xmlXPathFreeObject(obj); return NULL; } - ret = strdup((char *) obj->stringval); - xmlXPathFreeObject(obj); - if (ret == NULL) { + if (VIR_STRDUP(ret, (char *) obj->stringval) < 0) virReportOOMError(); - } + xmlXPathFreeObject(obj); return ret; } -- 1.8.1.5

--- src/vbox/vbox_XPCOMCGlue.c | 4 +- src/vbox/vbox_tmpl.c | 190 +++++++++++++++++++++++---------------------- 2 files changed, 98 insertions(+), 96 deletions(-) diff --git a/src/vbox/vbox_XPCOMCGlue.c b/src/vbox/vbox_XPCOMCGlue.c index e0b606f..c5500b9 100644 --- a/src/vbox/vbox_XPCOMCGlue.c +++ b/src/vbox/vbox_XPCOMCGlue.c @@ -105,9 +105,7 @@ tryLoadOne(const char *dir, bool setAppHome, bool ignoreMissing, return -1; } } else { - name = strdup(DYNLIB_NAME); - - if (name == NULL) { + if (VIR_STRDUP(name, DYNLIB_NAME) < 0) { virReportOOMError(); return -1; } diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 43ddac8..0e80194 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -1840,9 +1840,9 @@ 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 = strdup("hvm"); + char *osType; - if (osType == NULL) + if (VIR_STRDUP(osType, "hvm") < 0) virReportOOMError(); return osType; @@ -2290,7 +2290,7 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) { def->virtType = VIR_DOMAIN_VIRT_VBOX; def->id = dom->id; memcpy(def->uuid, dom->uuid, VIR_UUID_BUFLEN); - def->name = strdup(dom->name); + ignore_value(VIR_STRDUP(def->name, dom->name)); machine->vtbl->GetMemorySize(machine, &memorySize); def->mem.cur_balloon = memorySize * 1024; @@ -2325,7 +2325,7 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) { /* Skip cpumasklen, cpumask, onReboot, onPoweroff, onCrash */ - def->os.type = strdup("hvm"); + ignore_value(VIR_STRDUP(def->os.type, "hvm")); def->os.arch = virArchFromHost(); @@ -2460,9 +2460,8 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) { if (STREQ(valueTypeUtf8, "sdl")) { sdlPresent = 1; - if (valueDisplayUtf8) - sdlDisplay = strdup(valueDisplayUtf8); - if (sdlDisplay == NULL) { + if (valueDisplayUtf8 && + VIR_STRDUP(sdlDisplay, valueDisplayUtf8) < 0) { virReportOOMError(); /* just don't go to cleanup yet as it is ok to have * sdlDisplay as NULL and we check it below if it @@ -2474,9 +2473,8 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) { if (STREQ(valueTypeUtf8, "gui")) { guiPresent = 1; - if (valueDisplayUtf8) - guiDisplay = strdup(valueDisplayUtf8); - if (guiDisplay == NULL) { + if (valueDisplayUtf8 && + VIR_STRDUP(guiDisplay, valueDisplayUtf8) < 0) { virReportOOMError(); /* just don't go to cleanup yet as it is ok to have * guiDisplay as NULL and we check it below if it @@ -2513,8 +2511,7 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) { def->graphics[def->ngraphics]->type = VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP; tmp = getenv("DISPLAY"); if (tmp != NULL) { - def->graphics[def->ngraphics]->data.desktop.display = strdup(tmp); - if (def->graphics[def->ngraphics]->data.desktop.display == NULL) { + if (VIR_STRDUP(def->graphics[def->ngraphics]->data.desktop.display, tmp) < 0) { virReportOOMError(); /* just don't go to cleanup yet as it is ok to have * display as NULL @@ -2649,8 +2646,9 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) { if (hddType == HardDiskType_Immutable) def->disks[hddNum]->readonly = true; - def->disks[hddNum]->src = strdup(hddlocation); - def->disks[hddNum]->dst = strdup("hda"); + if (VIR_STRDUP(def->disks[hddNum]->src, hddlocation) < 0 || + VIR_STRDUP(def->disks[hddNum]->dst, "hda") < 0) + virReportOOMError(); hddNum++; VBOX_UTF8_FREE(hddlocation); @@ -2670,8 +2668,9 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) { if (hddType == HardDiskType_Immutable) def->disks[hddNum]->readonly = true; - def->disks[hddNum]->src = strdup(hddlocation); - def->disks[hddNum]->dst = strdup("hdb"); + if (VIR_STRDUP(def->disks[hddNum]->src, hddlocation) < 0 || + VIR_STRDUP(def->disks[hddNum]->dst, "hdb") < 0) + virReportOOMError(); hddNum++; VBOX_UTF8_FREE(hddlocation); @@ -2691,8 +2690,9 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) { if (hddType == HardDiskType_Immutable) def->disks[hddNum]->readonly = true; - def->disks[hddNum]->src = strdup(hddlocation); - def->disks[hddNum]->dst = strdup("hdd"); + if (VIR_STRDUP(def->disks[hddNum]->src, hddlocation) < 0 || + VIR_STRDUP(def->disks[hddNum]->dst, "hdd") < 0) + virReportOOMError(); hddNum++; VBOX_UTF8_FREE(hddlocation); @@ -2780,7 +2780,8 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) { medium->vtbl->GetLocation(medium, &mediumLocUtf16); VBOX_UTF16_TO_UTF8(mediumLocUtf16, &mediumLocUtf8); VBOX_UTF16_FREE(mediumLocUtf16); - def->disks[diskCount]->src = strdup(mediumLocUtf8); + if (VIR_STRDUP(def->disks[diskCount]->src, mediumLocUtf8) < 0) + virReportOOMError(); VBOX_UTF8_FREE(mediumLocUtf8); if (!(def->disks[diskCount]->src)) { @@ -2884,7 +2885,8 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) { sharedFolder->vtbl->GetHostPath(sharedFolder, &hostPathUtf16); VBOX_UTF16_TO_UTF8(hostPathUtf16, &hostPath); - def->fss[i]->src = strdup(hostPath); + if (VIR_STRDUP(def->fss[i]->src, hostPath) < 0) + virReportOOMError(); VBOX_UTF8_FREE(hostPath); VBOX_UTF16_FREE(hostPathUtf16); @@ -2895,7 +2897,8 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) { sharedFolder->vtbl->GetName(sharedFolder, &nameUtf16); VBOX_UTF16_TO_UTF8(nameUtf16, &name); - def->fss[i]->dst = strdup(name); + if (VIR_STRDUP(def->fss[i]->dst, name) < 0) + virReportOOMError(); VBOX_UTF8_FREE(name); VBOX_UTF16_FREE(nameUtf16); @@ -2957,6 +2960,7 @@ sharedFoldersCleanup: PRUnichar *MACAddressUtf16 = NULL; char *MACAddress = NULL; char macaddr[VIR_MAC_STRING_BUFLEN] = {0}; + int strdupRet = 0; adapter->vtbl->GetAttachmentType(adapter, &attachmentType); if (attachmentType == NetworkAttachmentType_NAT) { @@ -2976,8 +2980,8 @@ sharedFoldersCleanup: #endif /* VBOX_API_VERSION >= 4001 */ VBOX_UTF16_TO_UTF8(hostIntUtf16, &hostInt); - def->nets[netAdpIncCnt]->data.bridge.brname = strdup(hostInt); - + if (VIR_STRDUP(def->nets[netAdpIncCnt]->data.bridge.brname, hostInt) < 0) + virReportOOMError(); VBOX_UTF8_FREE(hostInt); VBOX_UTF16_FREE(hostIntUtf16); @@ -2990,8 +2994,8 @@ sharedFoldersCleanup: adapter->vtbl->GetInternalNetwork(adapter, &intNetUtf16); VBOX_UTF16_TO_UTF8(intNetUtf16, &intNet); - def->nets[netAdpIncCnt]->data.internal.name = strdup(intNet); - + if (VIR_STRDUP(def->nets[netAdpIncCnt]->data.internal.name, intNet) < 0) + virReportOOMError(); VBOX_UTF8_FREE(intNet); VBOX_UTF16_FREE(intNetUtf16); @@ -3008,8 +3012,8 @@ sharedFoldersCleanup: #endif /* VBOX_API_VERSION >= 4001 */ VBOX_UTF16_TO_UTF8(hostIntUtf16, &hostInt); - def->nets[netAdpIncCnt]->data.network.name = strdup(hostInt); - + if (VIR_STRDUP(def->nets[netAdpIncCnt]->data.network.name, hostInt) < 0) + virReportOOMError(); VBOX_UTF8_FREE(hostInt); VBOX_UTF16_FREE(hostIntUtf16); @@ -3022,21 +3026,24 @@ sharedFoldersCleanup: adapter->vtbl->GetAdapterType(adapter, &adapterType); if (adapterType == NetworkAdapterType_Am79C970A) { - def->nets[netAdpIncCnt]->model = strdup("Am79C970A"); + strdupRet = VIR_STRDUP(def->nets[netAdpIncCnt]->model, "Am79C970A"); } else if (adapterType == NetworkAdapterType_Am79C973) { - def->nets[netAdpIncCnt]->model = strdup("Am79C973"); + strdupRet = VIR_STRDUP(def->nets[netAdpIncCnt]->model, "Am79C973"); } else if (adapterType == NetworkAdapterType_I82540EM) { - def->nets[netAdpIncCnt]->model = strdup("82540EM"); + strdupRet = VIR_STRDUP(def->nets[netAdpIncCnt]->model, "82540EM"); } else if (adapterType == NetworkAdapterType_I82545EM) { - def->nets[netAdpIncCnt]->model = strdup("82545EM"); + strdupRet = VIR_STRDUP(def->nets[netAdpIncCnt]->model, "82545EM"); } else if (adapterType == NetworkAdapterType_I82543GC) { - def->nets[netAdpIncCnt]->model = strdup("82543GC"); + strdupRet = VIR_STRDUP(def->nets[netAdpIncCnt]->model, "82543GC"); #if VBOX_API_VERSION >= 3001 } else if (adapterType == NetworkAdapterType_Virtio) { - def->nets[netAdpIncCnt]->model = strdup("virtio"); + strdupRet = VIR_STRDUP(def->nets[netAdpIncCnt]->model, "virtio"); #endif /* VBOX_API_VERSION >= 3001 */ } + if (strdupRet < 0) + virReportOOMError(); + adapter->vtbl->GetMACAddress(adapter, &MACAddressUtf16); VBOX_UTF16_TO_UTF8(MACAddressUtf16, &MACAddress); snprintf(macaddr, VIR_MAC_STRING_BUFLEN, @@ -3120,8 +3127,9 @@ sharedFoldersCleanup: def->disks[def->ndisks - 1]->bus = VIR_DOMAIN_DISK_BUS_IDE; def->disks[def->ndisks - 1]->type = VIR_DOMAIN_DISK_TYPE_FILE; def->disks[def->ndisks - 1]->readonly = true; - def->disks[def->ndisks - 1]->src = strdup(location); - def->disks[def->ndisks - 1]->dst = strdup("hdc"); + if (VIR_STRDUP(def->disks[def->ndisks - 1]->src, location) < 0 || + VIR_STRDUP(def->disks[def->ndisks - 1]->dst, "hdc") < 0) + virReportOOMError(); } else { def->ndisks--; virReportOOMError(); @@ -3167,8 +3175,9 @@ sharedFoldersCleanup: def->disks[def->ndisks - 1]->bus = VIR_DOMAIN_DISK_BUS_FDC; def->disks[def->ndisks - 1]->type = VIR_DOMAIN_DISK_TYPE_FILE; def->disks[def->ndisks - 1]->readonly = false; - def->disks[def->ndisks - 1]->src = strdup(location); - def->disks[def->ndisks - 1]->dst = strdup("fda"); + if (VIR_STRDUP(def->disks[def->ndisks - 1]->src, location) < 0 || + VIR_STRDUP(def->disks[def->ndisks - 1]->dst, "fda") < 0) + virReportOOMError(); } else { def->ndisks--; virReportOOMError(); @@ -3261,7 +3270,8 @@ sharedFoldersCleanup: if (pathUtf16) { VBOX_UTF16_TO_UTF8(pathUtf16, &path); - def->serials[serialPortIncCount]->source.data.file.path = strdup(path); + if (VIR_STRDUP(def->serials[serialPortIncCount]->source.data.file.path, path) < 0) + virReportOOMError(); } serialPortIncCount++; @@ -3331,7 +3341,8 @@ sharedFoldersCleanup: parallelPort->vtbl->GetPath(parallelPort, &pathUtf16); VBOX_UTF16_TO_UTF8(pathUtf16, &path); - def->parallels[parallelPortIncCount]->source.data.file.path = strdup(path); + if (VIR_STRDUP(def->parallels[parallelPortIncCount]->source.data.file.path, path) < 0) + virReportOOMError(); parallelPortIncCount++; @@ -3478,7 +3489,8 @@ static int vboxConnectListDefinedDomains(virConnectPtr conn, char ** const names (state > MachineState_LastOnline)) { machine->vtbl->GetName(machine, &machineNameUtf16); VBOX_UTF16_TO_UTF8(machineNameUtf16, &machineName); - names[j] = strdup(machineName); + if (VIR_STRDUP(names[j], machineName) < 0) + virReportOOMError(); VBOX_UTF16_FREE(machineNameUtf16); VBOX_UTF8_FREE(machineName); if (!names[j]) { @@ -3585,8 +3597,7 @@ vboxStartMachine(virDomainPtr dom, int i, IMachine *machine, if (STREQ(valueTypeUtf8, "sdl")) { sdlPresent = 1; if (valueDisplayUtf8) { - sdlDisplay = strdup(valueDisplayUtf8); - if (sdlDisplay == NULL) { + if (VIR_STRDUP(sdlDisplay, valueDisplayUtf8) < 0) { virReportOOMError(); /* just don't go to cleanup yet as it is ok to have * sdlDisplay as NULL and we check it below if it @@ -3599,8 +3610,7 @@ vboxStartMachine(virDomainPtr dom, int i, IMachine *machine, if (STREQ(valueTypeUtf8, "gui")) { guiPresent = 1; if (valueDisplayUtf8) { - guiDisplay = strdup(valueDisplayUtf8); - if (guiDisplay == NULL) { + if (VIR_STRDUP(guiDisplay, valueDisplayUtf8) < 0) { virReportOOMError(); /* just don't go to cleanup yet as it is ok to have * guiDisplay as NULL and we check it below if it @@ -3982,7 +3992,10 @@ vboxAttachDrives(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine) PRInt32 device = 0; PRUnichar *hddcnameUtf16 = NULL; - char *hddcname = strdup("IDE"); + char *hddcname; + + if (VIR_STRDUP(hddcname, "IDE") < 0) + virReportOOMError(); VBOX_UTF8_TO_UTF16(hddcname, &hddcnameUtf16); VIR_FREE(hddcname); @@ -4802,8 +4815,7 @@ vboxAttachDisplay(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine) (guiPresent == 0)) { guiPresent = 1; if (def->graphics[i]->data.desktop.display) { - guiDisplay = strdup(def->graphics[i]->data.desktop.display); - if (guiDisplay == NULL) { + if (VIR_STRDUP(guiDisplay, def->graphics[i]->data.desktop.display) < 0) { virReportOOMError(); /* just don't go to cleanup yet as it is ok to have * guiDisplay as NULL and we check it below if it @@ -4817,8 +4829,7 @@ vboxAttachDisplay(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine) (sdlPresent == 0)) { sdlPresent = 1; if (def->graphics[i]->data.sdl.display) { - sdlDisplay = strdup(def->graphics[i]->data.sdl.display); - if (sdlDisplay == NULL) { + if (VIR_STRDUP(sdlDisplay, def->graphics[i]->data.sdl.display) < 0) { virReportOOMError(); /* just don't go to cleanup yet as it is ok to have * sdlDisplay as NULL and we check it below if it @@ -5226,7 +5237,10 @@ vboxDomainUndefineFlags(virDomainPtr dom, unsigned int flags) { PRUnichar *hddcnameUtf16 = NULL; - char *hddcname = strdup("IDE"); + char *hddcname; + + if (VIR_STRDUP(hddcname, "IDE") < 0) + virReportOOMError(); VBOX_UTF8_TO_UTF16(hddcname, &hddcnameUtf16); VIR_FREE(hddcname); @@ -5385,9 +5399,7 @@ static int vboxDomainAttachDeviceImpl(virDomainPtr dom, return ret; } - def->os.type = strdup("hvm"); - - if (def->os.type == NULL) { + if (VIR_STRDUP(def->os.type, "hvm") < 0) { virReportOOMError(); goto cleanup; } @@ -5620,9 +5632,7 @@ static int vboxDomainDetachDevice(virDomainPtr dom, const char *xml) { return ret; } - def->os.type = strdup("hvm"); - - if (def->os.type == NULL) { + if (VIR_STRDUP(def->os.type, "hvm") < 0) { virReportOOMError(); goto cleanup; } @@ -6051,7 +6061,7 @@ vboxDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot, goto cleanup; if (VIR_ALLOC(def) < 0 - || !(def->name = strdup(snapshot->name))) + || VIR_STRDUP(def->name, snapshot->name) < 0) goto no_memory; rc = snap->vtbl->GetDescription(snap, &str16); @@ -6064,10 +6074,12 @@ vboxDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot, if (str16) { VBOX_UTF16_TO_UTF8(str16, &str8); VBOX_UTF16_FREE(str16); - def->description = strdup(str8); - VBOX_UTF8_FREE(str8); - if (!def->description) + if (VIR_STRDUP(def->description, str8) < 0) { + virReportOOMError(); + VBOX_UTF8_FREE(str8); goto no_memory; + } + VBOX_UTF8_FREE(str8); } rc = snap->vtbl->GetTimeStamp(snap, ×tamp); @@ -6097,10 +6109,12 @@ vboxDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot, } VBOX_UTF16_TO_UTF8(str16, &str8); VBOX_UTF16_FREE(str16); - def->parent = strdup(str8); - VBOX_UTF8_FREE(str8); - if (!def->parent) + if (VIR_STRDUP(def->parent, str8) < 0) { + virReportOOMError(); + VBOX_UTF8_FREE(str8); goto no_memory; + } + VBOX_UTF8_FREE(str8); } rc = snap->vtbl->GetOnline(snap, &online); @@ -6247,12 +6261,12 @@ vboxDomainSnapshotListNames(virDomainPtr dom, } VBOX_UTF16_TO_UTF8(nameUtf16, &name); VBOX_UTF16_FREE(nameUtf16); - names[i] = strdup(name); - VBOX_UTF8_FREE(name); - if (!names[i]) { + if (VIR_STRDUP(names[i], name) < 0) { virReportOOMError(); + VBOX_UTF8_FREE(name); goto cleanup; } + VBOX_UTF8_FREE(name); } if (count <= nameslen) @@ -7529,12 +7543,10 @@ static int vboxConnectListNetworks(virConnectPtr conn, char **const names, int n VBOX_UTF16_TO_UTF8(nameUtf16, &nameUtf8); VIR_DEBUG("nnames[%d]: %s", ret, nameUtf8); - names[ret] = strdup(nameUtf8); - if (names[ret] == NULL) { + if (VIR_STRDUP(names[ret], nameUtf8) < 0) virReportOOMError(); - } else { + else ret++; - } VBOX_UTF8_FREE(nameUtf8); VBOX_UTF16_FREE(nameUtf16); @@ -7611,12 +7623,10 @@ static int vboxConnectListDefinedNetworks(virConnectPtr conn, char **const names VBOX_UTF16_TO_UTF8(nameUtf16, &nameUtf8); VIR_DEBUG("nnames[%d]: %s", ret, nameUtf8); - names[ret] = strdup(nameUtf8); - if (names[ret] == NULL) { + if (VIR_STRDUP(names[ret], nameUtf8) < 0) virReportOOMError(); - } else { + else ret++; - } VBOX_UTF8_FREE(nameUtf8); VBOX_UTF16_FREE(nameUtf16); @@ -8117,8 +8127,7 @@ static char *vboxNetworkGetXMLDesc(virNetworkPtr network, networkInterface->vtbl->GetInterfaceType(networkInterface, &interfaceType); if (interfaceType == HostNetworkInterfaceType_HostOnly) { - def->name = strdup(network->name); - if (def->name != NULL) { + if (VIR_STRDUP(def->name, network->name) == 0) { PRUnichar *networkNameUtf16 = NULL; IDHCPServer *dhcpServer = NULL; vboxIID vboxnet0IID = VBOX_IID_INITIALIZER; @@ -8175,8 +8184,7 @@ static char *vboxNetworkGetXMLDesc(virNetworkPtr network, ipdef->nhosts = 1; if (VIR_ALLOC_N(ipdef->hosts, ipdef->nhosts) >=0) { - ipdef->hosts[0].name = strdup(network->name); - if (ipdef->hosts[0].name == NULL) { + if (VIR_STRDUP(ipdef->hosts[0].name, network->name) < 0) { VIR_FREE(ipdef->hosts); ipdef->nhosts = 0; virReportOOMError(); @@ -8297,12 +8305,10 @@ static int vboxConnectListStoragePools(virConnectPtr conn ATTRIBUTE_UNUSED, int numActive = 0; if (nnames == 1) { - names[numActive] = strdup("default-pool"); - if (names[numActive] == NULL) { + if (VIR_STRDUP(names[numActive], "default-pool") < 0) virReportOOMError(); - } else { + else numActive++; - } } return numActive; } @@ -8385,12 +8391,10 @@ static int vboxStoragePoolListVolumes(virStoragePoolPtr pool, char **const names if (nameUtf8) { VIR_DEBUG("nnames[%d]: %s", numActive, nameUtf8); - names[numActive] = strdup(nameUtf8); - if (names[numActive] == NULL) { + if (VIR_STRDUP(names[numActive], nameUtf8) < 0) virReportOOMError(); - } else { + else numActive++; - } VBOX_UTF8_FREE(nameUtf8); } @@ -9007,12 +9011,10 @@ static char *vboxStorageVolGetXMLDesc(virStorageVolPtr vol, unsigned int flags) else defOk = 0; - def.name = strdup(vol->name); - if (!(def.name && defOk)) + if (VIR_STRDUP(def.name, vol->name) < 0) defOk = 0; - def.key = strdup(vol->key); - if (!(def.key && defOk)) + if (VIR_STRDUP(def.key, vol->key) < 0) defOk = 0; rc = hardDisk->vtbl->GetFormat(hardDisk, &hddFormatUtf16); @@ -9088,8 +9090,7 @@ static char *vboxStorageVolGetPath(virStorageVolPtr vol) { VBOX_UTF16_TO_UTF8(hddLocationUtf16, &hddLocationUtf8); if (hddLocationUtf8) { - ret = strdup(hddLocationUtf8); - if (!ret) + if (VIR_STRDUP(ret, hddLocationUtf8) < 0) virReportOOMError(); VIR_DEBUG("Storage Volume Name: %s", vol->name); @@ -9211,13 +9212,16 @@ vboxDomainScreenshot(virDomainPtr dom, goto endjob; } + if (VIR_STRDUP(ret, "image/png") < 0) + goto endjob; + if (virFDStreamOpenFile(st, tmp, 0, 0, O_RDONLY) < 0) { virReportError(VIR_ERR_OPERATION_FAILED, "%s", _("unable to open stream")); + VIR_FREE(ret); goto endjob; } - ret = strdup("image/png"); endjob: VIR_FREE(screenData); -- 1.8.1.5

On 04/29/2013 09:50 AM, Michal Privoznik wrote:
--- src/vbox/vbox_XPCOMCGlue.c | 4 +- src/vbox/vbox_tmpl.c | 190 +++++++++++++++++++++++---------------------- 2 files changed, 98 insertions(+), 96 deletions(-)
...
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 43ddac8..0e80194 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c
... Oooh - I remember going through this one while doing Coverity work - soooo many places where checks aren't made on memory allocations in the UTF#_TO_UTF# macros and strdup()'s...
@@ -2957,6 +2960,7 @@ sharedFoldersCleanup: PRUnichar *MACAddressUtf16 = NULL; char *MACAddress = NULL; char macaddr[VIR_MAC_STRING_BUFLEN] = {0}; + int strdupRet = 0;
This doesn't get tagged by the syntax-check rule in 35/37?

--- src/vmware/vmware_conf.c | 13 ++++++------- src/vmware/vmware_driver.c | 12 +++++++++--- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c index 4fb61a8..f7cd3bb 100644 --- a/src/vmware/vmware_conf.c +++ b/src/vmware/vmware_conf.c @@ -174,8 +174,7 @@ vmwareLoadDomains(struct vmware_driver *driver) pDomain = vm->privateData; - pDomain->vmxPath = strdup(vmxPath); - if (pDomain->vmxPath == NULL) { + if (VIR_STRDUP(pDomain->vmxPath, vmxPath) < 0) { virReportOOMError(); goto cleanup; } @@ -297,15 +296,15 @@ vmwareParsePath(char *path, char **directory, char **filename) return -1; } - if ((*directory = strdup(path)) == NULL) + if (VIR_STRDUP(*directory, path) < 0) goto no_memory; - if ((*filename = strdup(separator)) == NULL) { + if (VIR_STRDUP(*filename, separator) < 0) { VIR_FREE(*directory); goto no_memory; } } else { - if ((*filename = strdup(path)) == NULL) + if (VIR_STRDUP(*filename, path) < 0) goto no_memory; } @@ -492,9 +491,9 @@ cleanup: char * vmwareCopyVMXFileName(const char *datastorePath, void *opaque ATTRIBUTE_UNUSED) { - char *path = strdup(datastorePath); + char *path; - if (path == NULL) { + if (VIR_STRDUP(path, datastorePath) < 0) { virReportOOMError(); return NULL; } diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c index 1e2634e..fc01321 100644 --- a/src/vmware/vmware_driver.c +++ b/src/vmware/vmware_driver.c @@ -33,6 +33,9 @@ #include "vmx.h" #include "vmware_conf.h" #include "vmware_driver.h" +#include "virstring.h" + +#define VIR_FROM_THIS VIR_FROM_VMWARE static const char *vmw_types[] = { "player", "ws" }; @@ -352,7 +355,7 @@ vmwareDomainDefineXML(virConnectPtr conn, const char *xml) goto cleanup; pDomain = vm->privateData; - if ((pDomain->vmxPath = strdup(vmxPath)) == NULL) { + if (VIR_STRDUP(pDomain->vmxPath, vmxPath) < 0) { virReportOOMError(); goto cleanup; } @@ -636,7 +639,10 @@ vmwareDomainCreateXML(virConnectPtr conn, const char *xml, goto cleanup; pDomain = vm->privateData; - pDomain->vmxPath = strdup(vmxPath); + if (VIR_STRDUP(pDomain->vmxPath, vmxPath) < 0) { + virReportOOMError(); + goto cleanup; + } vmwareDomainConfigDisplay(pDomain, vmdef); vmdef = NULL; @@ -800,7 +806,7 @@ vmwareDomainGetOSType(virDomainPtr dom) goto cleanup; } - if (!(ret = strdup(vm->def->os.type))) + if (VIR_STRDUP(ret, vm->def->os.type) < 0) virReportOOMError(); cleanup: -- 1.8.1.5

--- src/vmx/vmx.c | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index c6c2f0d..4ccb0cd 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -682,9 +682,7 @@ virVMXGetConfigString(virConfPtr conf, const char *name, char **string, return -1; } - *string = strdup(value->str); - - if (*string == NULL) { + if (VIR_STRDUP(*string, value->str) < 0) { virReportOOMError(); return -1; } @@ -1526,9 +1524,7 @@ virVMXParseConfig(virVMXContext *ctx, def->onCrash = VIR_DOMAIN_LIFECYCLE_DESTROY; /* def:os */ - def->os.type = strdup("hvm"); - - if (def->os.type == NULL) { + if (VIR_STRDUP(def->os.type, "hvm") < 0) { virReportOOMError(); goto cleanup; } @@ -2579,9 +2575,7 @@ virVMXParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def) if (STRCASEEQ(virtualDev, "vmxnet") && features == 15) { VIR_FREE(virtualDev); - virtualDev = strdup("vmxnet2"); - - if (virtualDev == NULL) { + if (VIR_STRDUP(virtualDev, "vmxnet2") < 0) { virReportOOMError(); goto cleanup; } @@ -2596,12 +2590,9 @@ virVMXParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def) true) < 0) goto cleanup; - if (networkName == NULL) { - networkName = strdup(""); - if (networkName == NULL) { - virReportOOMError(); - goto cleanup; - } + if (!networkName && VIR_STRDUP(networkName, "") < 0) { + virReportOOMError(); + goto cleanup; } } @@ -2797,9 +2788,7 @@ virVMXParseSerial(virVMXContext *ctx, virConfPtr conf, int port, goto cleanup; } - (*def)->source.data.tcp.host = strdup(parsedUri->server); - - if ((*def)->source.data.tcp.host == NULL) { + if (VIR_STRDUP((*def)->source.data.tcp.host, parsedUri->server) < 0) { virReportOOMError(); goto cleanup; } -- 1.8.1.5

--- src/xen/xen_driver.c | 2 +- src/xen/xen_hypervisor.c | 15 +++++--------- src/xen/xen_inotify.c | 11 ++++------ src/xen/xend_internal.c | 53 +++++++++++++++--------------------------------- src/xen/xm_internal.c | 6 +++--- src/xen/xs_internal.c | 22 ++++++++------------ 6 files changed, 37 insertions(+), 72 deletions(-) diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c index 526786b..25d5394 100644 --- a/src/xen/xen_driver.c +++ b/src/xen/xen_driver.c @@ -2504,7 +2504,7 @@ xenUnifiedAddDomainInfo(xenUnifiedDomainInfoListPtr list, if (VIR_ALLOC(info) < 0) goto memory_error; - if (!(info->name = strdup(name))) + if (VIR_STRDUP(info->name, name) < 0) goto memory_error; memcpy(info->uuid, uuid, VIR_UUID_BUFLEN); diff --git a/src/xen/xen_hypervisor.c b/src/xen/xen_hypervisor.c index e15f7f2..c5f6c0f 100644 --- a/src/xen/xen_hypervisor.c +++ b/src/xen/xen_hypervisor.c @@ -1199,15 +1199,13 @@ xenHypervisorGetSchedulerType(virDomainPtr domain, int *nparams) switch (op.u.getschedulerid.sched_id){ case XEN_SCHEDULER_SEDF: - schedulertype = strdup("sedf"); - if (schedulertype == NULL) + if (VIR_STRDUP(schedulertype, "sedf") < 0) virReportOOMError(); if (nparams) *nparams = XEN_SCHED_SEDF_NPARAM; break; case XEN_SCHEDULER_CREDIT: - schedulertype = strdup("credit"); - if (schedulertype == NULL) + if (VIR_STRDUP(schedulertype, "credit") < 0) virReportOOMError(); if (nparams) *nparams = XEN_SCHED_CRED_NPARAM; @@ -2894,12 +2892,9 @@ xenHypervisorDomainGetOSType(virDomainPtr dom) return NULL; } - if (XEN_GETDOMAININFO_FLAGS(dominfo) & DOMFLAGS_HVM) - ostype = strdup("hvm"); - else - ostype = strdup("linux"); - - if (ostype == NULL) + if (VIR_STRDUP(ostype, + XEN_GETDOMAININFO_FLAGS(dominfo) & DOMFLAGS_HVM ? + "hvm" : "linux") < 0) virReportOOMError(); return ostype; diff --git a/src/xen/xen_inotify.c b/src/xen/xen_inotify.c index d83708c..3d0d094 100644 --- a/src/xen/xen_inotify.c +++ b/src/xen/xen_inotify.c @@ -39,7 +39,7 @@ #include "virlog.h" #include "viruuid.h" #include "virfile.h" - +#include "virstring.h" #include "xm_internal.h" /* for xenXMDomainConfigParse */ #define VIR_FROM_THIS VIR_FROM_XEN_INOTIFY @@ -62,10 +62,8 @@ xenInotifyXenCacheLookup(virConnectPtr conn, return -1; } - *name = strdup(entry->def->name); memcpy(uuid, entry->def->uuid, VIR_UUID_BUFLEN); - - if (!*name) { + if (VIR_STRDUP(*name, entry->def->name) < 0) { VIR_DEBUG("Error getting dom from def"); virReportOOMError(); return -1; @@ -107,8 +105,7 @@ xenInotifyXendDomainsDirLookup(virConnectPtr conn, list info */ for (i = 0 ; i < priv->configInfoList->count ; i++) { if (!memcmp(rawuuid, priv->configInfoList->doms[i]->uuid, VIR_UUID_BUFLEN)) { - *name = strdup(priv->configInfoList->doms[i]->name); - if (!*name) { + if (VIR_STRDUP(*name, priv->configInfoList->doms[i]->name) < 0) { virReportOOMError(); return -1; } @@ -122,7 +119,7 @@ xenInotifyXendDomainsDirLookup(virConnectPtr conn, return -1; } - if (!(*name = strdup(dom->name))) { + if (VIR_STRDUP(*name, dom->name) < 0) { virReportOOMError(); virDomainFree(dom); return -1; diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c index 97f44ab..4081050 100644 --- a/src/xen/xend_internal.c +++ b/src/xen/xend_internal.c @@ -761,8 +761,7 @@ xenDaemonListDomainsOld(virConnectPtr xend) _for_i = _for_i->u.s.cdr, node = _for_i->u.s.car) { if (node->kind != SEXPR_VALUE) continue; - ret[i] = strdup(node->u.value); - if (!ret[i]) + if (VIR_STRDUP(ret[i], node->u.value) < 0) goto no_memory; i++; } @@ -887,12 +886,9 @@ xenDaemonDomainLookupByID(virConnectPtr xend, "%s", _("domain information incomplete, missing name")); goto error; } - if (domname) { - *domname = strdup(name); - if (*domname == NULL) { - virReportOOMError(); - goto error; - } + if (domname && VIR_STRDUP(*domname, name) < 0) { + virReportOOMError(); + goto error; } if (sexpr_uuid(uuid, root, "domain/uuid") < 0) { @@ -1454,13 +1450,7 @@ xenDaemonDomainGetOSType(virDomainPtr domain) if (root == NULL) return NULL; - if (sexpr_lookup(root, "domain/image/hvm")) { - type = strdup("hvm"); - } else { - type = strdup("linux"); - } - - if (type == NULL) + if (VIR_STRDUP(type, sexpr_lookup(root, "domain/image/hvm") ? "hvm" : "linux") < 0) virReportOOMError(); sexpr_free(root); @@ -2363,12 +2353,8 @@ xenDaemonLookupByUUID(virConnectPtr conn, const unsigned char *uuid) else id = -1; - if (domname) { - name = strdup(domname); - - if (name == NULL) - virReportOOMError(); - } + if (domname && VIR_STRDUP(name, domname) < 0) + virReportOOMError(); sexpr_free(root); } @@ -2533,7 +2519,7 @@ xenDaemonAttachDeviceFlags(virDomainPtr domain, goto cleanup; if (dev->data.disk->device != VIR_DOMAIN_DISK_DEVICE_CDROM) { - if (!(target = strdup(dev->data.disk->dst))) { + if (VIR_STRDUP(target, dev->data.disk->dst) < 0) { virReportOOMError(); goto cleanup; } @@ -2551,7 +2537,7 @@ xenDaemonAttachDeviceFlags(virDomainPtr domain, char macStr[VIR_MAC_STRING_BUFLEN]; virMacAddrFormat(&dev->data.net->mac, macStr); - if (!(target = strdup(macStr))) { + if (VIR_STRDUP(target, macStr) < 0) { virReportOOMError(); goto cleanup; } @@ -2886,9 +2872,7 @@ xenDaemonDomainSetAutostart(virDomainPtr domain, int autostart) /* Change the autostart value in place, then define the new sexpr */ VIR_FREE(autonode->u.s.car->u.value); - autonode->u.s.car->u.value = (autostart ? strdup("start") - : strdup("ignore")); - if (!(autonode->u.s.car->u.value)) { + if (VIR_STRDUP(autonode->u.s.car->u.value,autostart ? "start" : "ignore") < 0) { virReportOOMError(); goto error; } @@ -3050,8 +3034,7 @@ xenDaemonDomainMigratePerform(virDomainPtr domain, virURIFree(uriptr); return -1; } - hostname = strdup(uriptr->server); - if (!hostname) { + if (VIR_STRDUP(hostname, uriptr->server) < 0) { virReportOOMError(); virURIFree(uriptr); return -1; @@ -3072,16 +3055,14 @@ xenDaemonDomainMigratePerform(virDomainPtr domain, /* Get the hostname. */ n = p - uri; /* n = Length of hostname in bytes. */ - hostname = strdup(uri); - if (!hostname) { + if (VIR_STRDUP(hostname, uri) < 0) { virReportOOMError(); return -1; } hostname[n] = '\0'; } else { /* "hostname" (or IP address) */ - hostname = strdup(uri); - if (!hostname) { + if (VIR_STRDUP(hostname, uri) < 0) { virReportOOMError(); return -1; } @@ -3263,7 +3244,7 @@ xenDaemonListDefinedDomains(virConnectPtr conn, if (node->kind != SEXPR_VALUE) continue; - if ((names[ret++] = strdup(node->u.value)) == NULL) { + if (VIR_STRDUP(names[ret++], node->u.value) < 0) { virReportOOMError(); goto error; } @@ -3322,16 +3303,14 @@ xenDaemonGetSchedulerType(virDomainPtr domain, int *nparams) goto error; } if (STREQ(ret, "credit")) { - schedulertype = strdup("credit"); - if (schedulertype == NULL){ + if (VIR_STRDUP(schedulertype, "credit") < 0) { virReportOOMError(); goto error; } if (nparams) *nparams = XEN_SCHED_CRED_NPARAM; } else if (STREQ(ret, "sedf")) { - schedulertype = strdup("sedf"); - if (schedulertype == NULL){ + if (VIR_STRDUP(schedulertype, "sedf") < 0) { virReportOOMError(); goto error; } diff --git a/src/xen/xm_internal.c b/src/xen/xm_internal.c index 921c66a..1a74133 100644 --- a/src/xen/xm_internal.c +++ b/src/xen/xm_internal.c @@ -260,7 +260,7 @@ xenXMConfigCacheAddFile(virConnectPtr conn, const char *filename) virReportOOMError(); return -1; } - if ((entry->filename = strdup(filename)) == NULL) { + if (VIR_STRDUP(entry->filename, filename) < 0) { virReportOOMError(); VIR_FREE(entry); return -1; @@ -1092,7 +1092,7 @@ xenXMDomainDefineXML(virConnectPtr conn, const char *xml) goto error; } - if ((entry->filename = strdup(filename)) == NULL) { + if (VIR_STRDUP(entry->filename, filename) < 0) { virReportOOMError(); goto error; } @@ -1190,7 +1190,7 @@ xenXMListIterator(void *payload ATTRIBUTE_UNUSED, const void *name, void *data) dom = xenDaemonLookupByName(ctx->conn, name); if (!dom) { - if (!(ctx->names[ctx->count] = strdup(name))) + if (VIR_STRDUP(ctx->names[ctx->count], name) < 0) ctx->oom = 1; else ctx->count++; diff --git a/src/xen/xs_internal.c b/src/xen/xs_internal.c index 5f0df63..304b7c5 100644 --- a/src/xen/xs_internal.c +++ b/src/xen/xs_internal.c @@ -50,6 +50,7 @@ #include "xen_driver.h" #include "xs_internal.h" #include "xen_hypervisor.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_XEN @@ -851,9 +852,7 @@ xenStoreDomainGetNetworkID(virConnectPtr conn, int id, const char *mac) VIR_FREE(val); if (match) { - ret = strdup(list[i]); - - if (ret == NULL) + if (VIR_STRDUP(ret, list[i]) < 0) virReportOOMError(); break; @@ -904,9 +903,7 @@ xenStoreDomainGetDiskID(virConnectPtr conn, int id, const char *dev) if ((devlen != len) || memcmp(val, dev, len)) { VIR_FREE(val); } else { - ret = strdup(list[i]); - - if (ret == NULL) + if (VIR_STRDUP(ret, list[i]) < 0) virReportOOMError(); VIR_FREE(val); @@ -927,9 +924,7 @@ xenStoreDomainGetDiskID(virConnectPtr conn, int id, const char *dev) if ((devlen != len) || memcmp(val, dev, len)) { VIR_FREE(val); } else { - ret = strdup(list[i]); - - if (ret == NULL) + if (VIR_STRDUP(ret, list[i]) < 0) virReportOOMError(); VIR_FREE(val); @@ -982,7 +977,8 @@ xenStoreDomainGetPCIID(virConnectPtr conn, int id, const char *bdf) VIR_FREE(val); if (match) { - ret = strdup(list[i]); + if (VIR_STRDUP(ret, list[i]) < 0) + virReportOOMError(); break; } } @@ -1091,14 +1087,12 @@ xenStoreAddWatch(virConnectPtr conn, if (VIR_ALLOC(watch) < 0) goto no_memory; - watch->path = strdup(path); - watch->token = strdup(token); watch->cb = cb; watch->opaque = opaque; - if (watch->path == NULL || watch->token == NULL) { + if (VIR_STRDUP(watch->path, path) < 0 || + VIR_STRDUP(watch->token, token) < 0) goto no_memory; - } /* Make space on list */ n = list->count; -- 1.8.1.5

--- src/xenapi/xenapi_driver.c | 32 +++++++++++++++----------------- src/xenapi/xenapi_utils.c | 20 ++++++++++---------- 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src/xenapi/xenapi_driver.c b/src/xenapi/xenapi_driver.c index 7e64df6..86abab8 100644 --- a/src/xenapi/xenapi_driver.c +++ b/src/xenapi/xenapi_driver.c @@ -135,9 +135,7 @@ xenapiConnectOpen(virConnectPtr conn, virConnectAuthPtr auth, } if (conn->uri->user != NULL) { - username = strdup(conn->uri->user); - - if (username == NULL) { + if (VIR_STRDUP(username, conn->uri->user) < 0) { virReportOOMError(); goto error; } @@ -320,7 +318,7 @@ xenapiConnectGetVersion(virConnectPtr conn, unsigned long *hvVer) if (result && result->size > 0) { for (i = 0; i < result->size; i++) { if (STREQ(result->contents[i].key, "xen")) { - if (!(version = strdup(result->contents[i].val))) { + if (VIR_STRDUP(version, result->contents[i].val) < 0) { xen_string_string_map_free(result); virReportOOMError(); return -1; @@ -952,7 +950,7 @@ xenapiDomainGetOSType(virDomainPtr dom) xenapiSessionErrorHandler(dom->conn, VIR_ERR_INTERNAL_ERROR, NULL); goto cleanup; } - if (!(ostype = (STREQ(boot_policy,"BIOS order") ? strdup("hvm") : strdup("xen")))) + if (VIR_STRDUP(ostype, STREQ(boot_policy, "BIOS order") ? "hvm" : "xen") < 0) virReportOOMError(); VIR_FREE(boot_policy); } else @@ -1268,7 +1266,7 @@ xenapiDomainGetVcpus(virDomainPtr dom, } for (i = 0; i < vcpu_params->size; i++) { if (STREQ(vcpu_params->contents[i].key, "mask")) { - if (!(mask = strdup(vcpu_params->contents[i].val))){ + if (VIR_STRDUP(mask, vcpu_params->contents[i].val) < 0){ xen_vm_set_free(vms); xen_string_string_map_free(vcpu_params); virReportOOMError(); @@ -1386,11 +1384,11 @@ xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) defPtr->virtType = VIR_DOMAIN_VIRT_XEN; defPtr->id = dom->id; memcpy(defPtr->uuid, dom->uuid, VIR_UUID_BUFLEN); - if (!(defPtr->name = strdup(dom->name))) + if (VIR_STRDUP(defPtr->name, dom->name) < 0) goto error_cleanup; xen_vm_get_hvm_boot_policy(session, &boot_policy, vm); if (STREQ(boot_policy,"BIOS order")) { - if (!(defPtr->os.type = strdup("hvm"))) { + if (VIR_STRDUP(defPtr->os.type, "hvm") < 0) { VIR_FREE(boot_policy); goto error_cleanup; } @@ -1413,17 +1411,17 @@ xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) VIR_FREE(boot_policy); } else { char *value = NULL; - if (!(defPtr->os.type = strdup("xen"))) { + if (VIR_STRDUP(defPtr->os.type, "xen") < 0) { VIR_FREE(boot_policy); goto error_cleanup; } - if (!(defPtr->os.loader = strdup("pygrub"))) { + if (VIR_STRDUP(defPtr->os.loader, "pygrub") < 0) { VIR_FREE(boot_policy); goto error_cleanup; } xen_vm_get_pv_kernel(session, &value, vm); if (STRNEQ(value, "")) { - if (!(defPtr->os.kernel = strdup(value))) { + if (VIR_STRDUP(defPtr->os.kernel, value) < 0) { VIR_FREE(boot_policy); VIR_FREE(value); goto error_cleanup; @@ -1432,7 +1430,7 @@ xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) } xen_vm_get_pv_ramdisk(session, &value, vm); if (STRNEQ(value, "")) { - if (!(defPtr->os.initrd = strdup(value))) { + if (VIR_STRDUP(defPtr->os.initrd, value) < 0) { VIR_FREE(boot_policy); VIR_FREE(value); goto error_cleanup; @@ -1441,7 +1439,7 @@ xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) } xen_vm_get_pv_args(session, &value, vm); if (STRNEQ(value, "")) { - if (!(defPtr->os.cmdline = strdup(value))) { + if (VIR_STRDUP(defPtr->os.cmdline, value) < 0) { VIR_FREE(boot_policy); VIR_FREE(value); goto error_cleanup; @@ -1449,12 +1447,12 @@ xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) VIR_FREE(value); } VIR_FREE(boot_policy); - if (!(defPtr->os.bootloader = strdup("pygrub"))) + if (VIR_STRDUP(defPtr->os.bootloader, "pygrub") < 0) goto error_cleanup; } xen_vm_get_pv_bootloader_args(session, &val, vm); if (STRNEQ(val, "")) { - if (!(defPtr->os.bootloaderArgs = strdup(val))) { + if (VIR_STRDUP(defPtr->os.bootloaderArgs, val) < 0) { VIR_FREE(val); goto error_cleanup; } @@ -1569,7 +1567,7 @@ xenapiConnectListDefinedDomains(virConnectPtr conn, char **const names, if (record != NULL) { if (record->is_a_template == 0) { char *usenames = NULL; - if (!(usenames = strdup(record->name_label))) { + if (VIR_STRDUP(usenames, record->name_label) < 0) { virReportOOMError(); xen_vm_record_free(record); xen_vm_set_free(result); @@ -1862,7 +1860,7 @@ xenapiDomainGetSchedulerType(virDomainPtr dom ATTRIBUTE_UNUSED, int *nparams) if (nparams) *nparams = 0; - if (!(result = strdup("credit"))) + if (VIR_STRDUP(result, "credit") < 0) virReportOOMError(); return result; } diff --git a/src/xenapi/xenapi_utils.c b/src/xenapi/xenapi_utils.c index 55fbb24..8dc0873 100644 --- a/src/xenapi/xenapi_utils.c +++ b/src/xenapi/xenapi_utils.c @@ -352,8 +352,8 @@ allocStringMap(xen_string_string_map **strings, char *key, char *val) return -1; } (*strings)->size = sz; - if (!((*strings)->contents[sz-1].key = strdup(key))) goto error; - if (!((*strings)->contents[sz-1].val = strdup(val))) goto error; + if (VIR_STRDUP((*strings)->contents[sz-1].key, key) < 0) goto error; + if (VIR_STRDUP((*strings)->contents[sz-1].val, val) < 0) goto error; return 0; error: xen_string_string_map_free(*strings); @@ -455,16 +455,16 @@ createVMRecordFromXml(virConnectPtr conn, virDomainDefPtr def, int i; *record = xen_vm_record_alloc(); - if (!((*record)->name_label = strdup(def->name))) + if (VIR_STRDUP((*record)->name_label, def->name) < 0) goto error_cleanup; if (def->uuid) { virUUIDFormat(def->uuid, uuidStr); - if (!((*record)->uuid = strdup(uuidStr))) + if (VIR_STRDUP((*record)->uuid, uuidStr) < 0) goto error_cleanup; } if (STREQ(def->os.type, "hvm")) { char *boot_order = NULL; - if (!((*record)->hvm_boot_policy = strdup("BIOS order"))) + if (VIR_STRDUP((*record)->hvm_boot_policy, "BIOS order") < 0) goto error_cleanup; if (def->os.nBootDevs != 0) boot_order = createXenAPIBootOrderString(def->os.nBootDevs, &def->os.bootDevs[0]); @@ -475,24 +475,24 @@ createVMRecordFromXml(virConnectPtr conn, virDomainDefPtr def, VIR_FREE(boot_order); } } else if (STREQ(def->os.type, "xen")) { - if (!((*record)->pv_bootloader = strdup("pygrub"))) + if (VIR_STRDUP((*record)->pv_bootloader, "pygrub") < 0) goto error_cleanup; if (def->os.kernel) { - if (!((*record)->pv_kernel = strdup(def->os.kernel))) + if (VIR_STRDUP((*record)->pv_kernel, def->os.kernel) < 0) goto error_cleanup; } if (def->os.initrd) { - if (!((*record)->pv_ramdisk = strdup(def->os.initrd))) + if (VIR_STRDUP((*record)->pv_ramdisk, def->os.initrd) < 0) goto error_cleanup; } if (def->os.cmdline) { - if (!((*record)->pv_args = strdup(def->os.cmdline))) + if (VIR_STRDUP((*record)->pv_args, def->os.cmdline) < 0) goto error_cleanup; } (*record)->hvm_boot_params = xen_string_string_map_alloc(0); } if (def->os.bootloaderArgs) - if (!((*record)->pv_bootloader_args = strdup(def->os.bootloaderArgs))) + if (VIR_STRDUP((*record)->pv_bootloader_args, def->os.bootloaderArgs) < 0) goto error_cleanup; if (def->mem.cur_balloon) -- 1.8.1.5

--- src/xenxs/xen_sxpr.c | 107 +++++++++++++++++++++------------------------------ src/xenxs/xen_xm.c | 43 ++++++++++----------- 2 files changed, 65 insertions(+), 85 deletions(-) diff --git a/src/xenxs/xen_sxpr.c b/src/xenxs/xen_sxpr.c index 9a76d04..7ebaa30 100644 --- a/src/xenxs/xen_sxpr.c +++ b/src/xenxs/xen_sxpr.c @@ -192,8 +192,7 @@ xenParseSxprChar(const char *value, if (value[0] == '/') { def->source.type = VIR_DOMAIN_CHR_TYPE_DEV; - def->source.data.file.path = strdup(value); - if (!def->source.data.file.path) + if (VIR_STRDUP(def->source.data.file.path, value) < 0) goto no_memory; } else { if ((tmp = strchr(value, ':')) != NULL) { @@ -216,13 +215,13 @@ xenParseSxprChar(const char *value, switch (def->source.type) { case VIR_DOMAIN_CHR_TYPE_PTY: if (tty != NULL && - !(def->source.data.file.path = strdup(tty))) + VIR_STRDUP(def->source.data.file.path, tty) < 0) goto no_memory; break; case VIR_DOMAIN_CHR_TYPE_FILE: case VIR_DOMAIN_CHR_TYPE_PIPE: - if (!(def->source.data.file.path = strdup(value))) + if (VIR_STRDUP(def->source.data.file.path, value) < 0) goto no_memory; break; @@ -238,17 +237,14 @@ xenParseSxprChar(const char *value, } if (offset != value && - (def->source.data.tcp.host = strndup(value, - offset - value)) == NULL) + VIR_STRNDUP(def->source.data.tcp.host, value, offset - value) < 0) goto no_memory; offset2 = strchr(offset, ','); - if (offset2 == NULL) - def->source.data.tcp.service = strdup(offset+1); - else - def->source.data.tcp.service = strndup(offset+1, - offset2-(offset+1)); - if (def->source.data.tcp.service == NULL) + + if ((offset2 && VIR_STRNDUP(def->source.data.tcp.service, offset + 1, + offset2 - (offset + 1)) < 0) || + (!offset2 && VIR_STRDUP(def->source.data.tcp.service, offset + 1) < 0)) goto no_memory; if (offset2 && strstr(offset2, ",server")) @@ -268,14 +264,12 @@ xenParseSxprChar(const char *value, } if (offset != value && - (def->source.data.udp.connectHost - = strndup(value, offset - value)) == NULL) + VIR_STRNDUP(def->source.data.udp.connectHost, value, offset - value) < 0) goto no_memory; offset2 = strchr(offset, '@'); if (offset2 != NULL) { - if ((def->source.data.udp.connectService - = strndup(offset + 1, offset2-(offset+1))) == NULL) + if (VIR_STRNDUP(def->source.data.udp.connectService, offset + 1, offset2-(offset+1)) < 0) goto no_memory; offset3 = strchr(offset2, ':'); @@ -286,16 +280,13 @@ xenParseSxprChar(const char *value, } if (offset3 > (offset2 + 1) && - (def->source.data.udp.bindHost - = strndup(offset2 + 1, offset3 - (offset2+1))) == NULL) + VIR_STRNDUP(def->source.data.udp.bindHost, offset2 + 1, offset3 - (offset2+1)) < 0) goto no_memory; - if ((def->source.data.udp.bindService - = strdup(offset3 + 1)) == NULL) + if (VIR_STRDUP(def->source.data.udp.bindService, offset3 + 1) < 0) goto no_memory; } else { - if ((def->source.data.udp.connectService - = strdup(offset + 1)) == NULL) + if (VIR_STRDUP(def->source.data.udp.connectService, offset + 1) < 0) goto no_memory; } } @@ -304,11 +295,9 @@ xenParseSxprChar(const char *value, case VIR_DOMAIN_CHR_TYPE_UNIX: { const char *offset = strchr(value, ','); - if (offset) - def->source.data.nix.path = strndup(value, (offset - value)); - else - def->source.data.nix.path = strdup(value); - if (def->source.data.nix.path == NULL) + + if ((offset && VIR_STRNDUP(def->source.data.nix.path, value, (offset - value)) < 0) || + (!offset && VIR_STRDUP(def->source.data.nix.path, value) < 0)) goto no_memory; if (offset != NULL && @@ -411,7 +400,7 @@ xenParseSxprDisks(virDomainDefPtr def, if (sexpr_lookup(node, "device/tap2") && STRPREFIX(src, "tap:")) { - if (!(disk->driverName = strdup("tap2"))) + if (VIR_STRDUP(disk->driverName, "tap2") < 0) goto no_memory; } else { if (VIR_ALLOC_N(disk->driverName, (offset-src)+1) < 0) @@ -438,7 +427,7 @@ xenParseSxprDisks(virDomainDefPtr def, goto error; } - if (!(driverType = strndup(src, offset - src))) + if (VIR_STRNDUP(driverType, src, offset - src) < 0) goto no_memory; if (STREQ(driverType, "aio")) disk->format = VIR_STORAGE_FILE_RAW; @@ -490,10 +479,9 @@ xenParseSxprDisks(virDomainDefPtr def, } } - if (!(disk->dst = strdup(dst))) + if (VIR_STRDUP(disk->dst, dst) < 0) goto no_memory; - if (src && - !(disk->src = strdup(src))) + if (src && VIR_STRDUP(disk->src, src) < 0) goto no_memory; if (STRPREFIX(disk->dst, "xvd")) @@ -572,25 +560,21 @@ xenParseSxprNets(virDomainDefPtr def, net->type = VIR_DOMAIN_NET_TYPE_BRIDGE; /* XXX virtual network reverse resolve */ - if (tmp && - !(net->data.bridge.brname = strdup(tmp))) + if (tmp &&VIR_STRDUP(net->data.bridge.brname, tmp) < 0) goto no_memory; if (tmp2 && net->type == VIR_DOMAIN_NET_TYPE_BRIDGE && - !(net->script = strdup(tmp2))) + VIR_STRDUP(net->script, tmp2) < 0) goto no_memory; tmp = sexpr_node(node, "device/vif/ip"); - if (tmp && - !(net->data.bridge.ipaddr = strdup(tmp))) + if (tmp && VIR_STRDUP(net->data.bridge.ipaddr, tmp) < 0) goto no_memory; } else { net->type = VIR_DOMAIN_NET_TYPE_ETHERNET; - if (tmp2 && - !(net->script = strdup(tmp2))) + if (tmp2 && VIR_STRDUP(net->script, tmp2) < 0) goto no_memory; tmp = sexpr_node(node, "device/vif/ip"); - if (tmp && - !(net->data.ethernet.ipaddr = strdup(tmp))) + if (tmp && VIR_STRDUP(net->data.ethernet.ipaddr, tmp) < 0) goto no_memory; } @@ -599,7 +583,7 @@ xenParseSxprNets(virDomainDefPtr def, * definition regardless of domain state. If vifname is not * specified, only generate one if domain is active (id != -1). */ if (tmp) { - if (!(net->ifname = strdup(tmp))) + if (VIR_STRDUP(net->ifname, tmp) < 0) goto no_memory; } else if (def->id != -1) { if (virAsprintf(&net->ifname, "vif%d.%d", def->id, vif_index) < 0) @@ -615,13 +599,12 @@ xenParseSxprNets(virDomainDefPtr def, } } - if (model && - !(net->model = strdup(model))) + if (model && VIR_STRDUP(net->model, model) < 0) goto no_memory; if (!model && type && STREQ(type, "netfront") && - !(net->model = strdup("netfront"))) + VIR_STRDUP(net->model, "netfront") < 0) goto no_memory; if (VIR_REALLOC_N(def->nets, def->nnets + 1) < 0) @@ -834,11 +817,11 @@ xenParseSxprGraphicsOld(virDomainDefPtr def, goto error; if (vncPasswd && - !(graphics->data.vnc.auth.passwd = strdup(vncPasswd))) + VIR_STRDUP(graphics->data.vnc.auth.passwd, vncPasswd) < 0) goto no_memory; if (keymap && - !(graphics->data.vnc.keymap = strdup(keymap))) + VIR_STRDUP(graphics->data.vnc.keymap, keymap) < 0) goto no_memory; if (VIR_ALLOC_N(def->graphics, 1) < 0) @@ -857,10 +840,10 @@ xenParseSxprGraphicsOld(virDomainDefPtr def, graphics->type = VIR_DOMAIN_GRAPHICS_TYPE_SDL; if (display && - !(graphics->data.sdl.display = strdup(display))) + VIR_STRDUP(graphics->data.sdl.display, display) < 0) goto no_memory; if (xauth && - !(graphics->data.sdl.xauth = strdup(xauth))) + VIR_STRDUP(graphics->data.sdl.xauth, xauth) < 0) goto no_memory; if (VIR_ALLOC_N(def->graphics, 1) < 0) @@ -926,11 +909,9 @@ xenParseSxprGraphicsNew(virDomainDefPtr def, if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_SDL) { const char *display = sexpr_node(node, "device/vfb/display"); const char *xauth = sexpr_node(node, "device/vfb/xauthority"); - if (display && - !(graphics->data.sdl.display = strdup(display))) + if (display && VIR_STRDUP(graphics->data.sdl.display, display) < 0) goto no_memory; - if (xauth && - !(graphics->data.sdl.xauth = strdup(xauth))) + if (xauth && VIR_STRDUP(graphics->data.sdl.xauth, xauth) < 0) goto no_memory; } else { int port; @@ -961,11 +942,11 @@ xenParseSxprGraphicsNew(virDomainDefPtr def, goto error; if (vncPasswd && - !(graphics->data.vnc.auth.passwd = strdup(vncPasswd))) + VIR_STRDUP(graphics->data.vnc.auth.passwd, vncPasswd) < 0) goto no_memory; if (keymap && - !(graphics->data.vnc.keymap = strdup(keymap))) + VIR_STRDUP(graphics->data.vnc.keymap, keymap) < 0) goto no_memory; } @@ -1180,7 +1161,7 @@ xenParseSxpr(const struct sexpr *root, if (!def->os.bootloader && sexpr_has(root, "domain/bootloader") && - (def->os.bootloader = strdup("")) == NULL) + VIR_STRDUP(def->os.bootloader, "") < 0) goto no_memory; if (def->os.bootloader && @@ -1189,7 +1170,7 @@ xenParseSxpr(const struct sexpr *root, goto no_memory; } - if (!(def->os.type = strdup(hvm ? "hvm" : "linux"))) + if (VIR_STRDUP(def->os.type, hvm ? "hvm" : "linux") < 0) goto no_memory; if (def->id != 0) { @@ -1357,17 +1338,17 @@ xenParseSxpr(const struct sexpr *root, virDomainDiskDefPtr disk; if (VIR_ALLOC(disk) < 0) goto no_memory; - if (!(disk->src = strdup(tmp))) { + if (VIR_STRDUP(disk->src, tmp) < 0) { virDomainDiskDefFree(disk); goto no_memory; } disk->type = VIR_DOMAIN_DISK_TYPE_FILE; disk->device = VIR_DOMAIN_DISK_DEVICE_CDROM; - if (!(disk->dst = strdup("hdc"))) { + if (VIR_STRDUP(disk->dst, "hdc") < 0) { virDomainDiskDefFree(disk); goto no_memory; } - if (!(disk->driverName = strdup("file"))) { + if (VIR_STRDUP(disk->driverName, "file") < 0) { virDomainDiskDefFree(disk); goto no_memory; } @@ -1393,17 +1374,17 @@ xenParseSxpr(const struct sexpr *root, virDomainDiskDefPtr disk; if (VIR_ALLOC(disk) < 0) goto no_memory; - if (!(disk->src = strdup(tmp))) { + if (VIR_STRDUP(disk->src, tmp) < 0) { VIR_FREE(disk); goto no_memory; } disk->type = VIR_DOMAIN_DISK_TYPE_FILE; disk->device = VIR_DOMAIN_DISK_DEVICE_FLOPPY; - if (!(disk->dst = strdup(fds[i]))) { + if (VIR_STRDUP(disk->dst, fds[i]) < 0) { virDomainDiskDefFree(disk); goto no_memory; } - if (!(disk->driverName = strdup("file"))) { + if (VIR_STRDUP(disk->driverName, "file") < 0) { virDomainDiskDefFree(disk); goto no_memory; } diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index 57ce2e7..7161fac 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -183,7 +183,7 @@ static int xenXMConfigCopyStringInternal(virConfPtr conf, return -1; } - if (!(*value = strdup(val->str))) { + if (VIR_STRDUP(*value, val->str) < 0) { virReportOOMError(); return -1; } @@ -288,7 +288,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, STREQ(str, "hvm")) hvm = 1; - if (!(def->os.type = strdup(hvm ? "hvm" : "xen"))) + if (VIR_STRDUP(def->os.type, hvm ? "hvm" : "xen") < 0) goto no_memory; def->os.arch = @@ -307,7 +307,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, def->os.arch, virDomainVirtTypeToString(def->virtType)); if (defaultMachine != NULL) { - if (!(def->os.machine = strdup(defaultMachine))) + if (VIR_STRDUP(def->os.machine, defaultMachine) < 0) goto no_memory; } @@ -562,7 +562,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, if (!(tmp = strchr(disk->src, ':'))) goto skipdisk; - if (!(driverType = strndup(disk->src, tmp - disk->src))) + if (VIR_STRNDUP(driverType, disk->src, tmp - disk->src) < 0) goto no_memory; if (STREQ(driverType, "aio")) disk->format = VIR_STORAGE_FILE_RAW; @@ -584,8 +584,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, } /* No source, or driver name, so fix to phy: */ - if (!disk->driverName && - !(disk->driverName = strdup("phy"))) + if (!disk->driverName && VIR_STRDUP(disk->driverName, "phy") < 0) goto no_memory; @@ -637,11 +636,11 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, disk->type = VIR_DOMAIN_DISK_TYPE_FILE; disk->device = VIR_DOMAIN_DISK_DEVICE_CDROM; - if (!(disk->driverName = strdup("file"))) + if (VIR_STRDUP(disk->driverName, "file") < 0) goto no_memory; - if (!(disk->src = strdup(str))) + if (VIR_STRDUP(disk->src, str) < 0) goto no_memory; - if (!(disk->dst = strdup("hdc"))) + if (VIR_STRDUP(disk->dst, "hdc") < 0) goto no_memory; disk->bus = VIR_DOMAIN_DISK_BUS_IDE; disk->readonly = true; @@ -703,7 +702,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, } else if (STRPREFIX(key, "script=")) { int len = nextkey ? (nextkey - data) : strlen(data); VIR_FREE(script); - if (!(script = strndup(data, len))) { + if (VIR_STRNDUP(script, data, len) < 0) { goto no_memory; } } else if (STRPREFIX(key, "model=")) { @@ -764,32 +763,32 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE) { if (bridge[0] && - !(net->data.bridge.brname = strdup(bridge))) + VIR_STRDUP(net->data.bridge.brname, bridge) < 0) goto no_memory; if (ip[0] && - !(net->data.bridge.ipaddr = strdup(ip))) + VIR_STRDUP(net->data.bridge.ipaddr, ip) < 0) goto no_memory; } else { if (ip[0] && - !(net->data.ethernet.ipaddr = strdup(ip))) + VIR_STRDUP(net->data.ethernet.ipaddr, ip) < 0) goto no_memory; } if (script && script[0] && - !(net->script = strdup(script))) + VIR_STRDUP(net->script, script) < 0) goto no_memory; if (model[0] && - !(net->model = strdup(model))) + VIR_STRDUP(net->model, model) < 0) goto no_memory; if (!model[0] && type[0] && STREQ(type, "netfront") && - !(net->model = strdup("netfront"))) + VIR_STRDUP(net->model, "netfront") < 0) goto no_memory; if (vifname[0] && - !(net->ifname = strdup(vifname))) + VIR_STRDUP(net->ifname, vifname) < 0) goto no_memory; if (VIR_REALLOC_N(def->nets, def->nnets+1) < 0) @@ -1019,20 +1018,20 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, -1, true) < 0) goto cleanup; } else if (STRPREFIX(key, "vncpasswd=")) { - if (!(graphics->data.vnc.auth.passwd = strdup(key + 10))) + if (VIR_STRDUP(graphics->data.vnc.auth.passwd, key + 10) < 0) goto no_memory; } else if (STRPREFIX(key, "keymap=")) { - if (!(graphics->data.vnc.keymap = strdup(key + 7))) + if (VIR_STRDUP(graphics->data.vnc.keymap, key + 7) < 0) goto no_memory; } 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 = strdup(key + 8))) + if (VIR_STRDUP(graphics->data.sdl.display, key + 8) < 0) goto no_memory; } else if (STRPREFIX(key, "xauthority=")) { - if (!(graphics->data.sdl.xauth = strdup(key + 11))) + if (VIR_STRDUP(graphics->data.sdl.xauth, key + 11) < 0) goto no_memory; } } @@ -1193,7 +1192,7 @@ int xenXMConfigSetString(virConfPtr conf, const char *setting, const char *str) value->type = VIR_CONF_STRING; value->next = NULL; - if (!(value->str = strdup(str))) { + if (VIR_STRDUP(value->str, str) < 0) { VIR_FREE(value); virReportOOMError(); return -1; -- 1.8.1.5

On 04/29/2013 09:50 AM, Michal Privoznik wrote:
--- src/xenxs/xen_sxpr.c | 107 +++++++++++++++++++++------------------------------ src/xenxs/xen_xm.c | 43 ++++++++++----------- 2 files changed, 65 insertions(+), 85 deletions(-)
diff --git a/src/xenxs/xen_sxpr.c b/src/xenxs/xen_sxpr.c index 9a76d04..7ebaa30 100644 --- a/src/xenxs/xen_sxpr.c +++ b/src/xenxs/xen_sxpr.c
...
@@ -572,25 +560,21 @@ xenParseSxprNets(virDomainDefPtr def, net->type = VIR_DOMAIN_NET_TYPE_BRIDGE; /* XXX virtual network reverse resolve */
- if (tmp && - !(net->data.bridge.brname = strdup(tmp))) + if (tmp &&VIR_STRDUP(net->data.bridge.brname, tmp) < 0)
spacing ^^^^ ...

--- tests/commandhelper.c | 14 +++++++++++--- tests/commandtest.c | 2 +- tests/openvzutilstest.c | 6 ++++-- tests/qemumonitortestutils.c | 8 ++++---- tests/qemuxml2argvtest.c | 27 ++++++++++++++++----------- tests/qemuxmlnstest.c | 4 +++- tests/securityselinuxhelper.c | 7 +++++-- tests/securityselinuxlabeltest.c | 2 +- tests/securityselinuxtest.c | 6 ++---- tests/storagebackendsheepdogtest.c | 6 ++---- tests/testutils.c | 4 +++- tests/testutilsqemu.c | 5 ++++- tests/vircgrouptest.c | 2 +- tests/virnetmessagetest.c | 21 +++++++++------------ tests/vmx2xmltest.c | 10 +++++----- tests/xml2vmxtest.c | 10 +++++----- 16 files changed, 76 insertions(+), 58 deletions(-) diff --git a/tests/commandhelper.c b/tests/commandhelper.c index 92f031f..8012424 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -31,6 +31,9 @@ #include "viralloc.h" #include "virfile.h" #include "testutils.h" +#include "virstring.h" + +#define VIR_FROM_THIS VIR_FROM_NONE #ifndef WIN32 @@ -42,9 +45,14 @@ static int envsort(const void *a, const void *b) { const char *bstr = *bstrptr; char *aeq = strchr(astr, '='); char *beq = strchr(bstr, '='); - char *akey = strndup(astr, aeq - astr); - char *bkey = strndup(bstr, beq - bstr); - int ret = strcmp(akey, bkey); + char *akey, *bkey; + int ret; + + if (VIR_STRNDUP(akey, astr, aeq - astr) < 0 || + VIR_STRNDUP(bkey, bstr, beq - bstr) < 0) + ret = 0; + else + ret = strcmp(akey, bkey); VIR_FREE(akey); VIR_FREE(bkey); return ret; diff --git a/tests/commandtest.c b/tests/commandtest.c index 6cb88c5..097e605 100644 --- a/tests/commandtest.c +++ b/tests/commandtest.c @@ -685,7 +685,7 @@ static int test17(const void *unused ATTRIBUTE_UNUSED) goto cleanup; } VIR_FREE(outbuf); - if ((outbuf = strdup("should not be leaked")) == NULL) { + if (VIR_STRDUP(outbuf, "should not be leaked") < 0) { puts("test framework failure"); goto cleanup; } diff --git a/tests/openvzutilstest.c b/tests/openvzutilstest.c index be0c74c..3cfbfb9 100644 --- a/tests/openvzutilstest.c +++ b/tests/openvzutilstest.c @@ -13,6 +13,8 @@ # include "openvz/openvz_conf.h" # include "virstring.h" +# define VIR_FROM_THIS VIR_FROM_NONE + static int testLocateConfFile(int vpsid ATTRIBUTE_UNUSED, char **conffile, const char *ext ATTRIBUTE_UNUSED) @@ -103,8 +105,8 @@ testReadNetworkConf(const void *data ATTRIBUTE_UNUSED) "</domain>\n"; if (VIR_ALLOC(def) < 0 || - !(def->os.type = strdup("exe")) || - !(def->os.init = strdup("/sbin/init"))) + VIR_STRDUP(def->os.type, "exe") < 0 || + VIR_STRDUP(def->os.init, "/sbin/init") < 0) goto cleanup; def->virtType = VIR_DOMAIN_VIRT_OPENVZ; diff --git a/tests/qemumonitortestutils.c b/tests/qemumonitortestutils.c index c24a37f..2f00cb7 100644 --- a/tests/qemumonitortestutils.c +++ b/tests/qemumonitortestutils.c @@ -159,7 +159,7 @@ static int qemuMonitorTestProcessCommandText(qemuMonitorTestPtr test, char *cmdname; int ret = -1; - if (!(cmdname = strdup(cmdstr))) { + if (VIR_STRDUP(cmdname, cmdstr) < 0) { virReportOOMError(); return -1; } @@ -407,8 +407,8 @@ qemuMonitorTestAddItem(qemuMonitorTestPtr test, if (VIR_ALLOC(item) < 0) goto no_memory; - if (!(item->command_name = strdup(command_name)) || - !(item->response = strdup(response))) + if (VIR_STRDUP(item->command_name, command_name) < 0 || + VIR_STRDUP(item->response, response) < 0) goto no_memory; virMutexLock(&test->lock); @@ -467,7 +467,7 @@ qemuMonitorTestPtr qemuMonitorTestNew(bool json, virDomainXMLOptionPtr xmlopt) return NULL; } - if (!(tmpdir_template = strdup("/tmp/libvirt_XXXXXX"))) + if (VIR_STRDUP(tmpdir_template, "/tmp/libvirt_XXXXXX") < 0) goto no_memory; if (!(test->tmpdir = mkdtemp(tmpdir_template))) { diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 1286273..df53c2e 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -20,9 +20,10 @@ # include "datatypes.h" # include "cpu/cpu_map.h" # include "virstring.h" - # include "testutilsqemu.h" +# define VIR_FROM_THIS VIR_FROM_NONE + static const char *abs_top_srcdir; static virQEMUDriver driver; @@ -32,8 +33,9 @@ fakeSecretGetValue(virSecretPtr obj ATTRIBUTE_UNUSED, unsigned int fakeflags ATTRIBUTE_UNUSED, unsigned int internalFlags ATTRIBUTE_UNUSED) { - char *secret = strdup("AQCVn5hO6HzFAhAAq0NCv8jtJcIcE+HOBlMQ1A"); - if (!secret) { + char *secret; + + if (VIR_STRDUP(secret, "AQCVn5hO6HzFAhAAq0NCv8jtJcIcE+HOBlMQ1A") < 0) { return NULL; } *value_size = strlen(secret); @@ -129,7 +131,7 @@ static int testCompareXMLToArgvFiles(const char *xml, if (STREQ(vmdef->os.machine, "pc") && STREQ(vmdef->emulator, "/usr/bin/qemu-system-x86_64")) { VIR_FREE(vmdef->os.machine); - if (!(vmdef->os.machine = strdup("pc-0.11"))) + if (VIR_STRDUP(vmdef->os.machine, "pc-0.11") < 0) goto out; } @@ -288,10 +290,10 @@ mymain(void) VIR_FREE(driver.config->vncListen); VIR_FREE(driver.config->vncTLSx509certdir); - if ((driver.config->vncTLSx509certdir = strdup("/etc/pki/libvirt-vnc")) == NULL) + if (VIR_STRDUP(driver.config->vncTLSx509certdir, "/etc/pki/libvirt-vnc") < 0) return EXIT_FAILURE; VIR_FREE(driver.config->spiceTLSx509certdir); - if ((driver.config->spiceTLSx509certdir = strdup("/etc/pki/libvirt-spice")) == NULL) + if (VIR_STRDUP(driver.config->spiceTLSx509certdir, "/etc/pki/libvirt-spice") < 0) return EXIT_FAILURE; if ((driver.caps = testQemuCapsInit()) == NULL) @@ -299,16 +301,16 @@ mymain(void) if (!(driver.xmlopt = virQEMUDriverCreateXMLConf(&driver))) return EXIT_FAILURE; VIR_FREE(driver.config->stateDir); - if ((driver.config->stateDir = strdup("/nowhere")) == NULL) + if (VIR_STRDUP(driver.config->stateDir, "/nowhere") < 0) return EXIT_FAILURE; VIR_FREE(driver.config->hugetlbfsMount); - if ((driver.config->hugetlbfsMount = strdup("/dev/hugepages")) == NULL) + if (VIR_STRDUP(driver.config->hugetlbfsMount, "/dev/hugepages") < 0) return EXIT_FAILURE; VIR_FREE(driver.config->hugepagePath); - if ((driver.config->hugepagePath = strdup("/dev/hugepages/libvirt/qemu")) == NULL) + if (VIR_STRDUP(driver.config->hugepagePath, "/dev/hugepages/libvirt/qemu") < 0) return EXIT_FAILURE; driver.config->spiceTLS = 1; - if (!(driver.config->spicePassword = strdup("123456"))) + if (VIR_STRDUP(driver.config->spicePassword, "123456") < 0) return EXIT_FAILURE; if (virAsprintf(&map, "%s/src/cpu/cpu_map.xml", abs_top_srcdir) < 0 || cpuMapOverride(map) < 0) { @@ -601,7 +603,9 @@ mymain(void) driver.config->vncSASL = 1; VIR_FREE(driver.config->vncSASLdir); - driver.config->vncSASLdir = strdup("/root/.sasl2"); + if (VIR_STRDUP(driver.config->vncSASLdir, "/root/.sasl2") < 0) + goto cleanup; + DO_TEST("graphics-vnc-sasl", QEMU_CAPS_VNC, QEMU_CAPS_VGA); driver.config->vncTLS = 1; driver.config->vncTLSx509verify = 1; @@ -974,6 +978,7 @@ mymain(void) DO_TEST("pci-autoadd-addr", QEMU_CAPS_DEVICE, QEMU_CAPS_DEVICE_PCI_BRIDGE); DO_TEST("pci-autoadd-idx", QEMU_CAPS_DEVICE, QEMU_CAPS_DEVICE_PCI_BRIDGE); +cleanup: virObjectUnref(driver.config); virObjectUnref(driver.caps); virObjectUnref(driver.xmlopt); diff --git a/tests/qemuxmlnstest.c b/tests/qemuxmlnstest.c index cd493e3..42d75dd 100644 --- a/tests/qemuxmlnstest.c +++ b/tests/qemuxmlnstest.c @@ -21,6 +21,8 @@ # include "testutilsqemu.h" # include "virstring.h" +# define VIR_FROM_THIS VIR_FROM_NONE + static const char *abs_top_srcdir; static virQEMUDriver driver; @@ -68,7 +70,7 @@ static int testCompareXMLToArgvFiles(const char *xml, * detects such paths, strips the extra '/' and makes the path absolute. */ if (vmdef->emulator && STRPREFIX(vmdef->emulator, "/.")) { - if (!(emulator = strdup(vmdef->emulator + 1))) + if (VIR_STRDUP(emulator, vmdef->emulator + 1) < 0) goto fail; VIR_FREE(vmdef->emulator); vmdef->emulator = NULL; diff --git a/tests/securityselinuxhelper.c b/tests/securityselinuxhelper.c index 647b841..1feed1c 100644 --- a/tests/securityselinuxhelper.c +++ b/tests/securityselinuxhelper.c @@ -28,6 +28,9 @@ # include <attr/xattr.h> #endif +#include "virstring.h" + +#define VIR_FROM_THIS VIR_FROM_NONE /* * The kernel policy will not allow us to arbitrarily change @@ -43,7 +46,7 @@ int getcon_raw(security_context_t *context) errno = EINVAL; return -1; } - if (!(*context = strdup(getenv("FAKE_CONTEXT")))) + if (VIR_STRDUP(*context, getenv("FAKE_CONTEXT")) < 0) return -1; return 0; } @@ -65,7 +68,7 @@ int getpidcon_raw(pid_t pid, security_context_t *context) errno = EINVAL; return -1; } - if (!(*context = strdup(getenv("FAKE_CONTEXT")))) + if (VIR_STRDUP(*context, getenv("FAKE_CONTEXT")) < 0) return -1; return 0; } diff --git a/tests/securityselinuxlabeltest.c b/tests/securityselinuxlabeltest.c index e270a76..48f0c5f 100644 --- a/tests/securityselinuxlabeltest.c +++ b/tests/securityselinuxlabeltest.c @@ -116,7 +116,7 @@ testSELinuxLoadFileList(const char *testname, goto cleanup; } if (*tmp != '\0' && *tmp != '\n') { - if (!(context = strdup(tmp))) { + if (VIR_STRDUP(context, tmp) < 0) { VIR_FREE(line); VIR_FREE(file); virReportOOMError(); diff --git a/tests/securityselinuxtest.c b/tests/securityselinuxtest.c index dd4cd11..481bb0d 100644 --- a/tests/securityselinuxtest.c +++ b/tests/securityselinuxtest.c @@ -80,12 +80,10 @@ testBuildDomainDef(bool dynamic, def->seclabels[0] = secdef; def->seclabels[0]->type = dynamic ? VIR_DOMAIN_SECLABEL_DYNAMIC : VIR_DOMAIN_SECLABEL_STATIC; - if (label && - !(def->seclabels[0]->label = strdup(label))) + if (label && VIR_STRDUP(def->seclabels[0]->label, label) < 0) goto no_memory; - if (baselabel && - !(def->seclabels[0]->baselabel = strdup(baselabel))) + if (baselabel && VIR_STRDUP(def->seclabels[0]->baselabel, baselabel) < 0) goto no_memory; return def; diff --git a/tests/storagebackendsheepdogtest.c b/tests/storagebackendsheepdogtest.c index 8800acb..19a6e71 100644 --- a/tests/storagebackendsheepdogtest.c +++ b/tests/storagebackendsheepdogtest.c @@ -56,8 +56,7 @@ test_node_info_parser(collie_test test, char *poolxml) if (!(pool = virStoragePoolDefParseString(poolXmlData))) goto cleanup; - output = strdup(test.output); - if (!output) + if (VIR_STRDUP(output, test.output) < 0) goto cleanup; if (virStorageBackendSheepdogParseNodeInfo(pool, output) != @@ -101,8 +100,7 @@ test_vdi_list_parser(collie_test test, char *poolxml, char *volxml) if (!(vol = virStorageVolDefParseString(pool, volXmlData))) goto cleanup; - output = strdup(test.output); - if (!output) + if (VIR_STRDUP(output, test.output) < 0) goto cleanup; if (virStorageBackendSheepdogParseVdiList(vol, output) != diff --git a/tests/testutils.c b/tests/testutils.c index b0806de..e2d8432 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -512,7 +512,9 @@ virtTestLogContentAndReset(void) if (virBufferError(&testLog.buf)) return NULL; ret = virBufferContentAndReset(&testLog.buf); - return ret ? ret : strdup(""); + if (!ret && VIR_STRDUP(ret, "") < 0) + virReportOOMError(); + return ret; } #if TEST_OOM_TRACE diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c index fba17a3..68bfb49 100644 --- a/tests/testutilsqemu.c +++ b/tests/testutilsqemu.c @@ -8,6 +8,9 @@ # include "cpu_conf.h" # include "qemu/qemu_driver.h" # include "qemu/qemu_domain.h" +# include "virstring.h" + +# define VIR_FROM_THIS VIR_FROM_NONE static virCapsGuestMachinePtr *testQemuAllocMachines(int *nmachines) { @@ -38,7 +41,7 @@ static virCapsGuestMachinePtr *testQemuAllocNewerMachines(int *nmachines) "pc-0.11", "pc", "pc-0.10", "isapc" }; - if ((canonical = strdup(x86_machines[0])) == NULL) + if (VIR_STRDUP(canonical, x86_machines[0]) < 0) return NULL; machines = virCapabilitiesAllocMachines(x86_machines, diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c index 4777fae..27f24cb 100644 --- a/tests/vircgrouptest.c +++ b/tests/vircgrouptest.c @@ -501,7 +501,7 @@ mymain(void) int ret = 0; char *fakesysfsdir; - if (!(fakesysfsdir = strdup(FAKESYSFSDIRTEMPLATE))) { + if (VIR_STRDUP(fakesysfsdir, FAKESYSFSDIRTEMPLATE) < 0) { fprintf(stderr, "Out of memory\n"); abort(); } diff --git a/tests/virnetmessagetest.c b/tests/virnetmessagetest.c index 96defe4..7e81ef0 100644 --- a/tests/virnetmessagetest.c +++ b/tests/virnetmessagetest.c @@ -27,7 +27,7 @@ #include "virerror.h" #include "viralloc.h" #include "virlog.h" - +#include "virstring.h" #include "rpc/virnetmessage.h" #define VIR_FROM_THIS VIR_FROM_RPC @@ -236,18 +236,15 @@ static int testMessagePayloadEncode(const void *args ATTRIBUTE_UNUSED) err.domain = VIR_FROM_RPC; err.level = VIR_ERR_ERROR; - if (VIR_ALLOC(err.message) < 0) - goto cleanup; - *err.message = strdup("Hello World"); - if (VIR_ALLOC(err.str1) < 0) - goto cleanup; - *err.str1 = strdup("One"); - if (VIR_ALLOC(err.str2) < 0) - goto cleanup; - *err.str2 = strdup("Two"); - if (VIR_ALLOC(err.str3) < 0) + if (VIR_ALLOC(err.message) < 0 || + VIR_STRDUP(*err.message, "Hello World") < 0 || + VIR_ALLOC(err.str1) < 0 || + VIR_STRDUP(*err.str1, "One") < 0 || + VIR_ALLOC(err.str2) < 0 || + VIR_STRDUP(*err.str2, "Two") < 0 || + VIR_ALLOC(err.str3) < 0 || + VIR_STRDUP(*err.str3, "Three") < 0) goto cleanup; - *err.str3 = strdup("Three"); err.int1 = 1; err.int2 = 2; diff --git a/tests/vmx2xmltest.c b/tests/vmx2xmltest.c index bd7cbc6..db41926 100644 --- a/tests/vmx2xmltest.c +++ b/tests/vmx2xmltest.c @@ -13,6 +13,8 @@ # include "vmx/vmx.h" # include "virstring.h" +# define VIR_FROM_THIS VIR_FROM_NONE + static virCapsPtr caps; static virDomainXMLOptionPtr xmlopt; static virVMXContext ctx; @@ -159,11 +161,8 @@ testParseVMXFileName(const char *fileName, void *opaque ATTRIBUTE_UNUSED) if (STRPREFIX(fileName, "/vmfs/volumes/")) { /* Found absolute path referencing a file inside a datastore */ - copyOfFileName = strdup(fileName); - - if (copyOfFileName == NULL) { + if (VIR_STRDUP(copyOfFileName, fileName) < 0) goto cleanup; - } /* Expected format: '/vmfs/volumes/<datastore>/<path>' */ if ((tmp = STRSKIP(copyOfFileName, "/vmfs/volumes/")) == NULL || @@ -177,7 +176,8 @@ testParseVMXFileName(const char *fileName, void *opaque ATTRIBUTE_UNUSED) goto cleanup; } else if (STRPREFIX(fileName, "/")) { /* Found absolute path referencing a file outside a datastore */ - src = strdup(fileName); + if (VIR_STRDUP(src, fileName) < 0) + goto cleanup; } else if (strchr(fileName, '/') != NULL) { /* Found relative path, this is not supported */ src = NULL; diff --git a/tests/xml2vmxtest.c b/tests/xml2vmxtest.c index 38b5a4d..46180fd 100644 --- a/tests/xml2vmxtest.c +++ b/tests/xml2vmxtest.c @@ -13,6 +13,8 @@ # include "vmx/vmx.h" # include "virstring.h" +# define VIR_FROM_THIS VIR_FROM_NONE + static virCapsPtr caps; static virVMXContext ctx; static virDomainXMLOptionPtr xmlopt; @@ -169,11 +171,8 @@ testFormatVMXFileName(const char *src, void *opaque ATTRIBUTE_UNUSED) if (STRPREFIX(src, "[")) { /* Found potential datastore path */ - copyOfDatastorePath = strdup(src); - - if (copyOfDatastorePath == NULL) { + if (VIR_STRDUP(copyOfDatastorePath, src) < 0) goto cleanup; - } /* Expected format: '[<datastore>] <path>' where <path> is optional */ if ((tmp = STRSKIP(copyOfDatastorePath, "[")) == NULL || *tmp == ']' || @@ -194,7 +193,8 @@ testFormatVMXFileName(const char *src, void *opaque ATTRIBUTE_UNUSED) goto cleanup; } else if (STRPREFIX(src, "/")) { /* Found absolute path */ - absolutePath = strdup(src); + if (VIR_STRDUP(absolutePath, src) < 0) + goto cleanup; } else { /* Found relative path, this is not supported */ goto cleanup; -- 1.8.1.5

--- src/datatypes.c | 25 +++++++++++++------------ src/libvirt.c | 9 +++++---- src/nodeinfo.c | 3 +-- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/datatypes.c b/src/datatypes.c index d3cf5f2..71aab04 100644 --- a/src/datatypes.c +++ b/src/datatypes.c @@ -27,6 +27,7 @@ #include "virlog.h" #include "viralloc.h" #include "viruuid.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_NONE @@ -225,7 +226,7 @@ virGetDomain(virConnectPtr conn, const char *name, const unsigned char *uuid) if (!(ret = virObjectNew(virDomainClass))) return NULL; - if (!(ret->name = strdup(name))) + if (VIR_STRDUP(ret->name, name) < 0) goto no_memory; ret->conn = virObjectRef(conn); @@ -297,7 +298,7 @@ virGetNetwork(virConnectPtr conn, const char *name, const unsigned char *uuid) if (!(ret = virObjectNew(virNetworkClass))) return NULL; - if (!(ret->name = strdup(name))) + if (VIR_STRDUP(ret->name, name) < 0) goto no_memory; ret->conn = virObjectRef(conn); @@ -372,9 +373,9 @@ virGetInterface(virConnectPtr conn, const char *name, const char *mac) if (!(ret = virObjectNew(virInterfaceClass))) return NULL; - if (!(ret->name = strdup(name))) + if (VIR_STRDUP(ret->name, name) < 0) goto no_memory; - if (!(ret->mac = strdup(mac))) + if (VIR_STRDUP(ret->mac, mac) < 0) goto no_memory; ret->conn = virObjectRef(conn); @@ -446,7 +447,7 @@ virGetStoragePool(virConnectPtr conn, const char *name, if (!(ret = virObjectNew(virStoragePoolClass))) return NULL; - if (!(ret->name = strdup(name))) + if (VIR_STRDUP(ret->name, name) < 0) goto no_memory; ret->conn = virObjectRef(conn); @@ -530,11 +531,11 @@ virGetStorageVol(virConnectPtr conn, const char *pool, const char *name, if (!(ret = virObjectNew(virStorageVolClass))) return NULL; - if (!(ret->pool = strdup(pool))) + if (VIR_STRDUP(ret->pool, pool) < 0) goto no_memory; - if (!(ret->name = strdup(name))) + if (VIR_STRDUP(ret->name, name) < 0) goto no_memory; - if (!(ret->key = strdup(key))) + if (VIR_STRDUP(ret->key, key) < 0) goto no_memory; ret->conn = virObjectRef(conn); @@ -610,7 +611,7 @@ virGetNodeDevice(virConnectPtr conn, const char *name) if (!(ret = virObjectNew(virNodeDeviceClass))) return NULL; - if (!(ret->name = strdup(name))) + if (VIR_STRDUP(ret->name, name) < 0) goto no_memory; ret->conn = virObjectRef(conn); @@ -680,7 +681,7 @@ virGetSecret(virConnectPtr conn, const unsigned char *uuid, memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN); ret->usageType = usageType; - if (!(ret->usageID = strdup(usageID))) + if (VIR_STRDUP(ret->usageID, usageID) < 0) goto no_memory; ret->conn = virObjectRef(conn); @@ -775,7 +776,7 @@ virGetNWFilter(virConnectPtr conn, const char *name, if (!(ret = virObjectNew(virNWFilterClass))) return NULL; - if (!(ret->name = strdup(name))) + if (VIR_STRDUP(ret->name, name) < 0) goto no_memory; memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN); @@ -832,7 +833,7 @@ virGetDomainSnapshot(virDomainPtr domain, const char *name) if (!(ret = virObjectNew(virDomainSnapshotClass))) return NULL; - if (!(ret->name = strdup(name))) + if (VIR_STRDUP(ret->name, name) < 0) goto no_memory; ret->domain = virObjectRef(domain); diff --git a/src/libvirt.c b/src/libvirt.c index 15b37a3..1ebb2c5 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -212,11 +212,12 @@ static int virConnectAuthCallbackDefault(virConnectCredentialPtr cred, } if (cred[i].type != VIR_CRED_EXTERNAL) { + int rc; if (STREQ(bufptr, "") && cred[i].defresult) - cred[i].result = strdup(cred[i].defresult); + rc = VIR_STRDUP(cred[i].result, cred[i].defresult); else - cred[i].result = strdup(bufptr); - if (!cred[i].result) + rc = VIR_STRDUP(cred[i].result, bufptr); + if (rc < 0) return -1; cred[i].resultlen = strlen(cred[i].result); } @@ -1045,7 +1046,7 @@ 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 = strdup(offset+1))) { + if (VIR_STRDUP(*uri, offset+1) < 0) { virReportOOMError(); return -1; } diff --git a/src/nodeinfo.c b/src/nodeinfo.c index 95c2f33..e3a0329 100644 --- a/src/nodeinfo.c +++ b/src/nodeinfo.c @@ -984,8 +984,7 @@ int nodeGetMemoryStats(virConnectPtr conn ATTRIBUTE_UNUSED, FILE *meminfo; if (cellNum == VIR_NODE_MEMORY_STATS_ALL_CELLS) { - meminfo_path = strdup(MEMINFO_PATH); - if (!meminfo_path) { + if (VIR_STRDUP(meminfo_path, MEMINFO_PATH) < 0) { virReportOOMError(); return -1; } -- 1.8.1.5

--- cfg.mk | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cfg.mk b/cfg.mk index d499ded..4c6d85c 100644 --- a/cfg.mk +++ b/cfg.mk @@ -383,6 +383,11 @@ sc_prohibit_asprintf: halt='use virAsprintf, not as'printf \ $(_sc_search_regexp) +sc_prohibit_strdup: + @prohibit='\<strn?dup\> *\(' \ + halt='use VIR_STRUP, not strdup' \ + $(_sc_search_regexp) + # Prefer virSetUIDGID. sc_prohibit_setuid: @prohibit='\<set(re)?[ug]id\> *\(' \ @@ -860,6 +865,9 @@ exclude_file_name_regexp--sc_prohibit_always_true_header_tests = \ exclude_file_name_regexp--sc_prohibit_asprintf = \ ^(bootstrap.conf$$|src/util/virstring\.c$$|examples/domain-events/events-c/event-test\.c$$|tests/vircgroupmock\.c$$) +exclude_file_name_regexp--sc_prohibit_strdup = \ + ^(docs/|examples/|python/|src/util/virstring\.c$$|tools/virsh\.c$$) + exclude_file_name_regexp--sc_prohibit_close = \ (\.p[yl]$$|^docs/|^(src/util/virfile\.c|src/libvirt\.c|tests/vircgroupmock\.c)$$) -- 1.8.1.5

On 04/29/2013 09:50 AM, Michal Privoznik wrote:
--- cfg.mk | 8 ++++++++ 1 file changed, 8 insertions(+)
diff --git a/cfg.mk b/cfg.mk index d499ded..4c6d85c 100644 --- a/cfg.mk +++ b/cfg.mk @@ -383,6 +383,11 @@ sc_prohibit_asprintf: halt='use virAsprintf, not as'printf \ $(_sc_search_regexp)
+sc_prohibit_strdup: + @prohibit='\<strn?dup\> *\(' \ + halt='use VIR_STRUP, not strdup' \
s/STRUP/STRDUP/ Do there need to be separate rules for STRDUP and STRNDUP?
+ $(_sc_search_regexp) + # Prefer virSetUIDGID. sc_prohibit_setuid: @prohibit='\<set(re)?[ug]id\> *\(' \ @@ -860,6 +865,9 @@ exclude_file_name_regexp--sc_prohibit_always_true_header_tests = \ exclude_file_name_regexp--sc_prohibit_asprintf = \ ^(bootstrap.conf$$|src/util/virstring\.c$$|examples/domain-events/events-c/event-test\.c$$|tests/vircgroupmock\.c$$)
+exclude_file_name_regexp--sc_prohibit_strdup = \ + ^(docs/|examples/|python/|src/util/virstring\.c$$|tools/virsh\.c$$) + exclude_file_name_regexp--sc_prohibit_close = \ (\.p[yl]$$|^docs/|^(src/util/virfile\.c|src/libvirt\.c|tests/vircgroupmock\.c)$$)

On 04/30/2013 07:03 AM, John Ferlan wrote:
On 04/29/2013 09:50 AM, Michal Privoznik wrote:
--- cfg.mk | 8 ++++++++ 1 file changed, 8 insertions(+)
diff --git a/cfg.mk b/cfg.mk index d499ded..4c6d85c 100644 --- a/cfg.mk +++ b/cfg.mk @@ -383,6 +383,11 @@ sc_prohibit_asprintf: halt='use virAsprintf, not as'printf \ $(_sc_search_regexp)
+sc_prohibit_strdup: + @prohibit='\<strn?dup\> *\(' \ + halt='use VIR_STRUP, not strdup' \
s/STRUP/STRDUP/
Do there need to be separate rules for STRDUP and STRNDUP?
Nah, one rule for both functions at once is good enough. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

Moreover, the original virVasprintf and virAsprintf functions will report OOM error. The new behaviour is not enabled for now as the rest of code needs to be adapted so we don't report an error twice. --- HACKING | 4 ++++ docs/hacking.html.in | 6 ++++++ src/libvirt_private.syms | 2 ++ src/util/viraudit.c | 4 +--- src/util/vircommand.c | 4 ++-- src/util/virerror.c | 2 +- src/util/virlog.c | 2 +- src/util/virstring.c | 44 ++++++++++++++++++++++++++++++++++++++++---- src/util/virstring.h | 4 ++++ tools/virsh.c | 6 +++--- 10 files changed, 64 insertions(+), 14 deletions(-) diff --git a/HACKING b/HACKING index 842f476..0f681ce 100644 --- a/HACKING +++ b/HACKING @@ -818,6 +818,10 @@ virAsprintf, in util.h: This makes it so gcc's -Wformat and -Wformat-security options can do their jobs and cross-check format strings with the number and types of arguments. +Moreover, this function automatically reports out-of-memory error if there's +any. In case you want to suppress such behaviour, which should be very rare +case, you can use virAspritnfQuiet() or virVasprintfQuiet(). + When printing to a string, consider using virBuffer for incremental allocations, virAsprintf for a one-shot allocation, and snprintf for fixed-width buffers. Do not use sprintf, even if you can prove the buffer diff --git a/docs/hacking.html.in b/docs/hacking.html.in index 1263607..a9b78ba 100644 --- a/docs/hacking.html.in +++ b/docs/hacking.html.in @@ -973,6 +973,12 @@ </p> <p> + Moreover, this function automatically reports out-of-memory error if + there's any. In case you want to suppress such behaviour, which should be + very rare case, you can use virAspritnfQuiet() or virVasprintfQuiet(). + </p> + + <p> When printing to a string, consider using virBuffer for incremental allocations, virAsprintf for a one-shot allocation, and snprintf for fixed-width buffers. Do not use sprintf, even diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index d4cb4a3..8c1d3ab 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1747,6 +1747,7 @@ virStorageFileResize; # util/virstring.h virArgvToString; virAsprintf; +virAsprintfQuiet; virSkipSpaces; virSkipSpacesAndBackslash; virSkipSpacesBackwards; @@ -1767,6 +1768,7 @@ virStrToLong_ul; virStrToLong_ull; virTrimSpaces; virVasprintf; +virVasprintfQuiet; # util/virsysinfo.h diff --git a/src/util/viraudit.c b/src/util/viraudit.c index 5dd4e1f..f05547e 100644 --- a/src/util/viraudit.c +++ b/src/util/viraudit.c @@ -96,10 +96,8 @@ void virAuditSend(const char *filename, #endif va_start(args, fmt); - if (virVasprintf(&str, fmt, args) < 0) { + if (virVasprintfQuiet(&str, fmt, args) < 0) VIR_WARN("Out of memory while formatting audit message"); - str = NULL; - } va_end(args); if (auditlog && str) { diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 460e25b..b611048 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -1163,7 +1163,7 @@ virCommandAddEnvFormat(virCommandPtr cmd, const char *format, ...) return; va_start(list, format); - if (virVasprintf(&env, format, list) < 0) { + if (virVasprintfQuiet(&env, format, list) < 0) { cmd->has_error = ENOMEM; va_end(list); return; @@ -1377,7 +1377,7 @@ virCommandAddArgFormat(virCommandPtr cmd, const char *format, ...) return; va_start(list, format); - if (virVasprintf(&arg, format, list) < 0) { + if (virVasprintfQuiet(&arg, format, list) < 0) { cmd->has_error = ENOMEM; va_end(list); return; diff --git a/src/util/virerror.c b/src/util/virerror.c index 8761a72..2b3a910 100644 --- a/src/util/virerror.c +++ b/src/util/virerror.c @@ -650,7 +650,7 @@ virRaiseErrorFull(const char *filename ATTRIBUTE_UNUSED, } else { va_list ap; va_start(ap, fmt); - ignore_value(virVasprintf(&str, fmt, ap)); + virVasprintfQuiet(&str, fmt, ap); va_end(ap); } diff --git a/src/util/virlog.c b/src/util/virlog.c index 921ffc5..cc3cfa7 100644 --- a/src/util/virlog.c +++ b/src/util/virlog.c @@ -828,7 +828,7 @@ virLogVMessage(virLogSource source, /* * serialize the error message, add level and timestamp */ - if (virVasprintf(&str, fmt, vargs) < 0) { + if (virVasprintfQuiet(&str, fmt, vargs) < 0) { goto cleanup; } diff --git a/src/util/virstring.c b/src/util/virstring.c index 2f672bc..2416c43 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -325,12 +325,12 @@ virStrToDouble(char const *s, } /** - * virVasprintf + * virVasprintfQuiet * * like glibc's vasprintf but makes sure *strp == NULL on failure */ int -virVasprintf(char **strp, const char *fmt, va_list list) +virVasprintfQuiet(char **strp, const char *fmt, va_list list) { int ret; @@ -341,9 +341,27 @@ virVasprintf(char **strp, const char *fmt, va_list list) } /** + * virVasprintf + * + * like glibc's vasprintf but makes sure *strp == NULL on failure and reports + * an OOM error. + */ +int +virVasprintf(char **strp, const char *fmt, va_list list) +{ + int ret; + + if ((ret = virVasprintfQuiet(strp, fmt, list)) < 0) + virReportOOMError(); + + return ret; +} + +/** * virAsprintf * - * like glibc's_asprintf but makes sure *strp == NULL on failure + * like glibc's_asprintf but makes sure *strp == NULL on failure and reports + * and OOM error. */ int virAsprintf(char **strp, const char *fmt, ...) @@ -352,7 +370,25 @@ virAsprintf(char **strp, const char *fmt, ...) int ret; va_start(ap, fmt); - ret = virVasprintf(strp, fmt, ap); + /* XXX Don't report OOM error for now, unless all code is adapted. */ + ret = virVasprintfQuiet(strp, fmt, ap); + va_end(ap); + return ret; +} + +/** + * virAsprintfQuiet + * + * like glibc's_asprintf but makes sure *strp == NULL on failure + */ +int +virAsprintfQuiet(char **strp, const char *fmt, ...) +{ + va_list ap; + int ret; + + va_start(ap, fmt); + ret = virVasprintfQuiet(strp, fmt, ap); va_end(ap); return ret; } diff --git a/src/util/virstring.h b/src/util/virstring.h index 620efba..908e13a 100644 --- a/src/util/virstring.h +++ b/src/util/virstring.h @@ -79,9 +79,13 @@ void virSkipSpacesBackwards(const char *str, char **endp) int virAsprintf(char **strp, const char *fmt, ...) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_FMT_PRINTF(2, 3) ATTRIBUTE_RETURN_CHECK; +int virAsprintfQuiet(char **strp, const char *fmt, ...) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_FMT_PRINTF(2, 3); int virVasprintf(char **strp, const char *fmt, va_list list) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_FMT_PRINTF(2, 0) ATTRIBUTE_RETURN_CHECK; +int virVasprintfQuiet(char **strp, const char *fmt, va_list list) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_FMT_PRINTF(2, 0); char *virStrncpy(char *dest, const char *src, size_t n, size_t destbytes) ATTRIBUTE_RETURN_CHECK; char *virStrcpy(char *dest, const char *src, size_t destbytes) diff --git a/tools/virsh.c b/tools/virsh.c index de2e57a..a48f27b 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -2217,7 +2217,7 @@ vshDebug(vshControl *ctl, int level, const char *format, ...) va_end(ap); va_start(ap, format); - if (virVasprintf(&str, format, ap) < 0) { + if (virVasprintfQuiet(&str, format, ap) < 0) { /* Skip debug messages on low memory */ va_end(ap); return; @@ -2237,7 +2237,7 @@ vshPrintExtra(vshControl *ctl, const char *format, ...) return; va_start(ap, format); - if (virVasprintf(&str, format, ap) < 0) { + if (virVasprintfQuiet(&str, format, ap) < 0) { vshError(ctl, "%s", _("Out of memory")); va_end(ap); return; @@ -2269,7 +2269,7 @@ vshError(vshControl *ctl, const char *format, ...) va_start(ap, format); /* We can't recursively call vshError on an OOM situation, so ignore failure here. */ - ignore_value(virVasprintf(&str, format, ap)); + virVasprintfQuiet(&str, format, ap); va_end(ap); fprintf(stderr, "%s\n", NULLSTR(str)); -- 1.8.1.5

For cases where caller doesn't want to repor an OOM error, he should use VIR_ALLOC_QUIET or variants. --- HACKING | 4 ++ docs/hacking.html.in | 6 +++ po/POTFILES.in | 1 + python/libvirt-override.c | 102 ++++++++++++++++++++++---------------------- src/esx/esx_vi.c | 3 +- src/util/viralloc.c | 95 +++++++++++++++++++++++++++++++++++------ src/util/viralloc.h | 54 ++++++++++++++++------- src/util/virbuffer.c | 8 ++-- src/util/virerror.c | 4 +- src/util/virthreadpthread.c | 2 +- tests/networkxml2conftest.c | 2 + tests/test_conf.c | 2 +- tests/xmconfigtest.c | 2 + 13 files changed, 196 insertions(+), 89 deletions(-) diff --git a/HACKING b/HACKING index 0f681ce..b7b2798 100644 --- a/HACKING +++ b/HACKING @@ -595,6 +595,10 @@ size: +These memory allocation macros report out-of-memory error automatically. In +case, you want to suppress such behavior, use their _QUIET variant, e.g. +VIR_ALLOC_QUIET, VIR_REALLOC_N_QUIET etc. + File handling ============= diff --git a/docs/hacking.html.in b/docs/hacking.html.in index a9b78ba..2d9e1cd 100644 --- a/docs/hacking.html.in +++ b/docs/hacking.html.in @@ -712,6 +712,12 @@ </li> </ul> + <p> + These memory allocation macros report out-of-memory error automatically. + In case, you want to suppress such behavior, use their _QUIET variant, e.g. + VIR_ALLOC_QUIET, VIR_REALLOC_N_QUIET etc. + </p> + <h2><a name="file_handling">File handling</a></h2> <p> diff --git a/po/POTFILES.in b/po/POTFILES.in index bf5a864..7450642 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -139,6 +139,7 @@ src/test/test_driver.c src/uml/uml_conf.c src/uml/uml_driver.c src/util/iohelper.c +src/util/viralloc.c src/util/viraudit.c src/util/virauth.c src/util/virauthconfig.c diff --git a/python/libvirt-override.c b/python/libvirt-override.c index 856789a..df40ae3 100644 --- a/python/libvirt-override.c +++ b/python/libvirt-override.c @@ -167,7 +167,7 @@ setPyVirTypedParameter(PyObject *info, return NULL; } - if (VIR_ALLOC_N(ret, size) < 0) { + if (VIR_ALLOC_N_QUIET(ret, size) < 0) { PyErr_NoMemory(); return NULL; } @@ -353,7 +353,7 @@ libvirt_virDomainBlockStatsFlags(PyObject *self ATTRIBUTE_UNUSED, if (!nparams) return PyDict_New(); - if (VIR_ALLOC_N(params, nparams) < 0) + if (VIR_ALLOC_N_QUIET(params, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -419,7 +419,7 @@ libvirt_virDomainGetCPUStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) sumparams = nparams * MIN(ncpus, 128); - if (VIR_ALLOC_N(params, sumparams) < 0) { + if (VIR_ALLOC_N_QUIET(params, sumparams) < 0) { error = PyErr_NoMemory(); goto error; } @@ -471,7 +471,7 @@ libvirt_virDomainGetCPUStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) if (nparams) { sumparams = nparams; - if (VIR_ALLOC_N(params, nparams) < 0) { + if (VIR_ALLOC_N_QUIET(params, nparams) < 0) { error = PyErr_NoMemory(); goto error; } @@ -651,7 +651,7 @@ libvirt_virDomainGetSchedulerParameters(PyObject *self ATTRIBUTE_UNUSED, if (!nparams) return PyDict_New(); - if (VIR_ALLOC_N(params, nparams) < 0) + if (VIR_ALLOC_N_QUIET(params, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -699,7 +699,7 @@ libvirt_virDomainGetSchedulerParametersFlags(PyObject *self ATTRIBUTE_UNUSED, if (!nparams) return PyDict_New(); - if (VIR_ALLOC_N(params, nparams) < 0) + if (VIR_ALLOC_N_QUIET(params, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -759,7 +759,7 @@ libvirt_virDomainSetSchedulerParameters(PyObject *self ATTRIBUTE_UNUSED, return NULL; } - if (VIR_ALLOC_N(params, nparams) < 0) + if (VIR_ALLOC_N_QUIET(params, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -835,7 +835,7 @@ libvirt_virDomainSetSchedulerParametersFlags(PyObject *self ATTRIBUTE_UNUSED, return NULL; } - if (VIR_ALLOC_N(params, nparams) < 0) + if (VIR_ALLOC_N_QUIET(params, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -909,7 +909,7 @@ libvirt_virDomainSetBlkioParameters(PyObject *self ATTRIBUTE_UNUSED, return NULL; } - if (VIR_ALLOC_N(params, nparams) < 0) + if (VIR_ALLOC_N_QUIET(params, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -969,7 +969,7 @@ libvirt_virDomainGetBlkioParameters(PyObject *self ATTRIBUTE_UNUSED, if (!nparams) return PyDict_New(); - if (VIR_ALLOC_N(params, nparams) < 0) + if (VIR_ALLOC_N_QUIET(params, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -1029,7 +1029,7 @@ libvirt_virDomainSetMemoryParameters(PyObject *self ATTRIBUTE_UNUSED, return NULL; } - if (VIR_ALLOC_N(params, nparams) < 0) + if (VIR_ALLOC_N_QUIET(params, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -1089,7 +1089,7 @@ libvirt_virDomainGetMemoryParameters(PyObject *self ATTRIBUTE_UNUSED, if (!nparams) return PyDict_New(); - if (VIR_ALLOC_N(params, nparams) < 0) + if (VIR_ALLOC_N_QUIET(params, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -1149,7 +1149,7 @@ libvirt_virDomainSetNumaParameters(PyObject *self ATTRIBUTE_UNUSED, return NULL; } - if (VIR_ALLOC_N(params, nparams) < 0) + if (VIR_ALLOC_N_QUIET(params, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -1209,7 +1209,7 @@ libvirt_virDomainGetNumaParameters(PyObject *self ATTRIBUTE_UNUSED, if (!nparams) return PyDict_New(); - if (VIR_ALLOC_N(params, nparams) < 0) + if (VIR_ALLOC_N_QUIET(params, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -1270,7 +1270,7 @@ libvirt_virDomainSetInterfaceParameters(PyObject *self ATTRIBUTE_UNUSED, return NULL; } - if (VIR_ALLOC_N(params, nparams) < 0) + if (VIR_ALLOC_N_QUIET(params, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -1331,7 +1331,7 @@ libvirt_virDomainGetInterfaceParameters(PyObject *self ATTRIBUTE_UNUSED, if (!nparams) return PyDict_New(); - if (VIR_ALLOC_N(params, nparams) < 0) + if (VIR_ALLOC_N_QUIET(params, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -1377,12 +1377,12 @@ libvirt_virDomainGetVcpus(PyObject *self ATTRIBUTE_UNUSED, if (i_retval < 0) return VIR_PY_INT_FAIL; - if (VIR_ALLOC_N(cpuinfo, dominfo.nrVirtCpu) < 0) + if (VIR_ALLOC_N_QUIET(cpuinfo, dominfo.nrVirtCpu) < 0) return PyErr_NoMemory(); cpumaplen = VIR_CPU_MAPLEN(cpunum); if (xalloc_oversized(dominfo.nrVirtCpu, cpumaplen) || - VIR_ALLOC_N(cpumap, dominfo.nrVirtCpu * cpumaplen) < 0) { + VIR_ALLOC_N_QUIET(cpumap, dominfo.nrVirtCpu * cpumaplen) < 0) { error = PyErr_NoMemory(); goto cleanup; } @@ -1504,7 +1504,7 @@ libvirt_virDomainPinVcpu(PyObject *self ATTRIBUTE_UNUSED, } cpumaplen = VIR_CPU_MAPLEN(cpunum); - if (VIR_ALLOC_N(cpumap, cpumaplen) < 0) + if (VIR_ALLOC_N_QUIET(cpumap, cpumaplen) < 0) return PyErr_NoMemory(); for (i = 0; i < tuple_size; i++) { @@ -1568,7 +1568,7 @@ libvirt_virDomainPinVcpuFlags(PyObject *self ATTRIBUTE_UNUSED, } cpumaplen = VIR_CPU_MAPLEN(cpunum); - if (VIR_ALLOC_N(cpumap, cpumaplen) < 0) + if (VIR_ALLOC_N_QUIET(cpumap, cpumaplen) < 0) return PyErr_NoMemory(); for (i = 0; i < tuple_size; i++) { @@ -1628,7 +1628,7 @@ libvirt_virDomainGetVcpuPinInfo(PyObject *self ATTRIBUTE_UNUSED, cpumaplen = VIR_CPU_MAPLEN(cpunum); if (xalloc_oversized(dominfo.nrVirtCpu, cpumaplen) || - VIR_ALLOC_N(cpumaps, dominfo.nrVirtCpu * cpumaplen) < 0) + VIR_ALLOC_N_QUIET(cpumaps, dominfo.nrVirtCpu * cpumaplen) < 0) goto cleanup; LIBVIRT_BEGIN_ALLOW_THREADS; @@ -1696,7 +1696,7 @@ libvirt_virDomainPinEmulator(PyObject *self ATTRIBUTE_UNUSED, if ((tuple_size = PyTuple_Size(pycpumap)) == -1) return NULL; - if (VIR_ALLOC_N(cpumap, cpumaplen) < 0) + if (VIR_ALLOC_N_QUIET(cpumap, cpumaplen) < 0) return PyErr_NoMemory(); for (i = 0; i < tuple_size; i++) { @@ -1755,7 +1755,7 @@ libvirt_virDomainGetEmulatorPinInfo(PyObject *self ATTRIBUTE_UNUSED, cpumaplen = VIR_CPU_MAPLEN(cpunum); - if (VIR_ALLOC_N(cpumap, cpumaplen) < 0) + if (VIR_ALLOC_N_QUIET(cpumap, cpumaplen) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -2030,7 +2030,7 @@ libvirt_virConnectOpenAuth(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { auth.ncredtype = PyList_Size(pycredtype); if (auth.ncredtype) { int i; - if (VIR_ALLOC_N(auth.credtype, auth.ncredtype) < 0) + if (VIR_ALLOC_N_QUIET(auth.credtype, auth.ncredtype) < 0) return VIR_PY_NONE; for (i = 0 ; i < auth.ncredtype ; i++) { PyObject *val; @@ -2158,7 +2158,7 @@ libvirt_virConnectListDomainsID(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - if (VIR_ALLOC_N(ids, c_retval) < 0) + if (VIR_ALLOC_N_QUIET(ids, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; @@ -2249,7 +2249,7 @@ libvirt_virConnectListDefinedDomains(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - if (VIR_ALLOC_N(names, c_retval) < 0) + if (VIR_ALLOC_N_QUIET(names, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virConnectListDefinedDomains(conn, names, c_retval); @@ -2296,7 +2296,7 @@ libvirt_virDomainSnapshotListNames(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - if (VIR_ALLOC_N(names, c_retval) < 0) + if (VIR_ALLOC_N_QUIET(names, c_retval) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virDomainSnapshotListNames(dom, names, c_retval, flags); @@ -2396,7 +2396,7 @@ libvirt_virDomainSnapshotListChildrenNames(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - if (VIR_ALLOC_N(names, c_retval) < 0) + if (VIR_ALLOC_N_QUIET(names, c_retval) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virDomainSnapshotListChildrenNames(snap, names, c_retval, @@ -2728,7 +2728,7 @@ libvirt_virConnectListNetworks(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - if (VIR_ALLOC_N(names, c_retval) < 0) + if (VIR_ALLOC_N_QUIET(names, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virConnectListNetworks(conn, names, c_retval); @@ -2773,7 +2773,7 @@ libvirt_virConnectListDefinedNetworks(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - if (VIR_ALLOC_N(names, c_retval) < 0) + if (VIR_ALLOC_N_QUIET(names, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virConnectListDefinedNetworks(conn, names, c_retval); @@ -2981,7 +2981,7 @@ libvirt_virNodeGetCellsFreeMemory(PyObject *self ATTRIBUTE_UNUSED, PyObject *arg return VIR_PY_NONE; conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn); - if (VIR_ALLOC_N(freeMems, maxCells) < 0) + if (VIR_ALLOC_N_QUIET(freeMems, maxCells) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; @@ -3025,7 +3025,7 @@ libvirt_virNodeGetCPUStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) return VIR_PY_NONE; if (nparams) { - if (VIR_ALLOC_N(stats, nparams) < 0) + if (VIR_ALLOC_N_QUIET(stats, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -3088,7 +3088,7 @@ libvirt_virNodeGetMemoryStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) return VIR_PY_NONE; if (nparams) { - if (VIR_ALLOC_N(stats, nparams) < 0) + if (VIR_ALLOC_N_QUIET(stats, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -3148,7 +3148,7 @@ libvirt_virConnectListStoragePools(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - if (VIR_ALLOC_N(names, c_retval) < 0) + if (VIR_ALLOC_N_QUIET(names, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virConnectListStoragePools(conn, names, c_retval); @@ -3201,7 +3201,7 @@ libvirt_virConnectListDefinedStoragePools(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - if (VIR_ALLOC_N(names, c_retval) < 0) + if (VIR_ALLOC_N_QUIET(names, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virConnectListDefinedStoragePools(conn, names, c_retval); @@ -3300,7 +3300,7 @@ libvirt_virStoragePoolListVolumes(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - if (VIR_ALLOC_N(names, c_retval) < 0) + if (VIR_ALLOC_N_QUIET(names, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virStoragePoolListVolumes(pool, names, c_retval); @@ -3561,7 +3561,7 @@ libvirt_virNodeListDevices(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - if (VIR_ALLOC_N(names, c_retval) < 0) + if (VIR_ALLOC_N_QUIET(names, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virNodeListDevices(conn, cap, names, c_retval, flags); @@ -3651,7 +3651,7 @@ libvirt_virNodeDeviceListCaps(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - if (VIR_ALLOC_N(names, c_retval) < 0) + if (VIR_ALLOC_N_QUIET(names, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virNodeDeviceListCaps(dev, names, c_retval); @@ -3770,7 +3770,7 @@ libvirt_virConnectListSecrets(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - if (VIR_ALLOC_N(uuids, c_retval) < 0) + if (VIR_ALLOC_N_QUIET(uuids, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virConnectListSecrets(conn, uuids, c_retval); @@ -3989,7 +3989,7 @@ libvirt_virConnectListNWFilters(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - if (VIR_ALLOC_N(uuids, c_retval) < 0) + if (VIR_ALLOC_N_QUIET(uuids, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virConnectListNWFilters(conn, uuids, c_retval); @@ -4080,7 +4080,7 @@ libvirt_virConnectListInterfaces(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - if (VIR_ALLOC_N(names, c_retval) < 0) + if (VIR_ALLOC_N_QUIET(names, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virConnectListInterfaces(conn, names, c_retval); @@ -4134,7 +4134,7 @@ libvirt_virConnectListDefinedInterfaces(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - if (VIR_ALLOC_N(names, c_retval) < 0) + if (VIR_ALLOC_N_QUIET(names, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virConnectListDefinedInterfaces(conn, names, c_retval); @@ -4234,7 +4234,7 @@ libvirt_virConnectBaselineCPU(PyObject *self ATTRIBUTE_UNUSED, int i; ncpus = PyList_Size(list); - if (VIR_ALLOC_N(xmlcpus, ncpus) < 0) + if (VIR_ALLOC_N_QUIET(xmlcpus, ncpus) < 0) return VIR_PY_INT_FAIL; for (i = 0; i < ncpus; i++) { @@ -4420,7 +4420,7 @@ libvirt_virDomainSetBlockIoTune(PyObject *self ATTRIBUTE_UNUSED, return NULL; } - if (VIR_ALLOC_N(params, nparams) < 0) + if (VIR_ALLOC_N_QUIET(params, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -4481,7 +4481,7 @@ libvirt_virDomainGetBlockIoTune(PyObject *self ATTRIBUTE_UNUSED, if (!nparams) return PyDict_New(); - if (VIR_ALLOC_N(params, nparams) < 0) + if (VIR_ALLOC_N_QUIET(params, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -4524,7 +4524,7 @@ libvirt_virDomainGetDiskErrors(PyObject *self ATTRIBUTE_UNUSED, ndisks = count; if (ndisks) { - if (VIR_ALLOC_N(disks, ndisks) < 0) + if (VIR_ALLOC_N_QUIET(disks, ndisks) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; @@ -6345,7 +6345,7 @@ libvirt_virStreamRecv(PyObject *self ATTRIBUTE_UNUSED, } stream = PyvirStream_Get(pyobj_stream); - if (VIR_ALLOC_N(buf, nbytes+1 > 0 ? nbytes+1 : 1) < 0) + if (VIR_ALLOC_N_QUIET(buf, nbytes+1 > 0 ? nbytes+1 : 1) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; @@ -6509,7 +6509,7 @@ libvirt_virDomainBlockPeek(PyObject *self ATTRIBUTE_UNUSED, domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain); - if (VIR_ALLOC_N(buf, size) < 0) + if (VIR_ALLOC_N_QUIET(buf, size) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; @@ -6546,7 +6546,7 @@ libvirt_virDomainMemoryPeek(PyObject *self ATTRIBUTE_UNUSED, domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain); - if (VIR_ALLOC_N(buf, size) < 0) + if (VIR_ALLOC_N_QUIET(buf, size) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; @@ -6606,7 +6606,7 @@ libvirt_virNodeSetMemoryParameters(PyObject *self ATTRIBUTE_UNUSED, return NULL; } - if (VIR_ALLOC_N(params, nparams) < 0) + if (VIR_ALLOC_N_QUIET(params, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -6666,7 +6666,7 @@ libvirt_virNodeGetMemoryParameters(PyObject *self ATTRIBUTE_UNUSED, if (!nparams) return PyDict_New(); - if (VIR_ALLOC_N(params, nparams) < 0) + if (VIR_ALLOC_N_QUIET(params, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c index 7245fbb..cc247b4 100644 --- a/src/esx/esx_vi.c +++ b/src/esx/esx_vi.c @@ -1760,7 +1760,8 @@ esxVI_Alloc(void **ptrptr, size_t size) return -1; } - if (virAllocN(ptrptr, size, 1) < 0) { + if (virAllocN(ptrptr, size, 1, false, VIR_FROM_THIS, + __FILE__, __FUNCTION__, __LINE__) < 0) { virReportOOMError(); return -1; } diff --git a/src/util/viralloc.c b/src/util/viralloc.c index 8f219bf..a22d763 100644 --- a/src/util/viralloc.c +++ b/src/util/viralloc.c @@ -25,6 +25,7 @@ #include "viralloc.h" #include "virlog.h" +#include "virerror.h" #if TEST_OOM static int testMallocNext = 0; @@ -105,6 +106,11 @@ void virAllocTestHook(void (*func)(int, void*) ATTRIBUTE_UNUSED, * virAlloc: * @ptrptr: pointer to pointer for address of allocated memory * @size: number of bytes to allocate + * @report: report OOM + * @domcode: code of error domain + * @filename: caller's filename + * @funcname: caller's funcname + * @linenr: caller's line number * * Allocate 'size' bytes of memory. Return the address of the * allocated memory in 'ptrptr'. The newly allocated memory is @@ -112,7 +118,8 @@ void virAllocTestHook(void (*func)(int, void*) ATTRIBUTE_UNUSED, * * Returns -1 on failure to allocate, zero on success */ -int virAlloc(void *ptrptr, size_t size) +int virAlloc(void *ptrptr, size_t size, bool report, int domcode, + const char *filename, const char *funcname, size_t linenr) { #if TEST_OOM if (virAllocTestFail()) { @@ -122,8 +129,11 @@ int virAlloc(void *ptrptr, size_t size) #endif *(void **)ptrptr = calloc(1, size); - if (*(void **)ptrptr == NULL) + if (*(void **)ptrptr == NULL) { + if (report) + virReportOOMErrorFull(domcode, filename, funcname, linenr); return -1; + } return 0; } @@ -132,6 +142,11 @@ int virAlloc(void *ptrptr, size_t size) * @ptrptr: pointer to pointer for address of allocated memory * @size: number of bytes to allocate * @count: number of elements to allocate + * @report: report OOM + * @domcode: code of error domain + * @filename: caller's filename + * @funcname: caller's funcname + * @linenr: caller's line number * * Allocate an array of memory 'count' elements long, * each with 'size' bytes. Return the address of the @@ -140,7 +155,8 @@ int virAlloc(void *ptrptr, size_t size) * * Returns -1 on failure to allocate, zero on success */ -int virAllocN(void *ptrptr, size_t size, size_t count) +int virAllocN(void *ptrptr, size_t size, size_t count, bool report, int domcode, + const char *filename, const char *funcname, size_t linenr) { #if TEST_OOM if (virAllocTestFail()) { @@ -150,8 +166,11 @@ int virAllocN(void *ptrptr, size_t size, size_t count) #endif *(void**)ptrptr = calloc(count, size); - if (*(void**)ptrptr == NULL) + if (*(void**)ptrptr == NULL) { + if (report) + virReportOOMErrorFull(domcode, filename, funcname, linenr); return -1; + } return 0; } @@ -160,6 +179,11 @@ int virAllocN(void *ptrptr, size_t size, size_t count) * @ptrptr: pointer to pointer for address of allocated memory * @size: number of bytes to allocate * @count: number of elements in array + * @report: report OOM + * @domcode: code of error domain + * @filename: caller's filename + * @funcname: caller's funcname + * @linenr: caller's line number * * Resize the block of memory in 'ptrptr' to be an array of * 'count' elements, each 'size' bytes in length. Update 'ptrptr' @@ -169,7 +193,8 @@ int virAllocN(void *ptrptr, size_t size, size_t count) * * Returns -1 on failure to allocate, zero on success */ -int virReallocN(void *ptrptr, size_t size, size_t count) +int virReallocN(void *ptrptr, size_t size, size_t count, bool report, int domcode, + const char *filename, const char *funcname, size_t linenr) { void *tmp; #if TEST_OOM @@ -179,11 +204,18 @@ int virReallocN(void *ptrptr, size_t size, size_t count) if (xalloc_oversized(count, size)) { errno = ENOMEM; + if (report) + virReportSystemErrorFull(domcode, ENOMEM, filename, funcname, linenr, + _("Allocation would overflow: " + "count=%zu size=%zu"), count, size); return -1; } tmp = realloc(*(void**)ptrptr, size * count); - if (!tmp && (size * count)) + if (!tmp && (size * count)) { + if (report) + virReportOOMErrorFull(domcode, filename, funcname, linenr); return -1; + } *(void**)ptrptr = tmp; return 0; } @@ -194,6 +226,11 @@ int virReallocN(void *ptrptr, size_t size, size_t count) * @size: number of bytes per element * @countptr: pointer to number of elements in array * @add: number of elements to add + * @report: report OOM + * @domcode: code of error domain + * @filename: caller's filename + * @funcname: caller's funcname + * @linenr: caller's line number * * Resize the block of memory in 'ptrptr' to be an array of * '*countptr' + 'add' elements, each 'size' bytes in length. @@ -203,15 +240,21 @@ int virReallocN(void *ptrptr, size_t size, size_t count) * * Returns -1 on failure to allocate, zero on success */ -int virExpandN(void *ptrptr, size_t size, size_t *countptr, size_t add) +int virExpandN(void *ptrptr, size_t size, size_t *countptr, size_t add, bool report, + int domcode, const char *filename, const char *funcname, size_t linenr) { int ret; if (*countptr + add < *countptr) { errno = ENOMEM; + if (report) + virReportSystemErrorFull(domcode, ENOMEM, filename, funcname, linenr, + _("Allocation would overflow: " + "countptr=%zu add=%zu"), *countptr, add); return -1; } - ret = virReallocN(ptrptr, size, *countptr + add); + ret = virReallocN(ptrptr, size, *countptr + add, report, + domcode, filename, funcname, linenr); if (ret == 0) { memset(*(char **)ptrptr + (size * *countptr), 0, size * add); *countptr += add; @@ -226,6 +269,11 @@ int virExpandN(void *ptrptr, size_t size, size_t *countptr, size_t add) * @allocptr: pointer to number of elements allocated in array * @count: number of elements currently used in array * @add: minimum number of additional elements to support in array + * @report: report OOM + * @domcode: code of error domain + * @filename: caller's filename + * @funcname: caller's funcname + * @linenr: caller's line number * * If 'count' + 'add' is larger than '*allocptr', then resize the * block of memory in 'ptrptr' to be an array of at least 'count' + @@ -237,7 +285,8 @@ int virExpandN(void *ptrptr, size_t size, size_t *countptr, size_t add) * Returns -1 on failure to allocate, zero on success */ int virResizeN(void *ptrptr, size_t size, size_t *allocptr, size_t count, - size_t add) + size_t add, bool report, int domcode, const char *filename, + const char *funcname, size_t linenr) { size_t delta; @@ -251,7 +300,8 @@ int virResizeN(void *ptrptr, size_t size, size_t *allocptr, size_t count, delta = count + add - *allocptr; if (delta < *allocptr / 2) delta = *allocptr / 2; - return virExpandN(ptrptr, size, allocptr, delta); + return virExpandN(ptrptr, size, allocptr, delta, report, + domcode, filename, funcname, linenr); } /** @@ -270,7 +320,8 @@ int virResizeN(void *ptrptr, size_t size, size_t *allocptr, size_t count, void virShrinkN(void *ptrptr, size_t size, size_t *countptr, size_t toremove) { if (toremove < *countptr) - ignore_value(virReallocN(ptrptr, size, *countptr -= toremove)); + ignore_value(virReallocN(ptrptr, size, *countptr -= toremove, false, + 0, NULL, NULL, 0)); else { virFree(ptrptr); *countptr = 0; @@ -318,7 +369,8 @@ virInsertElementsN(void *ptrptr, size_t size, size_t at, if (inPlace) { *countptr += add; - } else if (virExpandN(ptrptr, size, countptr, add) < 0) { + } else if (virExpandN(ptrptr, size, countptr, add, + false, 0, NULL, NULL, 0) < 0) { return -1; } @@ -394,6 +446,11 @@ virDeleteElementsN(void *ptrptr, size_t size, size_t at, * @struct_size: size of initial struct * @element_size: size of array elements * @count: number of array elements to allocate + * @report: report OOM + * @domcode: code of error domain + * @filename: caller's filename + * @funcname: caller's funcname + * @linenr: caller's line number * * Allocate struct_size bytes plus an array of 'count' elements, each * of size element_size. This sort of allocation is useful for @@ -406,7 +463,9 @@ virDeleteElementsN(void *ptrptr, size_t size, size_t at, * * Returns -1 on failure, 0 on success */ -int virAllocVar(void *ptrptr, size_t struct_size, size_t element_size, size_t count) +int virAllocVar(void *ptrptr, size_t struct_size, size_t element_size, size_t count, + bool report, int domcode, const char *filename, const char *funcname, + size_t linenr) { size_t alloc_size = 0; @@ -417,13 +476,21 @@ int virAllocVar(void *ptrptr, size_t struct_size, size_t element_size, size_t co if (VIR_ALLOC_VAR_OVERSIZED(struct_size, count, element_size)) { errno = ENOMEM; + if (report) + virReportSystemErrorFull(domcode, ENOMEM, filename, funcname, linenr, + _("Allocation would overflow: struct_size=%zu " + "count=%zu element_size=%zu"), + struct_size, count, element_size); return -1; } alloc_size = struct_size + (element_size * count); *(void **)ptrptr = calloc(1, alloc_size); - if (*(void **)ptrptr == NULL) + if (*(void **)ptrptr == NULL) { + if (report) + virReportOOMErrorFull(domcode, filename, funcname, linenr); return -1; + } return 0; } diff --git a/src/util/viralloc.h b/src/util/viralloc.h index 7be7f82..f069b3b 100644 --- a/src/util/viralloc.h +++ b/src/util/viralloc.h @@ -46,16 +46,21 @@ /* Don't call these directly - use the macros below */ -int virAlloc(void *ptrptr, size_t size) ATTRIBUTE_RETURN_CHECK - ATTRIBUTE_NONNULL(1); -int virAllocN(void *ptrptr, size_t size, size_t count) ATTRIBUTE_RETURN_CHECK - ATTRIBUTE_NONNULL(1); -int virReallocN(void *ptrptr, size_t size, size_t count) ATTRIBUTE_RETURN_CHECK - ATTRIBUTE_NONNULL(1); -int virExpandN(void *ptrptr, size_t size, size_t *count, size_t add) +int virAlloc(void *ptrptr, size_t size, bool report, int domcode, + const char *filename, const char *funcname, size_t linenr) + ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NONNULL(1); +int virAllocN(void *ptrptr, size_t size, size_t count, bool report, int domcode, + const char *filename, const char *funcname, size_t linenr) + ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NONNULL(1); +int virReallocN(void *ptrptr, size_t size, size_t count, bool report, int domcode, + const char *filename, const char *funcname, size_t linenr) + ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NONNULL(1); +int virExpandN(void *ptrptr, size_t size, size_t *count, size_t add, bool report, + int domcode, const char *filename, const char *funcname, size_t linenr) ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3); int virResizeN(void *ptrptr, size_t size, size_t *alloc, size_t count, - size_t desired) + size_t desired, bool report, int domcode, const char *filename, + const char *funcname, size_t linenr) ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3); void virShrinkN(void *ptrptr, size_t size, size_t *count, size_t toremove) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3); @@ -69,7 +74,10 @@ int virDeleteElementsN(void *ptrptr, size_t size, size_t at, size_t *countptr, int virAllocVar(void *ptrptr, size_t struct_size, size_t element_size, - size_t count) ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NONNULL(1); + size_t count, + bool report, int domcode, const char *filename, + const char *funcname, size_t linenr) + ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NONNULL(1); void virFree(void *ptrptr) ATTRIBUTE_NONNULL(1); /** @@ -82,7 +90,9 @@ void virFree(void *ptrptr) ATTRIBUTE_NONNULL(1); * * Returns -1 on failure, 0 on success */ -# define VIR_ALLOC(ptr) virAlloc(&(ptr), sizeof(*(ptr))) +# define VIR_ALLOC(ptr) virAlloc(&(ptr), sizeof(*(ptr)), true, VIR_FROM_THIS, \ + __FILE__, __FUNCTION__, __LINE__) +# define VIR_ALLOC_QUIET(ptr) virAlloc(&(ptr), sizeof(*(ptr)), false, 0, NULL, NULL, 0) /** * VIR_ALLOC_N: @@ -95,7 +105,12 @@ void virFree(void *ptrptr) ATTRIBUTE_NONNULL(1); * * Returns -1 on failure, 0 on success */ -# define VIR_ALLOC_N(ptr, count) virAllocN(&(ptr), sizeof(*(ptr)), (count)) +# define VIR_ALLOC_N(ptr, count) virAllocN(&(ptr), sizeof(*(ptr)), (count), \ + true, VIR_FROM_THIS, __FILE__, \ + __FUNCTION__, __LINE__) + +# define VIR_ALLOC_N_QUIET(ptr, count) virAllocN(&(ptr), sizeof(*(ptr)), (count), \ + false, VIR_FROM_NONE, NULL, NULL, 0) /** * VIR_REALLOC_N: @@ -108,7 +123,13 @@ void virFree(void *ptrptr) ATTRIBUTE_NONNULL(1); * * Returns -1 on failure, 0 on success */ -# define VIR_REALLOC_N(ptr, count) virReallocN(&(ptr), sizeof(*(ptr)), (count)) + +# define VIR_REALLOC_N(ptr, count) virReallocN(&(ptr), sizeof(*(ptr)), (count), \ + true, VIR_FROM_THIS, __FILE__, \ + __FUNCTION__, __LINE__) + +# define VIR_REALLOC_N_QUIET(ptr, count) virReallocN(&(ptr), sizeof(*(ptr)), (count), \ + false, VIR_FROM_NONE, NULL, NULL, 0) /** * VIR_EXPAND_N: @@ -124,7 +145,8 @@ void virFree(void *ptrptr) ATTRIBUTE_NONNULL(1); * Returns -1 on failure, 0 on success */ # define VIR_EXPAND_N(ptr, count, add) \ - virExpandN(&(ptr), sizeof(*(ptr)), &(count), add) + virExpandN(&(ptr), sizeof(*(ptr)), &(count), add, true, \ + VIR_FROM_THIS, __FILE__, __FUNCTION__, __LINE__) /** * VIR_RESIZE_N: @@ -147,7 +169,8 @@ void virFree(void *ptrptr) ATTRIBUTE_NONNULL(1); * Returns -1 on failure, 0 on success */ # define VIR_RESIZE_N(ptr, alloc, count, add) \ - virResizeN(&(ptr), sizeof(*(ptr)), &(alloc), count, add) + virResizeN(&(ptr), sizeof(*(ptr)), &(alloc), count, add, true, \ + VIR_FROM_THIS, __FILE__, __FUNCTION__, __LINE__) /** * VIR_SHRINK_N: @@ -352,7 +375,8 @@ void virFree(void *ptrptr) ATTRIBUTE_NONNULL(1); * Returns -1 on failure, 0 on success */ # define VIR_ALLOC_VAR(ptr, type, count) \ - virAllocVar(&(ptr), sizeof(*(ptr)), sizeof(type), (count)) + virAllocVar(&(ptr), sizeof(*(ptr)), sizeof(type), (count), true, \ + VIR_FROM_THIS, __FILE__, __FUNCTION__, __LINE__) /** * VIR_FREE: diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c index 693e4b2..b25a659 100644 --- a/src/util/virbuffer.c +++ b/src/util/virbuffer.c @@ -126,7 +126,7 @@ virBufferGrow(virBufferPtr buf, unsigned int len) size = buf->use + len + 1000; - if (VIR_REALLOC_N(buf->content, size) < 0) { + if (VIR_REALLOC_N_QUIET(buf->content, size) < 0) { virBufferSetError(buf, errno); return -1; } @@ -382,7 +382,7 @@ virBufferEscapeString(virBufferPtr buf, const char *format, const char *str) } if (xalloc_oversized(6, len) || - VIR_ALLOC_N(escaped, 6 * len + 1) < 0) { + VIR_ALLOC_N_QUIET(escaped, 6 * len + 1) < 0) { virBufferSetError(buf, errno); return; } @@ -499,7 +499,7 @@ virBufferEscape(virBufferPtr buf, char escape, const char *toescape, } if (xalloc_oversized(2, len) || - VIR_ALLOC_N(escaped, 2 * len + 1) < 0) { + VIR_ALLOC_N_QUIET(escaped, 2 * len + 1) < 0) { virBufferSetError(buf, errno); return; } @@ -597,7 +597,7 @@ virBufferEscapeShell(virBufferPtr buf, const char *str) if (*str) { len = strlen(str); if (xalloc_oversized(4, len) || - VIR_ALLOC_N(escaped, 4 * len + 3) < 0) { + VIR_ALLOC_N_QUIET(escaped, 4 * len + 3) < 0) { virBufferSetError(buf, errno); return; } diff --git a/src/util/virerror.c b/src/util/virerror.c index 2b3a910..f2d77bd 100644 --- a/src/util/virerror.c +++ b/src/util/virerror.c @@ -206,7 +206,7 @@ virLastErrorObject(void) virErrorPtr err; err = virThreadLocalGet(&virLastErr); if (!err) { - if (VIR_ALLOC(err) < 0) + if (VIR_ALLOC_QUIET(err) < 0) return NULL; if (virThreadLocalSet(&virLastErr, err) < 0) VIR_FREE(err); @@ -306,7 +306,7 @@ virSaveLastError(void) virErrorPtr to; int saved_errno = errno; - if (VIR_ALLOC(to) < 0) + if (VIR_ALLOC_QUIET(to) < 0) return NULL; virCopyLastError(to); diff --git a/src/util/virthreadpthread.c b/src/util/virthreadpthread.c index b42b333..810ad9c 100644 --- a/src/util/virthreadpthread.c +++ b/src/util/virthreadpthread.c @@ -174,7 +174,7 @@ int virThreadCreate(virThreadPtr thread, if ((err = pthread_attr_init(&attr)) != 0) goto cleanup; - if (VIR_ALLOC(args) < 0) { + if (VIR_ALLOC_QUIET(args) < 0) { err = ENOMEM; goto cleanup; } diff --git a/tests/networkxml2conftest.c b/tests/networkxml2conftest.c index 520feba..b234b30 100644 --- a/tests/networkxml2conftest.c +++ b/tests/networkxml2conftest.c @@ -16,6 +16,8 @@ #include "network/bridge_driver.h" #include "virstring.h" +#define VIR_FROM_THIS VIR_FROM_NONE + static int testCompareXMLToConfFiles(const char *inxml, const char *outconf, dnsmasqCapsPtr caps) { diff --git a/tests/test_conf.c b/tests/test_conf.c index d5467e8..acf41c6 100644 --- a/tests/test_conf.c +++ b/tests/test_conf.c @@ -20,7 +20,7 @@ int main(int argc, char **argv) goto cleanup; } - if (VIR_ALLOC_N(buffer, len) < 0) { + if (VIR_ALLOC_N_QUIET(buffer, len) < 0) { fprintf(stderr, "out of memory\n"); goto cleanup; } diff --git a/tests/xmconfigtest.c b/tests/xmconfigtest.c index 8e0c59e..73e4a2d 100644 --- a/tests/xmconfigtest.c +++ b/tests/xmconfigtest.c @@ -37,6 +37,8 @@ #include "viralloc.h" #include "virstring.h" +#define VIR_FROM_THIS VIR_FROM_NONE + static virCapsPtr caps; static virDomainXMLOptionPtr xmlopt; -- 1.8.1.5

On 04/29/2013 09:50 AM, Michal Privoznik wrote:
For cases where caller doesn't want to repor an OOM error, he should use
s/repor/report s/he should//
VIR_ALLOC_QUIET or variants. --- HACKING | 4 ++ docs/hacking.html.in | 6 +++ po/POTFILES.in | 1 + python/libvirt-override.c | 102 ++++++++++++++++++++++---------------------- src/esx/esx_vi.c | 3 +- src/util/viralloc.c | 95 +++++++++++++++++++++++++++++++++++------ src/util/viralloc.h | 54 ++++++++++++++++------- src/util/virbuffer.c | 8 ++-- src/util/virerror.c | 4 +- src/util/virthreadpthread.c | 2 +- tests/networkxml2conftest.c | 2 + tests/test_conf.c | 2 +- tests/xmconfigtest.c | 2 + 13 files changed, 196 insertions(+), 89 deletions(-)
From a pure code motion viewpoint the changes seemed reasonable.

On 04/29/2013 09:50 AM, Michal Privoznik wrote:
Previously, the first version dropped virReportOOMError from almost everywhere. This series don't set such high goal yet. It just prepares ground for doing so. The worst case scenario is the OOM error is reported twice. Once in VIR_ALLOC, VIR_STRDUP, virAsprintf (or similar), then in virReportOOMError itself. However, once this is pushed, it's easy to get rid of the latter one.
From the code motion and adjustment, it seems things are OK. I tried to keep focus, but the monotony of motion could have just as easily played
I've gone through each of the patches and figured I'd do one synopsis message! tricks on my eyes. I noted a few issues that need cleanup (the missing increment in 12, an 'm' instead of a ',', a couple of spacing things, and the syntax-check STRUP typo. While not called out, patches 24 (test), 26 (util), and 30 (xen) also had a few instances of auto increment inside the STR*DUP macro. It seems from Eric's comments from 12 that it's OK to do so as long as it's documented that way. Beyond that - thanks for a new way to take power naps :-) John
Patches available at: git://gitorious.org/~zippy2/libvirt/michal-staging.git branch oom3
Remember, this will not be pushed until we are after the freeze. But the freeze creates a nice steady HEAD which is needed in such a giant change like this one.
Michal Privoznik (37): virutil: Move string related functions to virstring.c virstring: Introduce VIR_STRUP and VIR_STRNDUP Adapt to VIR_STRDUP in daemon/* Adapt to VIR_STRDUP in src/conf/* Adapt to VIR_STRDUP in src/cpu/* Adapt to VIR_STRDUP in src/esx/* Adapt to VIR_STRDUP in src/hyperv/* Adapt to VIR_STRDUP in src/libxl/* Adapt to VIR_STRDUP in src/locking/* Adapt to VIR_STRDUP in src/lxc/* Adapt to VIR_STRDUP in src/network/* Adapt to VIR_STRDUP in src/node_device/* Adapt to VIR_STRDUP in src/interface/ Adapt to VIR_STRDUP in src/nwfilter/* Adapt to VIR_STRDUP in src/openvz/* Adapt to VIR_STRDUP in src/parallels/* Adapt to VIR_STRDUP in src/phyp/* Adapt to VIR_STRDUP in src/qemu/* Adapt to VIR_STRDUP in src/remote/* Adapt to VIR_STRDUP in src/rpc/* Adapt to VIR_STRDUP in src/secret/* Adapt to VIR_STRDUP in src/security/* Adapt to VIR_STRDUP in src/storage/* Adapt to VIR_STRDUP in src/test/* Adapt to VIR_STRDUP in src/uml/* Adapt to VIR_STRDUP in src/util/* Adapt to VIR_STRDUP in src/vbox/* Adapt to VIR_STRDUP in src/vmware/* Adapt to VIR_STRDUP in src/vmx/* Adapt to VIR_STRDUP in src/xen/* Adapt to VIR_STRDUP in src/xenapi/* Adapt to VIR_STRDUP in src/xenxs/* Adapt to VIR_STRDUP in tests/* Adapt to VIR_STRDUP in src/* Introduce syntax-check rule to prefer VIR_STRDUP over strdup virstring: Introduce virAsprintfQuiet and virVasprintfQuiet viralloc.c: Do report OOM error in VIR_ALLOC and friends
HACKING | 19 ++ cfg.mk | 12 +- daemon/libvirtd-config.c | 39 +-- daemon/libvirtd.c | 19 +- daemon/remote.c | 97 +++---- docs/hacking.html.in | 26 ++ include/libvirt/libvirt.h.in | 10 +- po/POTFILES.in | 1 + python/libvirt-override.c | 103 +++---- src/conf/capabilities.c | 27 +- src/conf/cpu_conf.c | 14 +- src/conf/device_conf.c | 2 +- src/conf/domain_audit.c | 1 + src/conf/domain_conf.c | 66 ++--- src/conf/domain_conf.h | 1 - src/conf/domain_event.c | 31 +- src/conf/interface_conf.c | 1 - src/conf/netdev_bandwidth_conf.c | 2 +- src/conf/netdev_vport_profile_conf.c | 1 + src/conf/network_conf.c | 2 +- src/conf/node_device_conf.c | 29 +- src/conf/nwfilter_conf.c | 20 +- src/conf/nwfilter_conf.h | 1 - src/conf/nwfilter_params.c | 23 +- src/conf/secret_conf.c | 1 - src/conf/snapshot_conf.c | 8 +- src/conf/storage_conf.c | 11 +- src/conf/storage_conf.h | 1 - src/conf/storage_encryption_conf.c | 1 - src/conf/virchrdev.c | 7 +- src/cpu/cpu_generic.c | 6 +- src/cpu/cpu_map.c | 3 +- src/cpu/cpu_powerpc.c | 11 +- src/cpu/cpu_x86.c | 9 +- src/datatypes.c | 26 +- src/driver.c | 2 +- src/esx/esx_device_monitor.c | 1 - src/esx/esx_driver.c | 35 +-- src/esx/esx_interface_driver.c | 6 +- src/esx/esx_network_driver.c | 21 +- src/esx/esx_nwfilter_driver.c | 1 - src/esx/esx_secret_driver.c | 1 - src/esx/esx_storage_backend_iscsi.c | 15 +- src/esx/esx_storage_backend_vmfs.c | 10 +- src/esx/esx_util.c | 39 +-- src/esx/esx_vi.c | 54 +--- src/esx/esx_vi_types.c | 24 +- src/fdstream.c | 1 + src/hyperv/hyperv_device_monitor.c | 1 - src/hyperv/hyperv_driver.c | 37 +-- src/hyperv/hyperv_interface_driver.c | 1 - src/hyperv/hyperv_network_driver.c | 1 - src/hyperv/hyperv_nwfilter_driver.c | 1 - src/hyperv/hyperv_secret_driver.c | 1 - src/hyperv/hyperv_storage_driver.c | 1 - src/hyperv/hyperv_util.c | 16 +- src/hyperv/hyperv_wmi.c | 2 +- src/interface/interface_backend_udev.c | 25 +- src/libvirt.c | 10 +- src/libvirt_private.syms | 36 +-- src/libxl/libxl_conf.c | 59 ++-- src/libxl/libxl_driver.c | 14 +- src/locking/lock_daemon.c | 13 +- src/locking/lock_daemon_config.c | 10 +- src/locking/lock_daemon_dispatch.c | 4 +- src/locking/lock_driver_lockd.c | 24 +- src/locking/lock_driver_sanlock.c | 9 +- src/locking/lock_manager.c | 4 +- src/lxc/lxc_cgroup.c | 3 +- src/lxc/lxc_conf.c | 18 +- src/lxc/lxc_container.c | 10 +- src/lxc/lxc_controller.c | 8 +- src/lxc/lxc_driver.c | 9 +- src/lxc/lxc_fuse.c | 1 + src/lxc/lxc_fuse.h | 1 - src/lxc/lxc_monitor.c | 1 + src/lxc/lxc_process.c | 5 +- src/network/bridge_driver.c | 30 +- src/node_device/node_device_driver.c | 29 +- src/node_device/node_device_hal.c | 13 +- src/node_device/node_device_linux_sysfs.c | 1 + src/node_device/node_device_udev.c | 104 +++---- src/nodeinfo.c | 6 +- src/nwfilter/nwfilter_dhcpsnoop.c | 16 +- src/nwfilter/nwfilter_driver.c | 5 +- src/nwfilter/nwfilter_ebiptables_driver.c | 12 +- src/nwfilter/nwfilter_gentech_driver.c | 4 +- src/nwfilter/nwfilter_learnipaddr.c | 4 +- src/openvz/openvz_conf.c | 33 ++- src/openvz/openvz_driver.c | 32 +-- src/parallels/parallels_driver.c | 36 +-- src/parallels/parallels_network.c | 14 +- src/parallels/parallels_storage.c | 40 ++- src/parallels/parallels_utils.c | 2 +- src/phyp/phyp_driver.c | 37 +-- src/qemu/qemu_agent.c | 1 + src/qemu/qemu_bridge_filter.c | 1 - src/qemu/qemu_capabilities.c | 38 +-- src/qemu/qemu_cgroup.c | 4 +- src/qemu/qemu_command.c | 282 ++++++++----------- src/qemu/qemu_conf.c | 33 +-- src/qemu/qemu_domain.c | 17 +- src/qemu/qemu_driver.c | 93 +++--- src/qemu/qemu_hotplug.c | 9 +- src/qemu/qemu_migration.c | 17 +- src/qemu/qemu_monitor.c | 1 + src/qemu/qemu_monitor_json.c | 40 ++- src/qemu/qemu_monitor_text.c | 10 +- src/qemu/qemu_process.c | 58 ++-- src/remote/remote_driver.c | 83 +++--- src/rpc/gendispatch.pl | 13 +- src/rpc/virkeepalive.c | 1 - src/rpc/virnetclient.c | 8 +- src/rpc/virnetmessage.c | 11 +- src/rpc/virnetsaslcontext.c | 3 +- src/rpc/virnetserver.c | 4 +- src/rpc/virnetserverclient.c | 8 +- src/rpc/virnetservermdns.c | 4 +- src/rpc/virnetsocket.c | 8 +- src/rpc/virnetsshsession.c | 23 +- src/rpc/virnettlscontext.c | 14 +- src/secret/secret_driver.c | 5 +- src/security/security_apparmor.c | 13 +- src/security/security_dac.c | 8 +- src/security/security_nop.c | 4 +- src/security/security_selinux.c | 51 ++-- src/security/virt-aa-helper.c | 6 +- src/storage/parthelper.c | 7 +- src/storage/storage_backend.c | 18 +- src/storage/storage_backend_disk.c | 16 +- src/storage/storage_backend_fs.c | 18 +- src/storage/storage_backend_iscsi.c | 16 +- src/storage/storage_backend_logical.c | 25 +- src/storage/storage_backend_mpath.c | 4 +- src/storage/storage_backend_rbd.c | 4 +- src/storage/storage_backend_scsi.c | 17 +- src/storage/storage_backend_sheepdog.c | 1 - src/storage/storage_driver.c | 13 +- src/test/test_driver.c | 84 +++--- src/uml/uml_conf.c | 7 +- src/uml/uml_driver.c | 8 +- src/util/iohelper.c | 1 + src/util/viralloc.c | 95 ++++++- src/util/viralloc.h | 54 +++- src/util/viraudit.c | 6 +- src/util/virauth.c | 9 +- src/util/virauthconfig.c | 7 +- src/util/virbitmap.c | 10 +- src/util/virbuffer.c | 8 +- src/util/vircgroup.c | 31 +- src/util/vircommand.c | 34 ++- src/util/vircommand.h | 1 - src/util/virconf.c | 21 +- src/util/virdnsmasq.c | 5 +- src/util/virebtables.c | 36 +-- src/util/virerror.c | 25 +- src/util/virfile.c | 1 + src/util/virhash.c | 5 +- src/util/virhook.h | 1 - src/util/viridentity.c | 9 +- src/util/virinitctl.c | 3 +- src/util/viriptables.c | 6 +- src/util/virjson.c | 18 +- src/util/virkeyfile.c | 7 +- src/util/virlockspace.c | 14 +- src/util/virlog.c | 21 +- src/util/virnetdev.c | 2 + src/util/virnetdevbandwidth.c | 1 + src/util/virnetdevbridge.c | 1 + src/util/virnetdevmacvlan.c | 10 +- src/util/virnetdevopenvswitch.c | 1 + src/util/virnetdevopenvswitch.h | 1 - src/util/virnetdevtap.c | 7 +- src/util/virnetdevveth.c | 2 + src/util/virnetdevvportprofile.c | 4 +- src/util/virobject.c | 5 +- src/util/virpci.c | 7 +- src/util/virpidfile.c | 1 + src/util/virprocess.c | 1 + src/util/virrandom.c | 1 + src/util/virsexpr.c | 27 +- src/util/virsocketaddr.c | 6 +- src/util/virstatslinux.c | 1 - src/util/virstoragefile.c | 13 +- src/util/virstring.c | 451 +++++++++++++++++++++++++++++- src/util/virstring.h | 74 +++++ src/util/virsysinfo.c | 170 +++++------ src/util/virthreadpthread.c | 2 +- src/util/virtime.c | 1 - src/util/virtpm.c | 2 +- src/util/virtypedparam.c | 9 +- src/util/viruri.c | 20 +- src/util/virusb.c | 1 + src/util/virutil.c | 393 ++------------------------ src/util/virutil.h | 49 ---- src/util/virxml.c | 7 +- src/vbox/vbox_MSCOMGlue.c | 1 - src/vbox/vbox_XPCOMCGlue.c | 5 +- src/vbox/vbox_driver.c | 1 - src/vbox/vbox_tmpl.c | 191 +++++++------ src/vmware/vmware_conf.c | 15 +- src/vmware/vmware_driver.c | 13 +- src/vmx/vmx.c | 26 +- src/xen/block_stats.c | 2 +- src/xen/xen_driver.c | 4 +- src/xen/xen_hypervisor.c | 17 +- src/xen/xen_inotify.c | 11 +- src/xen/xend_internal.c | 55 ++-- src/xen/xm_internal.c | 8 +- src/xen/xs_internal.c | 22 +- src/xenapi/xenapi_driver.c | 34 ++- src/xenapi/xenapi_utils.c | 22 +- src/xenxs/xen_sxpr.c | 108 +++---- src/xenxs/xen_xm.c | 44 +-- tests/commandhelper.c | 14 +- tests/commandtest.c | 4 +- tests/cputest.c | 1 + tests/domainsnapshotxml2xmltest.c | 1 + tests/esxutilstest.c | 1 - tests/interfacexml2xmltest.c | 2 +- tests/libvirtdconftest.c | 1 + tests/lxcxml2xmltest.c | 1 + tests/networkxml2conftest.c | 3 + tests/networkxml2xmltest.c | 1 + tests/nodedevxml2xmltest.c | 1 + tests/nodeinfotest.c | 2 +- tests/nwfilterxml2xmltest.c | 1 + tests/openvzutilstest.c | 8 +- tests/qemuargv2xmltest.c | 2 +- tests/qemuhelptest.c | 1 + tests/qemumonitortest.c | 1 - tests/qemumonitortestutils.c | 10 +- tests/qemuxml2argvtest.c | 28 +- tests/qemuxml2xmltest.c | 1 + tests/qemuxmlnstest.c | 6 +- tests/securityselinuxhelper.c | 7 +- tests/securityselinuxlabeltest.c | 5 +- tests/securityselinuxtest.c | 9 +- tests/sexpr2xmltest.c | 1 + tests/storagebackendsheepdogtest.c | 6 +- tests/storagepoolxml2xmltest.c | 1 + tests/storagevolxml2argvtest.c | 1 + tests/storagevolxml2xmltest.c | 1 + tests/sysinfotest.c | 2 +- tests/test_conf.c | 2 +- tests/testutils.c | 5 +- tests/testutilsqemu.c | 5 +- tests/virauthconfigtest.c | 1 - tests/virbuftest.c | 2 +- tests/vircgrouptest.c | 4 +- tests/virdrivermoduletest.c | 1 - tests/virhashtest.c | 3 +- tests/viridentitytest.c | 1 - tests/virkeyfiletest.c | 1 - tests/virnetmessagetest.c | 22 +- tests/virnetsockettest.c | 1 + tests/virportallocatortest.c | 2 +- tests/virshtest.c | 2 +- tests/virstoragetest.c | 1 + tests/virstringtest.c | 1 - tests/virtimetest.c | 1 - tests/viruritest.c | 1 - tests/vmx2xmltest.c | 11 +- tests/xencapstest.c | 1 + tests/xmconfigtest.c | 3 + tests/xml2sexprtest.c | 1 + tests/xml2vmxtest.c | 11 +- tools/console.c | 1 - tools/virsh-domain-monitor.c | 1 + tools/virsh-domain.c | 1 - tools/virsh-host.c | 2 +- tools/virsh-interface.c | 1 + tools/virsh-network.c | 1 - tools/virsh-nodedev.c | 1 - tools/virsh-pool.c | 2 +- tools/virsh-snapshot.c | 1 - tools/virsh-volume.c | 1 + tools/virsh.c | 8 +- tools/virt-host-validate-common.c | 1 + 279 files changed, 2544 insertions(+), 2653 deletions(-)
participants (3)
-
Eric Blake
-
John Ferlan
-
Michal Privoznik