# Avoid raw malloc and free, except in documentation comments.
sc_prohibit_raw_allocation:
@prohibit='^.[^*].*\<((m|c|re)alloc|free) *\([^)]' \
- halt='use VIR_ macros from memory.h instead of malloc/free' \
+ halt='use VIR_ macros from viralloc.h instead of malloc/free' \
$(_sc_search_regexp)
# Avoid functions that can lead to double-close bugs.
exclude_file_name_regexp--sc_prohibit_gethostname = ^src/util/util\.c$$
exclude_file_name_regexp--sc_prohibit_internal_functions = \
- ^src/(util/(memory|util|virfile)\.[hc]|esx/esx_vi\.c)$$
+ ^src/(util/(viralloc|util|virfile)\.[hc]|esx/esx_vi\.c)$$
exclude_file_name_regexp--sc_prohibit_newline_at_end_of_diagnostic = \
^src/rpc/gendispatch\.pl$$
^((po|tests)/|docs/.*py|run.in$$)
exclude_file_name_regexp--sc_prohibit_raw_allocation = \
- ^(src/util/memory\.[ch]|examples/.*)$$
+ ^(src/util/viralloc\.[ch]|examples/.*)$$
exclude_file_name_regexp--sc_prohibit_readlink = \
^src/(util/util|lxc/lxc_container)\.c$$
#include "libvirtd-config.h"
#include "virconf.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virterror_internal.h"
#include "virlog.h"
#include "rpc/virnetserver.h"
#include "util.h"
#include "uuid.h"
#include "remote_driver.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virconf.h"
#include "virnetlink.h"
#include "virnetserver.h"
#include "libvirtd.h"
#include "libvirt_internal.h"
#include "datatypes.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "util.h"
#include "stream.h"
#include "stream.h"
#include "remote.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "virnetserverclient.h"
#include "virterror_internal.h"
#include "libvirt/virterror.h"
#include "typewrappers.h"
#include "libvirt.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virtypedparam.h"
#include "ignore-value.h"
#include "util.h"
#include "typewrappers.h"
-#include "memory.h"
+#include "viralloc.h"
#ifndef Py_CAPSULE_H
typedef void(*PyCapsule_Destructor)(void *, void *);
# These files are not related to driver APIs. Simply generic
# helper APIs for various purposes
UTIL_SOURCES = \
- util/memory.c util/memory.h \
util/pci.c util/pci.h \
util/processinfo.c util/processinfo.h \
util/sexpr.c util/sexpr.h \
util/threadpool.c util/threadpool.h \
util/uuid.c util/uuid.h \
util/util.c util/util.h \
+ util/viralloc.c util/viralloc.h \
util/virarch.h util/virarch.c \
util/viratomic.h util/viratomic.c \
util/viraudit.c util/viraudit.h \
#include "capabilities.h"
#include "virbuffer.h"
-#include "memory.h"
+#include "viralloc.h"
#include "util.h"
#include "uuid.h"
#include "cpu_conf.h"
#include <config.h>
#include "virterror_internal.h"
-#include "memory.h"
+#include "viralloc.h"
#include "util.h"
#include "virbuffer.h"
#include "cpu_conf.h"
#include <config.h>
#include "virterror_internal.h"
#include "datatypes.h"
-#include "memory.h"
+#include "viralloc.h"
#include "xml.h"
#include "uuid.h"
#include "util.h"
#include "viraudit.h"
#include "uuid.h"
#include "virlog.h"
-#include "memory.h"
+#include "viralloc.h"
/* Return nn:mm in hex for block and character devices, and NULL
* for other file types, stat failure, or allocation failure. */
#include "datatypes.h"
#include "domain_conf.h"
#include "snapshot_conf.h"
-#include "memory.h"
+#include "viralloc.h"
#include "verify.h"
#include "xml.h"
#include "uuid.h"
#include "domain_event.h"
#include "virlog.h"
#include "datatypes.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virterror_internal.h"
#define VIR_FROM_THIS VIR_FROM_NONE
#include "interface_conf.h"
-#include "memory.h"
+#include "viralloc.h"
#include "xml.h"
#include "uuid.h"
#include "util.h"
#include "netdev_bandwidth_conf.h"
#include "virterror_internal.h"
#include "util.h"
-#include "memory.h"
+#include "viralloc.h"
#include "domain_conf.h"
#define VIR_FROM_THIS VIR_FROM_NONE
#include "netdev_vlan_conf.h"
#include "virterror_internal.h"
-#include "memory.h"
+#include "viralloc.h"
#define VIR_FROM_THIS VIR_FROM_NONE
#include "netdev_vport_profile_conf.h"
#include "virterror_internal.h"
-#include "memory.h"
+#include "viralloc.h"
#define VIR_FROM_THIS VIR_FROM_NONE
#include "netdev_vport_profile_conf.h"
#include "netdev_bandwidth_conf.h"
#include "netdev_vlan_conf.h"
-#include "memory.h"
+#include "viralloc.h"
#include "xml.h"
#include "uuid.h"
#include "util.h"
#include "virterror_internal.h"
#include "datatypes.h"
-#include "memory.h"
+#include "viralloc.h"
#include "node_device_conf.h"
-#include "memory.h"
+#include "viralloc.h"
#include "xml.h"
#include "util.h"
#include "virbuffer.h"
#include "internal.h"
#include "uuid.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virterror_internal.h"
#include "datatypes.h"
#include "nwfilter_params.h"
#include "internal.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virterror_internal.h"
#include "datatypes.h"
#include "nwfilter_params.h"
#include "virbuffer.h"
#include "datatypes.h"
#include "virlog.h"
-#include "memory.h"
+#include "viralloc.h"
#include "secret_conf.h"
#include "virterror_internal.h"
#include "util.h"
#include "datatypes.h"
#include "domain_conf.h"
#include "virlog.h"
-#include "memory.h"
+#include "viralloc.h"
#include "netdev_bandwidth_conf.h"
#include "netdev_vport_profile_conf.h"
#include "nwfilter_conf.h"
#include "uuid.h"
#include "virbuffer.h"
#include "util.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virfile.h"
#define VIR_FROM_THIS VIR_FROM_STORAGE
#include "internal.h"
#include "virbuffer.h"
-#include "memory.h"
+#include "viralloc.h"
#include "storage_conf.h"
#include "storage_encryption_conf.h"
#include "util.h"
#include "fdstream.h"
#include "internal.h"
#include "threads.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virpidfile.h"
#include "virlog.h"
#include "virterror_internal.h"
#include <config.h>
#include "virlog.h"
-#include "memory.h"
+#include "viralloc.h"
#include "xml.h"
#include "cpu.h"
#include "cpu_x86.h"
#include <config.h>
-#include "memory.h"
+#include "viralloc.h"
#include "cpu.h"
#define VIR_FROM_THIS VIR_FROM_CPU
#include <config.h>
-#include "memory.h"
+#include "viralloc.h"
#include "virhash.h"
#include "cpu.h"
#include "cpu_generic.h"
#include <config.h>
-#include "memory.h"
+#include "viralloc.h"
#include "cpu.h"
#include "cpu_map.h"
#include "configmake.h"
#include <stdint.h>
#include "virlog.h"
-#include "memory.h"
+#include "viralloc.h"
#include "util.h"
#include "cpu.h"
#include <config.h>
-#include "memory.h"
+#include "viralloc.h"
#include "cpu.h"
#include <stdint.h>
#include "virlog.h"
-#include "memory.h"
+#include "viralloc.h"
#include "util.h"
#include "cpu.h"
#include "cpu_map.h"
#include "datatypes.h"
#include "virterror_internal.h"
#include "virlog.h"
-#include "memory.h"
+#include "viralloc.h"
#include "uuid.h"
#include "util.h"
#include <unistd.h>
#include "driver.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "util.h"
#include "configmake.h"
#include "internal.h"
#include "util.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "uuid.h"
#include "esx_private.h"
#include "snapshot_conf.h"
#include "virauth.h"
#include "util.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "uuid.h"
#include "vmx.h"
#include "internal.h"
#include "util.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "uuid.h"
#include "interface_conf.h"
#include "md5.h"
#include "internal.h"
#include "util.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "uuid.h"
#include "network_conf.h"
#include "internal.h"
#include "util.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "uuid.h"
#include "esx_private.h"
#include "internal.h"
#include "util.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "uuid.h"
#include "esx_private.h"
#include "internal.h"
#include "md5.h"
#include "util.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "uuid.h"
#include "storage_conf.h"
#include "internal.h"
#include "md5.h"
#include "util.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "uuid.h"
#include "storage_conf.h"
#include <config.h>
#include "uuid.h"
-#include "memory.h"
+#include "viralloc.h"
#include "storage_conf.h"
#include "esx_private.h"
#include "esx_storage_driver.h"
#include "internal.h"
#include "datatypes.h"
#include "util.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "uuid.h"
#include "vmx.h"
#include <libxml/xpathInternals.h>
#include "virbuffer.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "util.h"
#include "uuid.h"
#include <config.h>
#include "virbuffer.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "uuid.h"
#include "esx_vi_methods.h"
#include "virbuffer.h"
#include "datatypes.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "util.h"
#include "esx_vi.h"
#include "virterror_internal.h"
#include "datatypes.h"
#include "virlog.h"
-#include "memory.h"
+#include "viralloc.h"
#include "util.h"
#include "virfile.h"
#include "configmake.h"
#include "virterror_internal.h"
#include "datatypes.h"
#include "util.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "uuid.h"
#include "hyperv_device_monitor.h"
#include "domain_conf.h"
#include "virauth.h"
#include "util.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "uuid.h"
#include "hyperv_driver.h"
#include "virterror_internal.h"
#include "datatypes.h"
#include "util.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "uuid.h"
#include "hyperv_interface_driver.h"
#include "virterror_internal.h"
#include "datatypes.h"
#include "util.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "uuid.h"
#include "hyperv_network_driver.h"
#include "virterror_internal.h"
#include "datatypes.h"
#include "util.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "uuid.h"
#include "hyperv_nwfilter_driver.h"
#include "virterror_internal.h"
#include "datatypes.h"
#include "util.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "uuid.h"
#include "hyperv_secret_driver.h"
#include "virterror_internal.h"
#include "datatypes.h"
#include "util.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "uuid.h"
#include "hyperv_storage_driver.h"
#include "internal.h"
#include "datatypes.h"
#include "util.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "uuid.h"
#include "hyperv_private.h"
#include "virterror_internal.h"
#include "datatypes.h"
#include "virlog.h"
-#include "memory.h"
+#include "viralloc.h"
#include "util.h"
#include "uuid.h"
#include "virbuffer.h"
#include "datatypes.h"
#include "interface_driver.h"
#include "interface_conf.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#define VIR_FROM_THIS VIR_FROM_INTERFACE
#include "datatypes.h"
#include "interface_driver.h"
#include "interface_conf.h"
-#include "memory.h"
+#include "viralloc.h"
#define VIR_FROM_THIS VIR_FROM_INTERFACE
#include "driver.h"
#include "uuid.h"
-#include "memory.h"
+#include "viralloc.h"
#include "configmake.h"
#include "intprops.h"
#include "virconf.h"
#include "datatypes.h"
#include "virfile.h"
#include "virstring.h"
-#include "memory.h"
+#include "viralloc.h"
#include "uuid.h"
#include "capabilities.h"
#include "libxl_driver.h"
#include "virconf.h"
#include "datatypes.h"
#include "virfile.h"
-#include "memory.h"
+#include "viralloc.h"
#include "uuid.h"
#include "vircommand.h"
#include "libxl.h"
#include <config.h>
#include "domain_lock.h"
-#include "memory.h"
+#include "viralloc.h"
#include "uuid.h"
#include "virterror_internal.h"
#include "virlog.h"
#include "virprocess.h"
#include "virterror_internal.h"
#include "virlog.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virconf.h"
#include "rpc/virnetserver.h"
#include "virrandom.h"
#include "lock_daemon_config.h"
#include "virconf.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virterror_internal.h"
#include "virlog.h"
#include "rpc/virnetserver.h"
#include "lock_driver.h"
#include "virconf.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "uuid.h"
#include "util.h"
#include <config.h>
#include "lock_driver_nop.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "uuid.h"
#include "lock_driver.h"
#include "virlog.h"
#include "virterror_internal.h"
-#include "memory.h"
+#include "viralloc.h"
#include "util.h"
#include "virfile.h"
#include "md5.h"
#include "virterror_internal.h"
#include "virlog.h"
#include "util.h"
-#include "memory.h"
+#include "viralloc.h"
#include "uuid.h"
#if HAVE_DLFCN_H
#include "configmake.h"
#include "internal.h"
#include "virconf.h"
-#include "memory.h"
+#include "viralloc.h"
#include "domain_conf.h"
#include "virfile.h"
#include "virterror_internal.h"
#include "virlog.h"
-#include "memory.h"
+#include "viralloc.h"
#include "vircgroup.h"
#define VIR_FROM_THIS VIR_FROM_LXC
#include "nodeinfo.h"
#include "virterror_internal.h"
#include "virconf.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "uuid.h"
#include "configmake.h"
#include "virlog.h"
#include "lxc_container.h"
#include "util.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virnetdevveth.h"
#include "uuid.h"
#include "virfile.h"
#include "lxc_fuse.h"
#include "virnetdev.h"
#include "virnetdevveth.h"
-#include "memory.h"
+#include "viralloc.h"
#include "util.h"
#include "virfile.h"
#include "virpidfile.h"
#include "lxc_domain.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "virterror_internal.h"
#include "lxc_domain.h"
#include "lxc_driver.h"
#include "lxc_process.h"
-#include "memory.h"
+#include "viralloc.h"
#include "util.h"
#include "virnetdevbridge.h"
#include "virnetdevveth.h"
# include "lxc_conf.h"
# include "util.h"
-# include "memory.h"
+# include "viralloc.h"
struct virLXCMeminfo {
unsigned long long memtotal;
#include <config.h>
#include "lxc_hostdev.h"
+#include "viralloc.h"
#include "virlog.h"
#include "virterror_internal.h"
-#include "memory.h"
#define VIR_FROM_THIS VIR_FROM_LXC
#include "lxc_protocol.h"
#include "lxc_monitor_dispatch.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virterror_internal.h"
#include "virlog.h"
#include "virtime.h"
#include "domain_nwfilter.h"
#include "network/bridge_driver.h"
-#include "memory.h"
+#include "viralloc.h"
#include "domain_audit.h"
#include "virterror_internal.h"
#include "virlog.h"
#include "virpidfile.h"
#include "util.h"
#include "vircommand.h"
-#include "memory.h"
+#include "viralloc.h"
#include "uuid.h"
#include "viriptables.h"
#include "virlog.h"
#include "virterror_internal.h"
#include "datatypes.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "node_device_conf.h"
#include "node_device_hal.h"
#include "virterror_internal.h"
#include "driver.h"
#include "datatypes.h"
-#include "memory.h"
+#include "viralloc.h"
#include "uuid.h"
#include "pci.h"
#include "virlog.h"
#include "node_device_driver.h"
#include "node_device_hal.h"
#include "virterror_internal.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "virfile.h"
#include "driver.h"
#include "datatypes.h"
#include "virlog.h"
-#include "memory.h"
+#include "viralloc.h"
#include "uuid.h"
#include "util.h"
#include "virbuffer.h"
#endif
#include "c-ctype.h"
-#include "memory.h"
+#include "viralloc.h"
#include "nodeinfo.h"
#include "physmem.h"
#include "util.h"
#include <netinet/udp.h>
#include <net/if.h>
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "datatypes.h"
#include "virterror_internal.h"
#include "virterror_internal.h"
#include "datatypes.h"
-#include "memory.h"
+#include "viralloc.h"
#include "domain_conf.h"
#include "domain_nwfilter.h"
#include "nwfilter_conf.h"
#include "internal.h"
#include "virbuffer.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "virterror_internal.h"
#include "domain_conf.h"
#include "internal.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "domain_conf.h"
#include "virterror_internal.h"
#include "intprops.h"
#include "virbuffer.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "datatypes.h"
#include "virnetdev.h"
#include "openvz_util.h"
#include "uuid.h"
#include "virbuffer.h"
-#include "memory.h"
+#include "viralloc.h"
#include "util.h"
#include "nodeinfo.h"
#include "virfile.h"
#include "util.h"
#include "openvz_conf.h"
#include "nodeinfo.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virfile.h"
#include "virtypedparam.h"
#include "virlog.h"
#include "virterror_internal.h"
#include "vircommand.h"
#include "datatypes.h"
-#include "memory.h"
+#include "viralloc.h"
#include "openvz_conf.h"
#include "openvz_util.h"
#include "datatypes.h"
#include "virterror_internal.h"
-#include "memory.h"
+#include "viralloc.h"
#include "util.h"
#include "virlog.h"
#include "vircommand.h"
#include <config.h>
#include "datatypes.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virterror_internal.h"
#include "md5.h"
#include <libgen.h>
#include "datatypes.h"
-#include "memory.h"
+#include "viralloc.h"
#include "configmake.h"
#include "storage_file.h"
#include "virterror_internal.h"
#include "vircommand.h"
#include "virterror_internal.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virjson.h"
#include "parallels_utils.h"
#include "util.h"
#include "datatypes.h"
#include "virbuffer.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "driver.h"
#include "libvirt/libvirt.h"
#include "qemu_agent.h"
#include "qemu_command.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "virterror_internal.h"
#include "virjson.h"
#include <config.h>
#include "qemu_capabilities.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "virterror_internal.h"
#include "util.h"
#include "qemu_process.h"
#include "vircgroup.h"
#include "virlog.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virterror_internal.h"
#include "util.h"
#include "domain_audit.h"
#include "qemu_capabilities.h"
#include "qemu_bridge_filter.h"
#include "cpu/cpu.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "virterror_internal.h"
#include "util.h"
#include "virbuffer.h"
#include "virconf.h"
#include "util.h"
-#include "memory.h"
+#include "viralloc.h"
#include "datatypes.h"
#include "xml.h"
#include "nodeinfo.h"
#include "qemu_command.h"
#include "qemu_capabilities.h"
#include "qemu_migration.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "virterror_internal.h"
#include "c-ctype.h"
#include "nodeinfo.h"
#include "stats_linux.h"
#include "capabilities.h"
-#include "memory.h"
+#include "viralloc.h"
#include "uuid.h"
#include "domain_conf.h"
#include "domain_audit.h"
#include "qemu_hostdev.h"
#include "virlog.h"
#include "virterror_internal.h"
-#include "memory.h"
+#include "viralloc.h"
#include "pci.h"
#include "virusb.h"
#include "virnetdev.h"
#include "virlog.h"
#include "datatypes.h"
#include "virterror_internal.h"
-#include "memory.h"
+#include "viralloc.h"
#include "pci.h"
#include "virfile.h"
#include "qemu_cgroup.h"
#include "domain_audit.h"
#include "virlog.h"
#include "virterror_internal.h"
-#include "memory.h"
+#include "viralloc.h"
#include "util.h"
#include "virfile.h"
#include "datatypes.h"
#include "qemu_monitor_text.h"
#include "qemu_monitor_json.h"
#include "virterror_internal.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "virfile.h"
#include "virprocess.h"
#include "qemu_monitor_json.h"
#include "qemu_command.h"
#include "qemu_capabilities.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "driver.h"
#include "datatypes.h"
#include "qemu_command.h"
#include "c-ctype.h"
#include "c-strcasestr.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "driver.h"
#include "datatypes.h"
#include "datatypes.h"
#include "virlog.h"
#include "virterror_internal.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virhook.h"
#include "virfile.h"
#include "virpidfile.h"
#include "remote_driver.h"
#include "remote_protocol.h"
#include "qemu_protocol.h"
-#include "memory.h"
+#include "viralloc.h"
#include "util.h"
#include "virfile.h"
#include "vircommand.h"
#include <config.h>
-#include "memory.h"
+#include "viralloc.h"
#include "threads.h"
#include "virfile.h"
#include "virlog.h"
#include "virnetclient.h"
#include "virnetsocket.h"
#include "virkeepalive.h"
-#include "memory.h"
+#include "viralloc.h"
#include "threads.h"
#include "virfile.h"
#include "virlog.h"
#include "virnetclient.h"
#include "virnetprotocol.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virterror_internal.h"
#include "virlog.h"
#include "util.h"
#include "virnetclientstream.h"
#include "virnetclient.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virterror_internal.h"
#include "virlog.h"
#include "threads.h"
#include <unistd.h>
#include "virnetmessage.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virterror_internal.h"
#include "virlog.h"
#include "virfile.h"
#include "virnetmessage.h"
#include "virterror_internal.h"
-#include "memory.h"
+#include "viralloc.h"
#include "threads.h"
#include "virlog.h"
#include "virnetserver.h"
#include "virlog.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virterror_internal.h"
#include "threads.h"
#include "threadpool.h"
#include "virlog.h"
#include "virterror_internal.h"
-#include "memory.h"
+#include "viralloc.h"
#include "threads.h"
#include "virkeepalive.h"
#include "virnetservermdns.h"
#include "vireventpoll.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virterror_internal.h"
#include "virlog.h"
#include "virnetserverprogram.h"
#include "virnetserverclient.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virterror_internal.h"
#include "virlog.h"
#include "virfile.h"
#include "virnetserverservice.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virterror_internal.h"
#include "threads.h"
#include "c-ctype.h"
#include "virnetsocket.h"
#include "util.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virterror_internal.h"
#include "virlog.h"
#include "virfile.h"
#include "internal.h"
#include "virbuffer.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "configmake.h"
#include "threads.h"
#include "virnettlscontext.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virterror_internal.h"
#include "util.h"
#include "virlog.h"
#include "datatypes.h"
#include "driver.h"
#include "virlog.h"
-#include "memory.h"
+#include "viralloc.h"
#include "secret_conf.h"
#include "secret_driver.h"
#include "threads.h"
#include "security_apparmor.h"
#include "util.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virterror_internal.h"
#include "datatypes.h"
#include "uuid.h"
#include "security_dac.h"
#include "virterror_internal.h"
#include "util.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "pci.h"
#include "virusb.h"
#include "security_stack.h"
#include "security_dac.h"
#include "virterror_internal.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#define VIR_FROM_THIS VIR_FROM_SECURITY
#include "security_selinux.h"
#include "virterror_internal.h"
#include "util.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "pci.h"
#include "virusb.h"
#include "security_stack.h"
#include "virterror_internal.h"
-#include "memory.h"
+#include "viralloc.h"
#define VIR_FROM_THIS VIR_FROM_SECURITY
#include "internal.h"
#include "virbuffer.h"
#include "util.h"
-#include "memory.h"
+#include "viralloc.h"
#include "vircommand.h"
#include "security_driver.h"
#include "datatypes.h"
#include "virterror_internal.h"
#include "util.h"
-#include "memory.h"
+#include "viralloc.h"
#include "internal.h"
#include "secret_conf.h"
#include "uuid.h"
#include "virlog.h"
#include "storage_backend_disk.h"
#include "util.h"
-#include "memory.h"
+#include "viralloc.h"
#include "vircommand.h"
#include "configmake.h"
#include "storage_conf.h"
#include "storage_file.h"
#include "vircommand.h"
-#include "memory.h"
+#include "viralloc.h"
#include "xml.h"
#include "virfile.h"
#include "virlog.h"
#include "storage_backend_scsi.h"
#include "storage_backend_iscsi.h"
#include "util.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "virfile.h"
#include "vircommand.h"
#include "storage_backend_logical.h"
#include "storage_conf.h"
#include "vircommand.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "virfile.h"
#include "virterror_internal.h"
#include "storage_conf.h"
#include "storage_backend.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "virfile.h"
#include "storage_backend_rbd.h"
#include "storage_conf.h"
#include "util.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "base64.h"
#include "uuid.h"
#include "virterror_internal.h"
#include "storage_backend_scsi.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "virfile.h"
#include "vircommand.h"
#include "storage_conf.h"
#include "vircommand.h"
#include "util.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#define VIR_FROM_THIS VIR_FROM_STORAGE
#include "util.h"
#include "storage_driver.h"
#include "storage_conf.h"
-#include "memory.h"
+#include "viralloc.h"
#include "storage_backend.h"
#include "virlog.h"
#include "virfile.h"
#include "util.h"
#include "uuid.h"
#include "capabilities.h"
-#include "memory.h"
+#include "viralloc.h"
#include "network_conf.h"
#include "interface_conf.h"
#include "domain_conf.h"
#include "virbuffer.h"
#include "virconf.h"
#include "util.h"
-#include "memory.h"
+#include "viralloc.h"
#include "nodeinfo.h"
#include "virlog.h"
#include "domain_nwfilter.h"
#include "nodeinfo.h"
#include "stats_linux.h"
#include "capabilities.h"
-#include "memory.h"
+#include "viralloc.h"
#include "uuid.h"
#include "domain_conf.h"
#include "domain_audit.h"
#include "util.h"
#include "threads.h"
#include "virfile.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virterror_internal.h"
#include "configmake.h"
#include "virrandom.h"
+++ /dev/null
-/*
- * memory.c: safer memory allocation
- *
- * Copyright (C) 2010-2012 Red Hat, Inc.
- * Copyright (C) 2008 Daniel P. Berrange
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see
- * <http://www.gnu.org/licenses/>.
- *
- */
-
-#include <config.h>
-#include <stdlib.h>
-
-#include "memory.h"
-#include "virlog.h"
-
-#if TEST_OOM
-static int testMallocNext = 0;
-static int testMallocFailFirst = 0;
-static int testMallocFailLast = 0;
-static void (*testMallocHook)(int, void*) = NULL;
-static void *testMallocHookData = NULL;
-
-void virAllocTestInit(void)
-{
- testMallocNext = 1;
- testMallocFailFirst = 0;
- testMallocFailLast = 0;
-}
-
-int virAllocTestCount(void)
-{
- return testMallocNext - 1;
-}
-
-void virAllocTestHook(void (*func)(int, void*), void *data)
-{
- testMallocHook = func;
- testMallocHookData = data;
-}
-
-void virAllocTestOOM(int n, int m)
-{
- testMallocNext = 1;
- testMallocFailFirst = n;
- testMallocFailLast = n + m - 1;
-}
-
-static int virAllocTestFail(void)
-{
- int fail = 0;
- if (testMallocNext == 0)
- return 0;
-
- fail =
- testMallocNext >= testMallocFailFirst &&
- testMallocNext <= testMallocFailLast;
-
- if (fail && testMallocHook)
- (testMallocHook)(testMallocNext, testMallocHookData);
-
- testMallocNext++;
- return fail;
-}
-#endif
-
-
-/**
- * virAlloc:
- * @ptrptr: pointer to pointer for address of allocated memory
- * @size: number of bytes to allocate
- *
- * Allocate 'size' bytes of memory. Return the address of the
- * allocated memory in 'ptrptr'. The newly allocated memory is
- * filled with zeros.
- *
- * Returns -1 on failure to allocate, zero on success
- */
-int virAlloc(void *ptrptr, size_t size)
-{
-#if TEST_OOM
- if (virAllocTestFail()) {
- *(void **)ptrptr = NULL;
- return -1;
- }
-#endif
-
- *(void **)ptrptr = calloc(1, size);
- if (*(void **)ptrptr == NULL)
- return -1;
- return 0;
-}
-
-/**
- * virAllocN:
- * @ptrptr: pointer to pointer for address of allocated memory
- * @size: number of bytes to allocate
- * @count: number of elements to allocate
- *
- * Allocate an array of memory 'count' elements long,
- * each with 'size' bytes. Return the address of the
- * allocated memory in 'ptrptr'. The newly allocated
- * memory is filled with zeros.
- *
- * Returns -1 on failure to allocate, zero on success
- */
-int virAllocN(void *ptrptr, size_t size, size_t count)
-{
-#if TEST_OOM
- if (virAllocTestFail()) {
- *(void **)ptrptr = NULL;
- return -1;
- }
-#endif
-
- *(void**)ptrptr = calloc(count, size);
- if (*(void**)ptrptr == NULL)
- return -1;
- return 0;
-}
-
-/**
- * virReallocN:
- * @ptrptr: pointer to pointer for address of allocated memory
- * @size: number of bytes to allocate
- * @count: number of elements in array
- *
- * Resize the block of memory in 'ptrptr' to be an array of
- * 'count' elements, each 'size' bytes in length. Update 'ptrptr'
- * with the address of the newly allocated memory. On failure,
- * 'ptrptr' is not changed and still points to the original memory
- * block. Any newly allocated memory in 'ptrptr' is uninitialized.
- *
- * Returns -1 on failure to allocate, zero on success
- */
-int virReallocN(void *ptrptr, size_t size, size_t count)
-{
- void *tmp;
-#if TEST_OOM
- if (virAllocTestFail())
- return -1;
-#endif
-
- if (xalloc_oversized(count, size)) {
- errno = ENOMEM;
- return -1;
- }
- tmp = realloc(*(void**)ptrptr, size * count);
- if (!tmp && (size * count))
- return -1;
- *(void**)ptrptr = tmp;
- return 0;
-}
-
-/**
- * virExpandN:
- * @ptrptr: pointer to pointer for address of allocated memory
- * @size: number of bytes per element
- * @countptr: pointer to number of elements in array
- * @add: number of elements to add
- *
- * Resize the block of memory in 'ptrptr' to be an array of
- * '*countptr' + 'add' elements, each 'size' bytes in length.
- * Update 'ptrptr' and 'countptr' with the details of the newly
- * allocated memory. On failure, 'ptrptr' and 'countptr' are not
- * changed. Any newly allocated memory in 'ptrptr' is zero-filled.
- *
- * Returns -1 on failure to allocate, zero on success
- */
-int virExpandN(void *ptrptr, size_t size, size_t *countptr, size_t add)
-{
- int ret;
-
- if (*countptr + add < *countptr) {
- errno = ENOMEM;
- return -1;
- }
- ret = virReallocN(ptrptr, size, *countptr + add);
- if (ret == 0) {
- memset(*(char **)ptrptr + (size * *countptr), 0, size * add);
- *countptr += add;
- }
- return ret;
-}
-
-/**
- * virResizeN:
- * @ptrptr: pointer to pointer for address of allocated memory
- * @size: number of bytes per element
- * @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
- *
- * If 'count' + 'add' is larger than '*allocptr', then resize the
- * block of memory in 'ptrptr' to be an array of at least 'count' +
- * 'add' elements, each 'size' bytes in length. Update 'ptrptr' and
- * 'allocptr' with the details of the newly allocated memory. On
- * failure, 'ptrptr' and 'allocptr' are not changed. Any newly
- * allocated memory in 'ptrptr' is zero-filled.
- *
- * 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 delta;
-
- if (count + add < count) {
- errno = ENOMEM;
- return -1;
- }
- if (count + add <= *allocptr)
- return 0;
-
- delta = count + add - *allocptr;
- if (delta < *allocptr / 2)
- delta = *allocptr / 2;
- return virExpandN(ptrptr, size, allocptr, delta);
-}
-
-/**
- * virShrinkN:
- * @ptrptr: pointer to pointer for address of allocated memory
- * @size: number of bytes per element
- * @countptr: pointer to number of elements in array
- * @toremove: number of elements to remove
- *
- * Resize the block of memory in 'ptrptr' to be an array of
- * '*countptr' - 'toremove' elements, each 'size' bytes in length.
- * Update 'ptrptr' and 'countptr' with the details of the newly
- * allocated memory. If 'toremove' is larger than 'countptr', free
- * the entire array.
- */
-void virShrinkN(void *ptrptr, size_t size, size_t *countptr, size_t toremove)
-{
- if (toremove < *countptr)
- ignore_value(virReallocN(ptrptr, size, *countptr -= toremove));
- else {
- virFree(ptrptr);
- *countptr = 0;
- }
-}
-
-/**
- * virInsertElementsN:
- * @ptrptr: pointer to hold address of allocated memory
- * @size: the size of one element in bytes
- * @at: index within array where new elements should be added
- * @countptr: variable tracking number of elements currently allocated
- * @add: number of elements to add
- * @newelems: pointer to array of one or more new elements to move into
- * place (the originals will be zeroed out if successful
- * and if clearOriginal is true)
- * @clearOriginal: false if the new item in the array should be copied
- * from the original, and the original left intact.
- * true if the original should be 0'd out on success.
- * @inPlace: false if we should expand the allocated memory before
- * moving, true if we should assume someone else *has
- * already* done that.
- *
- * Re-allocate an array of *countptr elements, each sizeof(*ptrptr) bytes
- * long, to be *countptr+add elements long, then appropriately move
- * the elements starting at ptrptr[at] up by add elements, copy the
- * items from newelems into ptrptr[at], then store the address of
- * allocated memory in *ptrptr and the new size in *countptr. If
- * newelems is NULL, the new elements at ptrptr[at] are instead filled
- * with zero.
- *
- * Returns -1 on failure, 0 on success
- */
-int
-virInsertElementsN(void *ptrptr, size_t size, size_t at,
- size_t *countptr,
- size_t add, void *newelems,
- bool clearOriginal, bool inPlace)
-{
- if (at > *countptr) {
- VIR_WARN("out of bounds index - count %zu at %zu add %zu",
- *countptr, at, add);
- return -1;
- }
-
- if (inPlace) {
- *countptr += add;
- } else if (virExpandN(ptrptr, size, countptr, add) < 0) {
- return -1;
- }
-
- /* memory was successfully re-allocated. Move up all elements from
- * ptrptr[at] to the end (if we're not "inserting" at the end
- * already), memcpy in the new elements, and clear the elements
- * from their original location. Remember that *countptr has
- * already been updated with new element count!
- */
- if (at < *countptr - add) {
- memmove(*(char**)ptrptr + (size * (at + add)),
- *(char**)ptrptr + (size * at),
- size * (*countptr - add - at));
- }
-
- if (newelems) {
- memcpy(*(char**)ptrptr + (size * at), newelems, size * add);
- if (clearOriginal)
- memset((char*)newelems, 0, size * add);
- } else if (inPlace || (at < *countptr - add)) {
- /* NB: if inPlace, assume memory at the end wasn't initialized */
- memset(*(char**)ptrptr + (size * at), 0, size * add);
- }
-
- return 0;
-}
-
-/**
- * virDeleteElementsN:
- * @ptrptr: pointer to hold address of allocated memory
- * @size: the size of one element in bytes
- * @at: index within array where new elements should be deleted
- * @countptr: variable tracking number of elements currently allocated
- * @remove: number of elements to remove
- * @inPlace: false if we should shrink the allocated memory when done,
- * true if we should assume someone else will do that.
- *
- * Re-allocate an array of *countptr elements, each sizeof(*ptrptr)
- * bytes long, to be *countptr-remove elements long, then store the
- * address of allocated memory in *ptrptr and the new size in *countptr.
- * If *countptr <= remove, the entire array is freed.
- *
- * Returns -1 on failure, 0 on success
- */
-int
-virDeleteElementsN(void *ptrptr, size_t size, size_t at,
- size_t *countptr, size_t remove,
- bool inPlace)
-{
- if (at + remove > *countptr) {
- VIR_WARN("out of bounds index - count %zu at %zu remove %zu",
- *countptr, at, remove);
- return -1;
- }
-
- /* First move down the elements at the end that won't be deleted,
- * then realloc. We assume that the items being deleted have
- * already been cleared.
- */
- memmove(*(char**)ptrptr + (size * at),
- *(char**)ptrptr + (size * (at + remove)),
- size * (*countptr - remove - at));
- if (inPlace)
- *countptr -= remove;
- else
- virShrinkN(ptrptr, size, countptr, remove);
- return 0;
-}
-
-/**
- * Vir_Alloc_Var:
- * @ptrptr: pointer to hold address of allocated memory
- * @struct_size: size of initial struct
- * @element_size: size of array elements
- * @count: number of array elements to allocate
- *
- * Allocate struct_size bytes plus an array of 'count' elements, each
- * of size element_size. This sort of allocation is useful for
- * receiving the data of certain ioctls and other APIs which return a
- * struct in which the last element is an array of undefined length.
- * The caller of this type of API is expected to know the length of
- * the array that will be returned and allocate a suitable buffer to
- * contain the returned data. C99 refers to these variable length
- * objects as structs containing flexible array members.
- *
- * Returns -1 on failure, 0 on success
- */
-int virAllocVar(void *ptrptr, size_t struct_size, size_t element_size, size_t count)
-{
- size_t alloc_size = 0;
-
-#if TEST_OOM
- if (virAllocTestFail())
- return -1;
-#endif
-
- if (VIR_ALLOC_VAR_OVERSIZED(struct_size, count, element_size)) {
- errno = ENOMEM;
- return -1;
- }
-
- alloc_size = struct_size + (element_size * count);
- *(void **)ptrptr = calloc(1, alloc_size);
- if (*(void **)ptrptr == NULL)
- return -1;
- return 0;
-}
-
-
-/**
- * virFree:
- * @ptrptr: pointer to pointer for address of memory to be freed
- *
- * Release the chunk of memory in the pointer pointed to by
- * the 'ptrptr' variable. After release, 'ptrptr' will be
- * updated to point to NULL.
- */
-void virFree(void *ptrptr)
-{
- int save_errno = errno;
-
- free(*(void**)ptrptr);
- *(void**)ptrptr = NULL;
- errno = save_errno;
-}
+++ /dev/null
-/*
- * memory.c: safer memory allocation
- *
- * Copyright (C) 2010-2012 Red Hat, Inc.
- * Copyright (C) 2008 Daniel P. Berrange
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see
- * <http://www.gnu.org/licenses/>.
- *
- */
-
-
-#ifndef __VIR_MEMORY_H_
-# define __VIR_MEMORY_H_
-
-# include "internal.h"
-
-/* Return 1 if an array of N objects, each of size S, cannot exist due
- to size arithmetic overflow. S must be positive and N must be
- nonnegative. This is a macro, not an inline function, so that it
- works correctly even when SIZE_MAX < N.
-
- By gnulib convention, SIZE_MAX represents overflow in size
- calculations, so the conservative dividend to use here is
- SIZE_MAX - 1, since SIZE_MAX might represent an overflowed value.
- However, malloc (SIZE_MAX) fails on all known hosts where
- sizeof(ptrdiff_t) <= sizeof(size_t), so do not bother to test for
- exactly-SIZE_MAX allocations on such hosts; this avoids a test and
- branch when S is known to be 1. */
-# ifndef xalloc_oversized
-# define xalloc_oversized(n, s) \
- ((size_t) (sizeof(ptrdiff_t) <= sizeof(size_t) ? -1 : -2) / (s) < (n))
-# endif
-
-
-
-/* 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)
- 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)
- ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3);
-void virShrinkN(void *ptrptr, size_t size, size_t *count, size_t toremove)
- ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3);
-int virInsertElementsN(void *ptrptr, size_t size, size_t at, size_t *countptr,
- size_t add, void *newelem,
- bool clearOriginal, bool inPlace)
- ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4);
-int virDeleteElementsN(void *ptrptr, size_t size, size_t at, size_t *countptr,
- size_t remove, bool inPlace)
- ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4);
-int virAllocVar(void *ptrptr,
- size_t struct_size,
- size_t element_size,
- size_t count) ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NONNULL(1);
-void virFree(void *ptrptr) ATTRIBUTE_NONNULL(1);
-
-/**
- * VIR_ALLOC:
- * @ptr: pointer to hold address of allocated memory
- *
- * Allocate sizeof(*ptr) bytes of memory and store
- * the address of allocated memory in 'ptr'. Fill the
- * newly allocated memory with zeros.
- *
- * Returns -1 on failure, 0 on success
- */
-# define VIR_ALLOC(ptr) virAlloc(&(ptr), sizeof(*(ptr)))
-
-/**
- * VIR_ALLOC_N:
- * @ptr: pointer to hold address of allocated memory
- * @count: number of elements to allocate
- *
- * Allocate an array of 'count' elements, each sizeof(*ptr)
- * bytes long and store the address of allocated memory in
- * 'ptr'. Fill the newly allocated memory with zeros.
- *
- * Returns -1 on failure, 0 on success
- */
-# define VIR_ALLOC_N(ptr, count) virAllocN(&(ptr), sizeof(*(ptr)), (count))
-
-/**
- * VIR_REALLOC_N:
- * @ptr: pointer to hold address of allocated memory
- * @count: number of elements to allocate
- *
- * Re-allocate an array of 'count' elements, each sizeof(*ptr)
- * bytes long and store the address of allocated memory in
- * 'ptr'. If 'ptr' grew, the added memory is uninitialized.
- *
- * Returns -1 on failure, 0 on success
- */
-# define VIR_REALLOC_N(ptr, count) virReallocN(&(ptr), sizeof(*(ptr)), (count))
-
-/**
- * VIR_EXPAND_N:
- * @ptr: pointer to hold address of allocated memory
- * @count: variable tracking number of elements currently allocated
- * @add: number of elements to add
- *
- * Re-allocate an array of 'count' elements, each sizeof(*ptr)
- * bytes long, to be 'count' + 'add' elements long, then store the
- * address of allocated memory in 'ptr' and the new size in 'count'.
- * The new elements are filled with zero.
- *
- * Returns -1 on failure, 0 on success
- */
-# define VIR_EXPAND_N(ptr, count, add) \
- virExpandN(&(ptr), sizeof(*(ptr)), &(count), add)
-
-/**
- * VIR_RESIZE_N:
- * @ptr: pointer to hold address of allocated memory
- * @alloc: variable tracking number of elements currently allocated
- * @count: number of elements currently in use
- * @add: minimum number of elements to additionally support
- *
- * Blindly using VIR_EXPAND_N(array, alloc, 1) in a loop scales
- * quadratically, because every iteration must copy contents from
- * all prior iterations. But amortized linear scaling can be achieved
- * by tracking allocation size separately from the number of used
- * elements, and growing geometrically only as needed.
- *
- * If 'count' + 'add' is larger than 'alloc', then geometrically reallocate
- * the array of 'alloc' elements, each sizeof(*ptr) bytes long, and store
- * the address of allocated memory in 'ptr' and the new size in 'alloc'.
- * The new elements are filled with zero.
- *
- * Returns -1 on failure, 0 on success
- */
-# define VIR_RESIZE_N(ptr, alloc, count, add) \
- virResizeN(&(ptr), sizeof(*(ptr)), &(alloc), count, add)
-
-/**
- * VIR_SHRINK_N:
- * @ptr: pointer to hold address of allocated memory
- * @count: variable tracking number of elements currently allocated
- * @remove: number of elements to remove
- *
- * Re-allocate an array of 'count' elements, each sizeof(*ptr)
- * bytes long, to be 'count' - 'remove' elements long, then store the
- * address of allocated memory in 'ptr' and the new size in 'count'.
- * If 'count' <= 'remove', the entire array is freed.
- *
- * No return value.
- */
-# define VIR_SHRINK_N(ptr, count, remove) \
- virShrinkN(&(ptr), sizeof(*(ptr)), &(count), remove)
-
-/*
- * VIR_TYPEMATCH:
- *
- * The following macro seems a bit cryptic, so it needs a thorough
- * explanation. Its purpose is to check for assignment compatibility
- * and identical size between two values without creating any side
- * effects (by doing something silly like actually assigning one to
- * the other). Note that it takes advantage of the C89-guaranteed
- * property of sizeof() - it cannot have any side effects, so anything
- * that happens inside sizeof() will not have any effect at runtime.
- *
- * VIR_TYPEMATCH evaluates to "1" if the two passed values are both
- * assignment-compatible and the same size, and otherwise generates a
- * compile-time error. It determines the result by performing the
- * following three operations:
- *
- * * sizeof(*(a) = *(b)) assures that *a and *b are
- * assignment-compatible (they may still have a different size
- * though! e.g. longVar = intVar) (If not, there is a compile-time
- * error. If so, the result of that subexpression is sizeof(*(a)),
- * i.e. one element of the array)
- *
- * * sizeof(*(a) = *(b)) == sizeof(*(b)) checks if *a and *b are also
- * of the same size (so that, e.g. you don't accidentally copy an
- * int plus the random bytes following it into an array of long). It
- * evaluates to 1 if they are the same, and 0 otherwise.
- *
- * * sizeof(char[2 * (result of previous step) - 1]) evaluates to 1
- * if the previous step was successful (char [(2*1) - 1] i.e.
- * char[1]), or generates a compile error if it wasn't successful
- * (char[2*0 -1] i.e. char[-1], which isn't valid in C).
- *
- * So VIR_TYPECHECK(a, b) will either abort the compile with an error,
- * or evaluate to "1", and in the meantime check that we've actually
- * added the correct &'s and/or *'s to the arguments. (Whew!)
-*/
-# define VIR_TYPEMATCH(a, b) \
- sizeof(char[2 * (sizeof(*(a) = *(b)) == sizeof(*(b))) - 1])
-
-/**
- * VIR_INSERT_ELEMENT:
- * @ptr: pointer to array of objects (*not* ptr to ptr)
- * @at: index within array where new elements should be added
- * @count: variable tracking number of elements currently allocated
- * @newelem: the new element to move into place (*not* a pointer to
- * the element, but the element itself).
- * (the original will be zeroed out if successful)
- *
- * Re-allocate an array of 'count' elements, each sizeof(*ptr) bytes
- * long, to be 'count' + 1 elements long, then appropriately move
- * the elements starting at ptr[at] up by 1 element, copy the
- * item 'newelem' into ptr[at], then store the address of
- * allocated memory in 'ptr' and the new size in 'count'.
- *
- * VIR_INSERT_ELEMENT_COPY is identical, but doesn't clear out the
- * original element to 0 on success, so there are two copies of the
- * element. This is useful if the "element" is actually just a
- * pointer to the real data, and you want to maintain a reference to
- * it for use after the insert is completed; but if the "element" is
- * an object that points to other allocated memory, having multiple
- * copies can cause problems (e.g. double free).
- *
- * VIR_INSERT_ELEMENT_*INPLACE are identical, but assume any necessary
- * memory re-allocation has already been done.
- *
- * VIR_INSERT_ELEMENT_* all need to send "1" as the "add" argument to
- * virInsertElementsN (which has the currently-unused capability of
- * inserting multiple items at once). We use this to our advantage by
- * replacing it with VIR_TYPECHECK(ptr, &newelem) so that we can be
- * assured ptr and &newelem are of compatible types.
- *
- * Returns -1 on failure, 0 on success
- *
- *
- */
-# define VIR_INSERT_ELEMENT(ptr, at, count, newelem) \
- virInsertElementsN(&(ptr), sizeof(*(ptr)), at, &(count), \
- VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), true, false)
-# define VIR_INSERT_ELEMENT_COPY(ptr, at, count, newelem) \
- virInsertElementsN(&(ptr), sizeof(*(ptr)), at, &(count), \
- VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), false, false)
-# define VIR_INSERT_ELEMENT_INPLACE(ptr, at, count, newelem) \
- virInsertElementsN(&(ptr), sizeof(*(ptr)), at, &(count), \
- VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), true, true)
-# define VIR_INSERT_ELEMENT_COPY_INPLACE(ptr, at, count, newelem) \
- virInsertElementsN(&(ptr), sizeof(*(ptr)), at, &(count), \
- VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), false, true)
-
-/**
- * VIR_APPEND_ELEMENT:
- * @ptr: pointer to array of objects (*not* ptr to ptr)
- * @count: variable tracking number of elements currently allocated
- * @newelem: the new element to move into place (*not* a pointer to
- * the element, but the element itself).
- * (the original will be zeroed out if successful)
- *
- * Re-allocate an array of 'count' elements, each sizeof(*ptr) bytes
- * long, to be 'count' + 1 elements long, then copy the item from
- * 'newelem' into ptr[count+1], and store the address of allocated
- * memory in 'ptr' and the new size in 'count'. If 'newelem' is NULL,
- * the new element at ptr[at] is instead filled with zero.
- *
- * VIR_APPEND_ELEMENT_COPY is identical, but doesn't clear out the
- * original element to 0 on success, so there are two copies of the
- * element. This is useful if the "element" is actually just a
- * pointer to the real data, and you want to maintain a reference to
- * it for use after the append is completed; but if the "element" is
- * an object that points to other allocated memory, having multiple
- * copies can cause problems (e.g. double free).
- *
- * VIR_APPEND_ELEMENT_*INPLACE are identical, but assume any
- * necessary memory re-allocation has already been done.
- *
- * VIR_APPEND_ELEMENT_* all need to send "1" as the "add" argument to
- * virInsertElementsN (which has the currently-unused capability of
- * inserting multiple items at once). We use this to our advantage by
- * replacing it with VIR_TYPECHECK(ptr, &newelem) so that we can be
- * assured ptr and &newelem are of compatible types.
- *
- * Returns -1 on failure, 0 on success
- *
- *
- */
-# define VIR_APPEND_ELEMENT(ptr, count, newelem) \
- virInsertElementsN(&(ptr), sizeof(*(ptr)), count, &(count), \
- VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), true, false)
-# define VIR_APPEND_ELEMENT_COPY(ptr, count, newelem) \
- virInsertElementsN(&(ptr), sizeof(*(ptr)), count, &(count), \
- VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), false, false)
-# define VIR_APPEND_ELEMENT_INPLACE(ptr, count, newelem) \
- virInsertElementsN(&(ptr), sizeof(*(ptr)), count, &(count), \
- VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), true, true)
-# define VIR_APPEND_ELEMENT_COPY_INPLACE(ptr, count, newelem) \
- virInsertElementsN(&(ptr), sizeof(*(ptr)), count, &(count), \
- VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), false, true)
-
-/**
- * VIR_DELETE_ELEMENT:
- * @ptr: pointer to array of objects (*not* ptr to ptr)
- * @at: index within array where new elements should be deleted
- * @count: variable tracking number of elements currently allocated
- *
- * Re-allocate an array of 'count' elements, each sizeof(*ptr)
- * bytes long, to be 'count' - 1 elements long, then store the
- * address of allocated memory in 'ptr' and the new size in 'count'.
- * If 'count' <= 1, the entire array is freed.
- *
- * VIR_DELETE_ELEMENT_INPLACE is identical, but assumes any
- * necessary memory re-allocation will be done later.
- *
- * Returns -1 on failure, 0 on success
- */
-# define VIR_DELETE_ELEMENT(ptr, at, count) \
- virDeleteElementsN(&(ptr), sizeof(*(ptr)), at, &(count), 1, false)
-# define VIR_DELETE_ELEMENT_INPLACE(ptr, at, count) \
- virDeleteElementsN(&(ptr), sizeof(*(ptr)), at, &(count), 1, true)
-
-/*
- * VIR_ALLOC_VAR_OVERSIZED:
- * @M: size of base structure
- * @N: number of array elements in trailing array
- * @S: size of trailing array elements
- *
- * Check to make sure that the requested allocation will not cause
- * arithmetic overflow in the allocation size. The check is
- * essentially the same as that in gnulib's xalloc_oversized.
- */
-# define VIR_ALLOC_VAR_OVERSIZED(M, N, S) ((((size_t)-1) - (M)) / (S) < (N))
-
-/**
- * VIR_ALLOC_VAR:
- * @ptr: pointer to hold address of allocated memory
- * @type: element type of trailing array
- * @count: number of array elements to allocate
- *
- * Allocate sizeof(*ptr) bytes plus an array of 'count' elements, each
- * sizeof('type'). This sort of allocation is useful for receiving
- * the data of certain ioctls and other APIs which return a struct in
- * which the last element is an array of undefined length. The caller
- * of this type of API is expected to know the length of the array
- * that will be returned and allocate a suitable buffer to contain the
- * returned data. C99 refers to these variable length objects as
- * structs containing flexible array members.
-
- * Returns -1 on failure, 0 on success
- */
-# define VIR_ALLOC_VAR(ptr, type, count) \
- virAllocVar(&(ptr), sizeof(*(ptr)), sizeof(type), (count))
-
-/**
- * VIR_FREE:
- * @ptr: pointer holding address to be freed
- *
- * Free the memory stored in 'ptr' and update to point
- * to NULL.
- */
-/* The ternary ensures that ptr is a pointer and not an integer type,
- * while evaluating ptr only once. For now, we intentionally cast
- * away const, since a number of callers safely pass const char *.
- */
-# define VIR_FREE(ptr) virFree((void *) (1 ? (const void *) &(ptr) : (ptr)))
-
-
-# if TEST_OOM
-void virAllocTestInit(void);
-int virAllocTestCount(void);
-void virAllocTestOOM(int n, int m);
-void virAllocTestHook(void (*func)(int, void*), void *data);
-# endif
-
-
-
-#endif /* __VIR_MEMORY_H_ */
#include <stdlib.h>
#include "virlog.h"
-#include "memory.h"
+#include "viralloc.h"
#include "vircommand.h"
#include "virterror_internal.h"
#include "virfile.h"
#include "virterror_internal.h"
#include "sexpr.h"
#include "util.h"
-#include "memory.h"
+#include "viralloc.h"
#define VIR_FROM_THIS VIR_FROM_SEXPR
# include "datatypes.h"
# include "util.h"
# include "stats_linux.h"
-# include "memory.h"
+# include "viralloc.h"
# include "virfile.h"
# define VIR_FROM_THIS VIR_FROM_STATS_LINUX
# include <sys/statfs.h>
#endif
#include "dirname.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virterror_internal.h"
#include "virlog.h"
#include "virfile.h"
#include "sysinfo.h"
#include "util.h"
#include "virlog.h"
-#include "memory.h"
+#include "viralloc.h"
#include "vircommand.h"
#define VIR_FROM_THIS VIR_FROM_SYSINFO
#include <config.h>
#include "threadpool.h"
-#include "memory.h"
+#include "viralloc.h"
#include "threads.h"
#include "virterror_internal.h"
# include <sys/syscall.h>
#endif
-#include "memory.h"
+#include "viralloc.h"
/* Nothing special required for pthreads */
#include <process.h>
-#include "memory.h"
+#include "viralloc.h"
struct virThreadLocalData {
DWORD key;
#include "virbuffer.h"
#include "util.h"
#include "storage_file.h"
-#include "memory.h"
+#include "viralloc.h"
#include "threads.h"
#include "verify.h"
#include "virfile.h"
#include "util.h"
#include "virterror_internal.h"
#include "virlog.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virfile.h"
#include "virrandom.h"
--- /dev/null
+/*
+ * viralloc.c: safer memory allocation
+ *
+ * Copyright (C) 2010-2012 Red Hat, Inc.
+ * Copyright (C) 2008 Daniel P. Berrange
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <config.h>
+#include <stdlib.h>
+
+#include "viralloc.h"
+#include "virlog.h"
+
+#if TEST_OOM
+static int testMallocNext = 0;
+static int testMallocFailFirst = 0;
+static int testMallocFailLast = 0;
+static void (*testMallocHook)(int, void*) = NULL;
+static void *testMallocHookData = NULL;
+
+void virAllocTestInit(void)
+{
+ testMallocNext = 1;
+ testMallocFailFirst = 0;
+ testMallocFailLast = 0;
+}
+
+int virAllocTestCount(void)
+{
+ return testMallocNext - 1;
+}
+
+void virAllocTestHook(void (*func)(int, void*), void *data)
+{
+ testMallocHook = func;
+ testMallocHookData = data;
+}
+
+void virAllocTestOOM(int n, int m)
+{
+ testMallocNext = 1;
+ testMallocFailFirst = n;
+ testMallocFailLast = n + m - 1;
+}
+
+static int virAllocTestFail(void)
+{
+ int fail = 0;
+ if (testMallocNext == 0)
+ return 0;
+
+ fail =
+ testMallocNext >= testMallocFailFirst &&
+ testMallocNext <= testMallocFailLast;
+
+ if (fail && testMallocHook)
+ (testMallocHook)(testMallocNext, testMallocHookData);
+
+ testMallocNext++;
+ return fail;
+}
+#endif
+
+
+/**
+ * virAlloc:
+ * @ptrptr: pointer to pointer for address of allocated memory
+ * @size: number of bytes to allocate
+ *
+ * Allocate 'size' bytes of memory. Return the address of the
+ * allocated memory in 'ptrptr'. The newly allocated memory is
+ * filled with zeros.
+ *
+ * Returns -1 on failure to allocate, zero on success
+ */
+int virAlloc(void *ptrptr, size_t size)
+{
+#if TEST_OOM
+ if (virAllocTestFail()) {
+ *(void **)ptrptr = NULL;
+ return -1;
+ }
+#endif
+
+ *(void **)ptrptr = calloc(1, size);
+ if (*(void **)ptrptr == NULL)
+ return -1;
+ return 0;
+}
+
+/**
+ * virAllocN:
+ * @ptrptr: pointer to pointer for address of allocated memory
+ * @size: number of bytes to allocate
+ * @count: number of elements to allocate
+ *
+ * Allocate an array of memory 'count' elements long,
+ * each with 'size' bytes. Return the address of the
+ * allocated memory in 'ptrptr'. The newly allocated
+ * memory is filled with zeros.
+ *
+ * Returns -1 on failure to allocate, zero on success
+ */
+int virAllocN(void *ptrptr, size_t size, size_t count)
+{
+#if TEST_OOM
+ if (virAllocTestFail()) {
+ *(void **)ptrptr = NULL;
+ return -1;
+ }
+#endif
+
+ *(void**)ptrptr = calloc(count, size);
+ if (*(void**)ptrptr == NULL)
+ return -1;
+ return 0;
+}
+
+/**
+ * virReallocN:
+ * @ptrptr: pointer to pointer for address of allocated memory
+ * @size: number of bytes to allocate
+ * @count: number of elements in array
+ *
+ * Resize the block of memory in 'ptrptr' to be an array of
+ * 'count' elements, each 'size' bytes in length. Update 'ptrptr'
+ * with the address of the newly allocated memory. On failure,
+ * 'ptrptr' is not changed and still points to the original memory
+ * block. Any newly allocated memory in 'ptrptr' is uninitialized.
+ *
+ * Returns -1 on failure to allocate, zero on success
+ */
+int virReallocN(void *ptrptr, size_t size, size_t count)
+{
+ void *tmp;
+#if TEST_OOM
+ if (virAllocTestFail())
+ return -1;
+#endif
+
+ if (xalloc_oversized(count, size)) {
+ errno = ENOMEM;
+ return -1;
+ }
+ tmp = realloc(*(void**)ptrptr, size * count);
+ if (!tmp && (size * count))
+ return -1;
+ *(void**)ptrptr = tmp;
+ return 0;
+}
+
+/**
+ * virExpandN:
+ * @ptrptr: pointer to pointer for address of allocated memory
+ * @size: number of bytes per element
+ * @countptr: pointer to number of elements in array
+ * @add: number of elements to add
+ *
+ * Resize the block of memory in 'ptrptr' to be an array of
+ * '*countptr' + 'add' elements, each 'size' bytes in length.
+ * Update 'ptrptr' and 'countptr' with the details of the newly
+ * allocated memory. On failure, 'ptrptr' and 'countptr' are not
+ * changed. Any newly allocated memory in 'ptrptr' is zero-filled.
+ *
+ * Returns -1 on failure to allocate, zero on success
+ */
+int virExpandN(void *ptrptr, size_t size, size_t *countptr, size_t add)
+{
+ int ret;
+
+ if (*countptr + add < *countptr) {
+ errno = ENOMEM;
+ return -1;
+ }
+ ret = virReallocN(ptrptr, size, *countptr + add);
+ if (ret == 0) {
+ memset(*(char **)ptrptr + (size * *countptr), 0, size * add);
+ *countptr += add;
+ }
+ return ret;
+}
+
+/**
+ * virResizeN:
+ * @ptrptr: pointer to pointer for address of allocated memory
+ * @size: number of bytes per element
+ * @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
+ *
+ * If 'count' + 'add' is larger than '*allocptr', then resize the
+ * block of memory in 'ptrptr' to be an array of at least 'count' +
+ * 'add' elements, each 'size' bytes in length. Update 'ptrptr' and
+ * 'allocptr' with the details of the newly allocated memory. On
+ * failure, 'ptrptr' and 'allocptr' are not changed. Any newly
+ * allocated memory in 'ptrptr' is zero-filled.
+ *
+ * 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 delta;
+
+ if (count + add < count) {
+ errno = ENOMEM;
+ return -1;
+ }
+ if (count + add <= *allocptr)
+ return 0;
+
+ delta = count + add - *allocptr;
+ if (delta < *allocptr / 2)
+ delta = *allocptr / 2;
+ return virExpandN(ptrptr, size, allocptr, delta);
+}
+
+/**
+ * virShrinkN:
+ * @ptrptr: pointer to pointer for address of allocated memory
+ * @size: number of bytes per element
+ * @countptr: pointer to number of elements in array
+ * @toremove: number of elements to remove
+ *
+ * Resize the block of memory in 'ptrptr' to be an array of
+ * '*countptr' - 'toremove' elements, each 'size' bytes in length.
+ * Update 'ptrptr' and 'countptr' with the details of the newly
+ * allocated memory. If 'toremove' is larger than 'countptr', free
+ * the entire array.
+ */
+void virShrinkN(void *ptrptr, size_t size, size_t *countptr, size_t toremove)
+{
+ if (toremove < *countptr)
+ ignore_value(virReallocN(ptrptr, size, *countptr -= toremove));
+ else {
+ virFree(ptrptr);
+ *countptr = 0;
+ }
+}
+
+/**
+ * virInsertElementsN:
+ * @ptrptr: pointer to hold address of allocated memory
+ * @size: the size of one element in bytes
+ * @at: index within array where new elements should be added
+ * @countptr: variable tracking number of elements currently allocated
+ * @add: number of elements to add
+ * @newelems: pointer to array of one or more new elements to move into
+ * place (the originals will be zeroed out if successful
+ * and if clearOriginal is true)
+ * @clearOriginal: false if the new item in the array should be copied
+ * from the original, and the original left intact.
+ * true if the original should be 0'd out on success.
+ * @inPlace: false if we should expand the allocated memory before
+ * moving, true if we should assume someone else *has
+ * already* done that.
+ *
+ * Re-allocate an array of *countptr elements, each sizeof(*ptrptr) bytes
+ * long, to be *countptr+add elements long, then appropriately move
+ * the elements starting at ptrptr[at] up by add elements, copy the
+ * items from newelems into ptrptr[at], then store the address of
+ * allocated memory in *ptrptr and the new size in *countptr. If
+ * newelems is NULL, the new elements at ptrptr[at] are instead filled
+ * with zero.
+ *
+ * Returns -1 on failure, 0 on success
+ */
+int
+virInsertElementsN(void *ptrptr, size_t size, size_t at,
+ size_t *countptr,
+ size_t add, void *newelems,
+ bool clearOriginal, bool inPlace)
+{
+ if (at > *countptr) {
+ VIR_WARN("out of bounds index - count %zu at %zu add %zu",
+ *countptr, at, add);
+ return -1;
+ }
+
+ if (inPlace) {
+ *countptr += add;
+ } else if (virExpandN(ptrptr, size, countptr, add) < 0) {
+ return -1;
+ }
+
+ /* memory was successfully re-allocated. Move up all elements from
+ * ptrptr[at] to the end (if we're not "inserting" at the end
+ * already), memcpy in the new elements, and clear the elements
+ * from their original location. Remember that *countptr has
+ * already been updated with new element count!
+ */
+ if (at < *countptr - add) {
+ memmove(*(char**)ptrptr + (size * (at + add)),
+ *(char**)ptrptr + (size * at),
+ size * (*countptr - add - at));
+ }
+
+ if (newelems) {
+ memcpy(*(char**)ptrptr + (size * at), newelems, size * add);
+ if (clearOriginal)
+ memset((char*)newelems, 0, size * add);
+ } else if (inPlace || (at < *countptr - add)) {
+ /* NB: if inPlace, assume memory at the end wasn't initialized */
+ memset(*(char**)ptrptr + (size * at), 0, size * add);
+ }
+
+ return 0;
+}
+
+/**
+ * virDeleteElementsN:
+ * @ptrptr: pointer to hold address of allocated memory
+ * @size: the size of one element in bytes
+ * @at: index within array where new elements should be deleted
+ * @countptr: variable tracking number of elements currently allocated
+ * @remove: number of elements to remove
+ * @inPlace: false if we should shrink the allocated memory when done,
+ * true if we should assume someone else will do that.
+ *
+ * Re-allocate an array of *countptr elements, each sizeof(*ptrptr)
+ * bytes long, to be *countptr-remove elements long, then store the
+ * address of allocated memory in *ptrptr and the new size in *countptr.
+ * If *countptr <= remove, the entire array is freed.
+ *
+ * Returns -1 on failure, 0 on success
+ */
+int
+virDeleteElementsN(void *ptrptr, size_t size, size_t at,
+ size_t *countptr, size_t remove,
+ bool inPlace)
+{
+ if (at + remove > *countptr) {
+ VIR_WARN("out of bounds index - count %zu at %zu remove %zu",
+ *countptr, at, remove);
+ return -1;
+ }
+
+ /* First move down the elements at the end that won't be deleted,
+ * then realloc. We assume that the items being deleted have
+ * already been cleared.
+ */
+ memmove(*(char**)ptrptr + (size * at),
+ *(char**)ptrptr + (size * (at + remove)),
+ size * (*countptr - remove - at));
+ if (inPlace)
+ *countptr -= remove;
+ else
+ virShrinkN(ptrptr, size, countptr, remove);
+ return 0;
+}
+
+/**
+ * Vir_Alloc_Var:
+ * @ptrptr: pointer to hold address of allocated memory
+ * @struct_size: size of initial struct
+ * @element_size: size of array elements
+ * @count: number of array elements to allocate
+ *
+ * Allocate struct_size bytes plus an array of 'count' elements, each
+ * of size element_size. This sort of allocation is useful for
+ * receiving the data of certain ioctls and other APIs which return a
+ * struct in which the last element is an array of undefined length.
+ * The caller of this type of API is expected to know the length of
+ * the array that will be returned and allocate a suitable buffer to
+ * contain the returned data. C99 refers to these variable length
+ * objects as structs containing flexible array members.
+ *
+ * Returns -1 on failure, 0 on success
+ */
+int virAllocVar(void *ptrptr, size_t struct_size, size_t element_size, size_t count)
+{
+ size_t alloc_size = 0;
+
+#if TEST_OOM
+ if (virAllocTestFail())
+ return -1;
+#endif
+
+ if (VIR_ALLOC_VAR_OVERSIZED(struct_size, count, element_size)) {
+ errno = ENOMEM;
+ return -1;
+ }
+
+ alloc_size = struct_size + (element_size * count);
+ *(void **)ptrptr = calloc(1, alloc_size);
+ if (*(void **)ptrptr == NULL)
+ return -1;
+ return 0;
+}
+
+
+/**
+ * virFree:
+ * @ptrptr: pointer to pointer for address of memory to be freed
+ *
+ * Release the chunk of memory in the pointer pointed to by
+ * the 'ptrptr' variable. After release, 'ptrptr' will be
+ * updated to point to NULL.
+ */
+void virFree(void *ptrptr)
+{
+ int save_errno = errno;
+
+ free(*(void**)ptrptr);
+ *(void**)ptrptr = NULL;
+ errno = save_errno;
+}
--- /dev/null
+/*
+ * viralloc.h: safer memory allocation
+ *
+ * Copyright (C) 2010-2012 Red Hat, Inc.
+ * Copyright (C) 2008 Daniel P. Berrange
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ */
+
+
+#ifndef __VIR_MEMORY_H_
+# define __VIR_MEMORY_H_
+
+# include "internal.h"
+
+/* Return 1 if an array of N objects, each of size S, cannot exist due
+ to size arithmetic overflow. S must be positive and N must be
+ nonnegative. This is a macro, not an inline function, so that it
+ works correctly even when SIZE_MAX < N.
+
+ By gnulib convention, SIZE_MAX represents overflow in size
+ calculations, so the conservative dividend to use here is
+ SIZE_MAX - 1, since SIZE_MAX might represent an overflowed value.
+ However, malloc (SIZE_MAX) fails on all known hosts where
+ sizeof(ptrdiff_t) <= sizeof(size_t), so do not bother to test for
+ exactly-SIZE_MAX allocations on such hosts; this avoids a test and
+ branch when S is known to be 1. */
+# ifndef xalloc_oversized
+# define xalloc_oversized(n, s) \
+ ((size_t) (sizeof(ptrdiff_t) <= sizeof(size_t) ? -1 : -2) / (s) < (n))
+# endif
+
+
+
+/* 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)
+ 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)
+ ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3);
+void virShrinkN(void *ptrptr, size_t size, size_t *count, size_t toremove)
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3);
+int virInsertElementsN(void *ptrptr, size_t size, size_t at, size_t *countptr,
+ size_t add, void *newelem,
+ bool clearOriginal, bool inPlace)
+ ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4);
+int virDeleteElementsN(void *ptrptr, size_t size, size_t at, size_t *countptr,
+ size_t remove, bool inPlace)
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4);
+int virAllocVar(void *ptrptr,
+ size_t struct_size,
+ size_t element_size,
+ size_t count) ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NONNULL(1);
+void virFree(void *ptrptr) ATTRIBUTE_NONNULL(1);
+
+/**
+ * VIR_ALLOC:
+ * @ptr: pointer to hold address of allocated memory
+ *
+ * Allocate sizeof(*ptr) bytes of memory and store
+ * the address of allocated memory in 'ptr'. Fill the
+ * newly allocated memory with zeros.
+ *
+ * Returns -1 on failure, 0 on success
+ */
+# define VIR_ALLOC(ptr) virAlloc(&(ptr), sizeof(*(ptr)))
+
+/**
+ * VIR_ALLOC_N:
+ * @ptr: pointer to hold address of allocated memory
+ * @count: number of elements to allocate
+ *
+ * Allocate an array of 'count' elements, each sizeof(*ptr)
+ * bytes long and store the address of allocated memory in
+ * 'ptr'. Fill the newly allocated memory with zeros.
+ *
+ * Returns -1 on failure, 0 on success
+ */
+# define VIR_ALLOC_N(ptr, count) virAllocN(&(ptr), sizeof(*(ptr)), (count))
+
+/**
+ * VIR_REALLOC_N:
+ * @ptr: pointer to hold address of allocated memory
+ * @count: number of elements to allocate
+ *
+ * Re-allocate an array of 'count' elements, each sizeof(*ptr)
+ * bytes long and store the address of allocated memory in
+ * 'ptr'. If 'ptr' grew, the added memory is uninitialized.
+ *
+ * Returns -1 on failure, 0 on success
+ */
+# define VIR_REALLOC_N(ptr, count) virReallocN(&(ptr), sizeof(*(ptr)), (count))
+
+/**
+ * VIR_EXPAND_N:
+ * @ptr: pointer to hold address of allocated memory
+ * @count: variable tracking number of elements currently allocated
+ * @add: number of elements to add
+ *
+ * Re-allocate an array of 'count' elements, each sizeof(*ptr)
+ * bytes long, to be 'count' + 'add' elements long, then store the
+ * address of allocated memory in 'ptr' and the new size in 'count'.
+ * The new elements are filled with zero.
+ *
+ * Returns -1 on failure, 0 on success
+ */
+# define VIR_EXPAND_N(ptr, count, add) \
+ virExpandN(&(ptr), sizeof(*(ptr)), &(count), add)
+
+/**
+ * VIR_RESIZE_N:
+ * @ptr: pointer to hold address of allocated memory
+ * @alloc: variable tracking number of elements currently allocated
+ * @count: number of elements currently in use
+ * @add: minimum number of elements to additionally support
+ *
+ * Blindly using VIR_EXPAND_N(array, alloc, 1) in a loop scales
+ * quadratically, because every iteration must copy contents from
+ * all prior iterations. But amortized linear scaling can be achieved
+ * by tracking allocation size separately from the number of used
+ * elements, and growing geometrically only as needed.
+ *
+ * If 'count' + 'add' is larger than 'alloc', then geometrically reallocate
+ * the array of 'alloc' elements, each sizeof(*ptr) bytes long, and store
+ * the address of allocated memory in 'ptr' and the new size in 'alloc'.
+ * The new elements are filled with zero.
+ *
+ * Returns -1 on failure, 0 on success
+ */
+# define VIR_RESIZE_N(ptr, alloc, count, add) \
+ virResizeN(&(ptr), sizeof(*(ptr)), &(alloc), count, add)
+
+/**
+ * VIR_SHRINK_N:
+ * @ptr: pointer to hold address of allocated memory
+ * @count: variable tracking number of elements currently allocated
+ * @remove: number of elements to remove
+ *
+ * Re-allocate an array of 'count' elements, each sizeof(*ptr)
+ * bytes long, to be 'count' - 'remove' elements long, then store the
+ * address of allocated memory in 'ptr' and the new size in 'count'.
+ * If 'count' <= 'remove', the entire array is freed.
+ *
+ * No return value.
+ */
+# define VIR_SHRINK_N(ptr, count, remove) \
+ virShrinkN(&(ptr), sizeof(*(ptr)), &(count), remove)
+
+/*
+ * VIR_TYPEMATCH:
+ *
+ * The following macro seems a bit cryptic, so it needs a thorough
+ * explanation. Its purpose is to check for assignment compatibility
+ * and identical size between two values without creating any side
+ * effects (by doing something silly like actually assigning one to
+ * the other). Note that it takes advantage of the C89-guaranteed
+ * property of sizeof() - it cannot have any side effects, so anything
+ * that happens inside sizeof() will not have any effect at runtime.
+ *
+ * VIR_TYPEMATCH evaluates to "1" if the two passed values are both
+ * assignment-compatible and the same size, and otherwise generates a
+ * compile-time error. It determines the result by performing the
+ * following three operations:
+ *
+ * * sizeof(*(a) = *(b)) assures that *a and *b are
+ * assignment-compatible (they may still have a different size
+ * though! e.g. longVar = intVar) (If not, there is a compile-time
+ * error. If so, the result of that subexpression is sizeof(*(a)),
+ * i.e. one element of the array)
+ *
+ * * sizeof(*(a) = *(b)) == sizeof(*(b)) checks if *a and *b are also
+ * of the same size (so that, e.g. you don't accidentally copy an
+ * int plus the random bytes following it into an array of long). It
+ * evaluates to 1 if they are the same, and 0 otherwise.
+ *
+ * * sizeof(char[2 * (result of previous step) - 1]) evaluates to 1
+ * if the previous step was successful (char [(2*1) - 1] i.e.
+ * char[1]), or generates a compile error if it wasn't successful
+ * (char[2*0 -1] i.e. char[-1], which isn't valid in C).
+ *
+ * So VIR_TYPECHECK(a, b) will either abort the compile with an error,
+ * or evaluate to "1", and in the meantime check that we've actually
+ * added the correct &'s and/or *'s to the arguments. (Whew!)
+*/
+# define VIR_TYPEMATCH(a, b) \
+ sizeof(char[2 * (sizeof(*(a) = *(b)) == sizeof(*(b))) - 1])
+
+/**
+ * VIR_INSERT_ELEMENT:
+ * @ptr: pointer to array of objects (*not* ptr to ptr)
+ * @at: index within array where new elements should be added
+ * @count: variable tracking number of elements currently allocated
+ * @newelem: the new element to move into place (*not* a pointer to
+ * the element, but the element itself).
+ * (the original will be zeroed out if successful)
+ *
+ * Re-allocate an array of 'count' elements, each sizeof(*ptr) bytes
+ * long, to be 'count' + 1 elements long, then appropriately move
+ * the elements starting at ptr[at] up by 1 element, copy the
+ * item 'newelem' into ptr[at], then store the address of
+ * allocated memory in 'ptr' and the new size in 'count'.
+ *
+ * VIR_INSERT_ELEMENT_COPY is identical, but doesn't clear out the
+ * original element to 0 on success, so there are two copies of the
+ * element. This is useful if the "element" is actually just a
+ * pointer to the real data, and you want to maintain a reference to
+ * it for use after the insert is completed; but if the "element" is
+ * an object that points to other allocated memory, having multiple
+ * copies can cause problems (e.g. double free).
+ *
+ * VIR_INSERT_ELEMENT_*INPLACE are identical, but assume any necessary
+ * memory re-allocation has already been done.
+ *
+ * VIR_INSERT_ELEMENT_* all need to send "1" as the "add" argument to
+ * virInsertElementsN (which has the currently-unused capability of
+ * inserting multiple items at once). We use this to our advantage by
+ * replacing it with VIR_TYPECHECK(ptr, &newelem) so that we can be
+ * assured ptr and &newelem are of compatible types.
+ *
+ * Returns -1 on failure, 0 on success
+ *
+ *
+ */
+# define VIR_INSERT_ELEMENT(ptr, at, count, newelem) \
+ virInsertElementsN(&(ptr), sizeof(*(ptr)), at, &(count), \
+ VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), true, false)
+# define VIR_INSERT_ELEMENT_COPY(ptr, at, count, newelem) \
+ virInsertElementsN(&(ptr), sizeof(*(ptr)), at, &(count), \
+ VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), false, false)
+# define VIR_INSERT_ELEMENT_INPLACE(ptr, at, count, newelem) \
+ virInsertElementsN(&(ptr), sizeof(*(ptr)), at, &(count), \
+ VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), true, true)
+# define VIR_INSERT_ELEMENT_COPY_INPLACE(ptr, at, count, newelem) \
+ virInsertElementsN(&(ptr), sizeof(*(ptr)), at, &(count), \
+ VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), false, true)
+
+/**
+ * VIR_APPEND_ELEMENT:
+ * @ptr: pointer to array of objects (*not* ptr to ptr)
+ * @count: variable tracking number of elements currently allocated
+ * @newelem: the new element to move into place (*not* a pointer to
+ * the element, but the element itself).
+ * (the original will be zeroed out if successful)
+ *
+ * Re-allocate an array of 'count' elements, each sizeof(*ptr) bytes
+ * long, to be 'count' + 1 elements long, then copy the item from
+ * 'newelem' into ptr[count+1], and store the address of allocated
+ * memory in 'ptr' and the new size in 'count'. If 'newelem' is NULL,
+ * the new element at ptr[at] is instead filled with zero.
+ *
+ * VIR_APPEND_ELEMENT_COPY is identical, but doesn't clear out the
+ * original element to 0 on success, so there are two copies of the
+ * element. This is useful if the "element" is actually just a
+ * pointer to the real data, and you want to maintain a reference to
+ * it for use after the append is completed; but if the "element" is
+ * an object that points to other allocated memory, having multiple
+ * copies can cause problems (e.g. double free).
+ *
+ * VIR_APPEND_ELEMENT_*INPLACE are identical, but assume any
+ * necessary memory re-allocation has already been done.
+ *
+ * VIR_APPEND_ELEMENT_* all need to send "1" as the "add" argument to
+ * virInsertElementsN (which has the currently-unused capability of
+ * inserting multiple items at once). We use this to our advantage by
+ * replacing it with VIR_TYPECHECK(ptr, &newelem) so that we can be
+ * assured ptr and &newelem are of compatible types.
+ *
+ * Returns -1 on failure, 0 on success
+ *
+ *
+ */
+# define VIR_APPEND_ELEMENT(ptr, count, newelem) \
+ virInsertElementsN(&(ptr), sizeof(*(ptr)), count, &(count), \
+ VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), true, false)
+# define VIR_APPEND_ELEMENT_COPY(ptr, count, newelem) \
+ virInsertElementsN(&(ptr), sizeof(*(ptr)), count, &(count), \
+ VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), false, false)
+# define VIR_APPEND_ELEMENT_INPLACE(ptr, count, newelem) \
+ virInsertElementsN(&(ptr), sizeof(*(ptr)), count, &(count), \
+ VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), true, true)
+# define VIR_APPEND_ELEMENT_COPY_INPLACE(ptr, count, newelem) \
+ virInsertElementsN(&(ptr), sizeof(*(ptr)), count, &(count), \
+ VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), false, true)
+
+/**
+ * VIR_DELETE_ELEMENT:
+ * @ptr: pointer to array of objects (*not* ptr to ptr)
+ * @at: index within array where new elements should be deleted
+ * @count: variable tracking number of elements currently allocated
+ *
+ * Re-allocate an array of 'count' elements, each sizeof(*ptr)
+ * bytes long, to be 'count' - 1 elements long, then store the
+ * address of allocated memory in 'ptr' and the new size in 'count'.
+ * If 'count' <= 1, the entire array is freed.
+ *
+ * VIR_DELETE_ELEMENT_INPLACE is identical, but assumes any
+ * necessary memory re-allocation will be done later.
+ *
+ * Returns -1 on failure, 0 on success
+ */
+# define VIR_DELETE_ELEMENT(ptr, at, count) \
+ virDeleteElementsN(&(ptr), sizeof(*(ptr)), at, &(count), 1, false)
+# define VIR_DELETE_ELEMENT_INPLACE(ptr, at, count) \
+ virDeleteElementsN(&(ptr), sizeof(*(ptr)), at, &(count), 1, true)
+
+/*
+ * VIR_ALLOC_VAR_OVERSIZED:
+ * @M: size of base structure
+ * @N: number of array elements in trailing array
+ * @S: size of trailing array elements
+ *
+ * Check to make sure that the requested allocation will not cause
+ * arithmetic overflow in the allocation size. The check is
+ * essentially the same as that in gnulib's xalloc_oversized.
+ */
+# define VIR_ALLOC_VAR_OVERSIZED(M, N, S) ((((size_t)-1) - (M)) / (S) < (N))
+
+/**
+ * VIR_ALLOC_VAR:
+ * @ptr: pointer to hold address of allocated memory
+ * @type: element type of trailing array
+ * @count: number of array elements to allocate
+ *
+ * Allocate sizeof(*ptr) bytes plus an array of 'count' elements, each
+ * sizeof('type'). This sort of allocation is useful for receiving
+ * the data of certain ioctls and other APIs which return a struct in
+ * which the last element is an array of undefined length. The caller
+ * of this type of API is expected to know the length of the array
+ * that will be returned and allocate a suitable buffer to contain the
+ * returned data. C99 refers to these variable length objects as
+ * structs containing flexible array members.
+
+ * Returns -1 on failure, 0 on success
+ */
+# define VIR_ALLOC_VAR(ptr, type, count) \
+ virAllocVar(&(ptr), sizeof(*(ptr)), sizeof(type), (count))
+
+/**
+ * VIR_FREE:
+ * @ptr: pointer holding address to be freed
+ *
+ * Free the memory stored in 'ptr' and update to point
+ * to NULL.
+ */
+/* The ternary ensures that ptr is a pointer and not an integer type,
+ * while evaluating ptr only once. For now, we intentionally cast
+ * away const, since a number of callers safely pass const char *.
+ */
+# define VIR_FREE(ptr) virFree((void *) (1 ? (const void *) &(ptr) : (ptr)))
+
+
+# if TEST_OOM
+void virAllocTestInit(void);
+int virAllocTestCount(void);
+void virAllocTestOOM(int n, int m);
+void virAllocTestHook(void (*func)(int, void*), void *data);
+# endif
+
+
+
+#endif /* __VIR_MEMORY_H_ */
#include "viraudit.h"
#include "util.h"
#include "virfile.h"
-#include "memory.h"
+#include "viralloc.h"
/* Provide the macros in case the header file is old.
FIXME: should be removed. */
#include "virauth.h"
#include "util.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "datatypes.h"
#include "virterror_internal.h"
#include "virauthconfig.h"
#include "virkeyfile.h"
-#include "memory.h"
+#include "viralloc.h"
#include "util.h"
#include "virlog.h"
#include "virterror_internal.h"
#include <sys/types.h>
#include "virbitmap.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virbuffer.h"
#include "util.h"
#include "c-ctype.h"
#define __VIR_BUFFER_C__
#include "virbuffer.h"
-#include "memory.h"
+#include "viralloc.h"
/* If adding more fields, ensure to edit buf.h to match
#include "internal.h"
#include "util.h"
-#include "memory.h"
+#include "viralloc.h"
#include "vircgroup.h"
#include "virlog.h"
#include "virfile.h"
#endif
#include "vircommand.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virterror_internal.h"
#include "util.h"
#include "virlog.h"
#include "util.h"
#include "c-ctype.h"
#include "virlog.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virfile.h"
#define VIR_FROM_THIS VIR_FROM_CONF
#include <config.h>
#include "virdbus.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virterror_internal.h"
#include "virlog.h"
#include "threads.h"
#include "virdnsmasq.h"
#include "util.h"
#include "vircommand.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virterror_internal.h"
#include "virlog.h"
#include "virfile.h"
#include "internal.h"
#include "virebtables.h"
#include "vircommand.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virterror_internal.h"
#include "virlog.h"
#include "threads.h"
#include "threads.h"
#include "virlog.h"
#include "vireventpoll.h"
-#include "memory.h"
+#include "viralloc.h"
#include "util.h"
#include "virfile.h"
#include "virterror_internal.h"
#include "vircommand.h"
#include "configmake.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virterror_internal.h"
#include "virlog.h"
#include "virterror_internal.h"
#include "virhash.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "virhashcode.h"
#include "virrandom.h"
#include "virhook.h"
#include "util.h"
#include "virlog.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virfile.h"
#include "configmake.h"
#include "vircommand.h"
#include "virinitctl.h"
#include "virterror_internal.h"
#include "util.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virfile.h"
#define VIR_FROM_THIS VIR_FROM_INITCTL
#include "internal.h"
#include "viriptables.h"
#include "vircommand.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virterror_internal.h"
#include "virlog.h"
#include "threads.h"
#include <config.h>
#include "virjson.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virterror_internal.h"
#include "virlog.h"
#include "util.h"
#include "c-ctype.h"
#include "virlog.h"
-#include "memory.h"
+#include "viralloc.h"
#include "util.h"
#include "virhash.h"
#include "virkeyfile.h"
#include "virlockspace.h"
#include "virlog.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virterror_internal.h"
#include "util.h"
#include "virfile.h"
#include "virterror_internal.h"
#include "virlog.h"
-#include "memory.h"
+#include "viralloc.h"
#include "util.h"
#include "virbuffer.h"
#include "threads.h"
#include "virfile.h"
#include "virterror_internal.h"
#include "vircommand.h"
-#include "memory.h"
+#include "viralloc.h"
#include "pci.h"
#include "virlog.h"
#include "virnetdevbandwidth.h"
#include "vircommand.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virterror_internal.h"
#define VIR_FROM_THIS VIR_FROM_NONE
#include "virterror_internal.h"
#include "util.h"
#include "virfile.h"
-#include "memory.h"
+#include "viralloc.h"
#include "intprops.h"
#include <sys/ioctl.h>
# define MACVLAN_MODE_PASSTHRU 8
# endif
-# include "memory.h"
+# include "viralloc.h"
# include "virlog.h"
# include "uuid.h"
# include "virfile.h"
#include "virnetdevopenvswitch.h"
#include "vircommand.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virterror_internal.h"
#include "virmacaddr.h"
#include "virterror_internal.h"
#include "virfile.h"
#include "virterror_internal.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "util.h"
#include <sys/wait.h>
#include "virnetdevveth.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "vircommand.h"
#include "virterror_internal.h"
#include "internal.h"
#include "virterror_internal.h"
#include "virnetdevvlan.h"
-#include "memory.h"
+#include "viralloc.h"
#define VIR_FROM_THIS VIR_FROM_NONE
#include "virnetdevvportprofile.h"
#include "virterror_internal.h"
-#include "memory.h"
+#include "viralloc.h"
#define VIR_FROM_THIS VIR_FROM_NET
#include "virnetlink.h"
#include "virlog.h"
-#include "memory.h"
+#include "viralloc.h"
#include "threads.h"
#include "virmacaddr.h"
#include "virterror_internal.h"
#include "threads.h"
#include "datatypes.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "virterror_internal.h"
#include "virobject.h"
#include "threads.h"
-#include "memory.h"
+#include "viralloc.h"
#include "viratomic.h"
#include "virterror_internal.h"
#include "virlog.h"
#include "virpidfile.h"
#include "virfile.h"
-#include "memory.h"
+#include "viralloc.h"
#include "util.h"
#include "intprops.h"
#include "virlog.h"
#include "virprocess.h"
#include "virterror_internal.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "util.h"
#include <config.h>
#include "virstring.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virbuffer.h"
#include "virterror_internal.h"
#include "virterror_internal.h"
#include "datatypes.h"
#include "virlog.h"
-#include "memory.h"
+#include "viralloc.h"
#include "threads.h"
#include "util.h"
#include "virtime.h"
#include "util.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virterror_internal.h"
#define VIR_FROM_THIS VIR_FROM_NONE
#include <stdarg.h>
-#include "memory.h"
+#include "viralloc.h"
#include "util.h"
#include "virterror_internal.h"
#include "viruri.h"
-#include "memory.h"
+#include "viralloc.h"
#include "util.h"
#include "virterror_internal.h"
#include "virbuffer.h"
#include "virusb.h"
#include "virlog.h"
-#include "memory.h"
+#include "viralloc.h"
#include "util.h"
#include "virterror_internal.h"
#include "xml.h"
#include "virbuffer.h"
#include "util.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virfile.h"
#define VIR_FROM_THIS VIR_FROM_XML
#define nsCID CLSID
#include "internal.h"
-#include "memory.h"
+#include "viralloc.h"
#include "util.h"
#include "virlog.h"
#include "virterror_internal.h"
#include "vbox_XPCOMCGlue.h"
#include "internal.h"
-#include "memory.h"
+#include "viralloc.h"
#include "util.h"
#include "virlog.h"
#include "virterror_internal.h"
#include "storage_conf.h"
#include "storage_file.h"
#include "uuid.h"
-#include "memory.h"
+#include "viralloc.h"
#include "nodeinfo.h"
#include "virlog.h"
#include "vbox_driver.h"
#include "vircommand.h"
#include "cpu/cpu.h"
#include "dirname.h"
-#include "memory.h"
+#include "viralloc.h"
#include "nodeinfo.h"
#include "virfile.h"
#include "uuid.h"
#include "virterror_internal.h"
#include "datatypes.h"
#include "virfile.h"
-#include "memory.h"
+#include "viralloc.h"
#include "util.h"
#include "uuid.h"
#include "vircommand.h"
#include "internal.h"
#include "virterror_internal.h"
#include "virconf.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "uuid.h"
#include "vmx.h"
# include "datatypes.h"
# include "util.h"
# include "block_stats.h"
-# include "memory.h"
+# include "viralloc.h"
# include "virfile.h"
# define VIR_FROM_THIS VIR_FROM_STATS_LINUX
#endif
#include "xml.h"
#include "util.h"
-#include "memory.h"
+#include "viralloc.h"
#include "node_device_conf.h"
#include "pci.h"
#include "uuid.h"
#include "xend_internal.h"
#include "virbuffer.h"
#include "capabilities.h"
-#include "memory.h"
+#include "viralloc.h"
#include "threads.h"
#include "virfile.h"
#include "virnodesuspend.h"
#include "virterror_internal.h"
#include "datatypes.h"
#include "driver.h"
-#include "memory.h"
+#include "viralloc.h"
#include "xen_driver.h"
#include "virconf.h"
#include "domain_conf.h"
#include "xen_driver.h"
#include "xen_hypervisor.h"
#include "xs_internal.h" /* To extract VNC port & Serial console TTY */
-#include "memory.h"
+#include "viralloc.h"
#include "count-one-bits.h"
#include "virfile.h"
#include "viruri.h"
#include "virbuffer.h"
#include "uuid.h"
#include "util.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "count-one-bits.h"
#include "virterror_internal.h"
#include "datatypes.h"
#include "driver.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "uuid.h"
#include "xen_driver.h"
#include "virauth.h"
#include "util.h"
#include "uuid.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virbuffer.h"
#include "viruri.h"
#include "xenapi_driver.h"
#include "datatypes.h"
#include "util.h"
#include "uuid.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virbuffer.h"
#include "virlog.h"
#include "viruri.h"
#include "internal.h"
#include "virterror_internal.h"
#include "virconf.h"
-#include "memory.h"
+#include "viralloc.h"
#include "verify.h"
#include "uuid.h"
#include "virlog.h"
#include "internal.h"
#include "virterror_internal.h"
#include "virconf.h"
-#include "memory.h"
+#include "viralloc.h"
#include "verify.h"
#include "uuid.h"
#include "sexpr.h"
#include "internal.h"
#include "util.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virfile.h"
#include "testutils.h"
#include "internal.h"
#include "nodeinfo.h"
#include "util.h"
-#include "memory.h"
+#include "viralloc.h"
#include "vircommand.h"
#include "virfile.h"
#include "virpidfile.h"
#include <string.h>
#include <errno.h>
#include "virconf.h"
-#include "memory.h"
+#include "viralloc.h"
int main(int argc, char **argv)
{
#include "internal.h"
#include "xml.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virbuffer.h"
#include "testutils.h"
#include "cpu_conf.h"
# include <unistd.h>
# include "internal.h"
-# include "memory.h"
+# include "viralloc.h"
# include "testutils.h"
# include "util.h"
# include "vmx/vmx.h"
#include "testutils.h"
#include "network_conf.h"
#include "vircommand.h"
-#include "memory.h"
+#include "viralloc.h"
#include "network/bridge_driver.h"
static int
# include <unistd.h>
# include "internal.h"
-# include "memory.h"
+# include "viralloc.h"
# include "testutils.h"
# include "util.h"
# include "openvz/openvz_conf.h"
# include "testutils.h"
# include "qemu/qemu_capabilities.h"
-# include "memory.h"
+# include "viralloc.h"
struct testInfo {
const char *name;
#ifdef WITH_QEMU
# include "internal.h"
-# include "memory.h"
+# include "viralloc.h"
# include "testutils.h"
# include "util.h"
# include "qemu/qemu_monitor.h"
#include "threads.h"
#include "qemu/qemu_monitor.h"
#include "rpc/virnetsocket.h"
-#include "memory.h"
+#include "viralloc.h"
#include "util.h"
#include "virlog.h"
#include "virterror_internal.h"
# include "internal.h"
# include "testutils.h"
-# include "util/memory.h"
+# include "viralloc.h"
# include "qemu/qemu_capabilities.h"
# include "qemu/qemu_command.h"
# include "qemu/qemu_domain.h"
#include "internal.h"
#include "testutils.h"
-#include "memory.h"
+#include "viralloc.h"
#include "util.h"
#include "virlog.h"
#include "virterror_internal.h"
#include "virsocketaddr.h"
#include "testutils.h"
#include "virlog.h"
-#include "memory.h"
+#include "viralloc.h"
static void testQuietError(void *userData ATTRIBUTE_UNUSED,
virErrorPtr error ATTRIBUTE_UNUSED)
#include <limits.h>
#include "testutils.h"
#include "internal.h"
-#include "memory.h"
+#include "viralloc.h"
#include "util.h"
#include "threads.h"
#include "virterror_internal.h"
# define __VIT_TEST_UTILS_H__
# include <stdio.h>
-# include "memory.h"
+# include "viralloc.h"
# define EXIT_AM_SKIP 77 /* tell Automake we're skipping a test */
# define EXIT_AM_HARDFAIL 99 /* tell Automake that the framework is broken */
# include "testutilslxc.h"
# include "testutils.h"
-# include "memory.h"
+# include "viralloc.h"
# include "domain_conf.h"
# include "testutilsqemu.h"
# include "testutils.h"
-# include "memory.h"
+# include "viralloc.h"
# include "cpu_conf.h"
# include "qemu/qemu_driver.h"
# include "qemu/qemu_domain.h"
#include <unistd.h>
#include "internal.h"
-#include "memory.h"
+#include "viralloc.h"
#include "testutils.h"
#include "util.h"
#include "testutils.h"
#include "util.h"
#include "virterror_internal.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "virauthconfig.h"
#include "util.h"
#include "testutils.h"
#include "virbuffer.h"
-#include "memory.h"
+#include "viralloc.h"
#define TEST_ERROR(...) \
do { \
#include "testutils.h"
#include "util.h"
#include "virterror_internal.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "driver.h"
#include "virhash.h"
#include "virhashdata.h"
#include "testutils.h"
-#include "memory.h"
+#include "viralloc.h"
#include "util.h"
#include "virlog.h"
#include "testutils.h"
#include "util.h"
#include "virterror_internal.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "virkeyfile.h"
#include "testutils.h"
#include "util.h"
#include "virterror_internal.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "virlockspace.h"
#include "testutils.h"
#include "util.h"
#include "virterror_internal.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "rpc/virnetmessage.h"
#include "testutils.h"
#include "util.h"
#include "virterror_internal.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "virfile.h"
#include "testutils.h"
#include "util.h"
#include "virterror_internal.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "virfile.h"
#include "vircommand.h"
#include "testutils.h"
#include "util.h"
#include "virterror_internal.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "virstring.h"
#include "testutils.h"
#include "util.h"
#include "virterror_internal.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "virtime.h"
#include "testutils.h"
#include "util.h"
#include "virterror_internal.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virlog.h"
#include "viruri.h"
# include <unistd.h>
# include "internal.h"
-# include "memory.h"
+# include "viralloc.h"
# include "testutils.h"
# include "vmx/vmx.h"
#include "xenxs/xen_xm.h"
#include "testutils.h"
#include "testutilsxen.h"
-#include "memory.h"
+#include "viralloc.h"
static virCapsPtr caps;
# include <unistd.h>
# include "internal.h"
-# include "memory.h"
+# include "viralloc.h"
# include "testutils.h"
# include "vmx/vmx.h"
# include "virlog.h"
# include "util.h"
# include "virfile.h"
-# include "memory.h"
+# include "viralloc.h"
# include "threads.h"
# include "virterror_internal.h"
#include "internal.h"
#include "conf/domain_conf.h"
#include "intprops.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virmacaddr.h"
#include "virsh-domain.h"
#include "xml.h"
#include "c-ctype.h"
#include "conf/domain_conf.h"
#include "console.h"
-#include "memory.h"
+#include "viralloc.h"
#include "util.h"
#include "virfile.h"
#include "virkeycode.h"
#include "internal.h"
#include "virbuffer.h"
-#include "memory.h"
+#include "viralloc.h"
#include "util.h"
#include "virsh-domain.h"
#include "xml.h"
#include "internal.h"
#include "virbuffer.h"
-#include "memory.h"
+#include "viralloc.h"
#include "util.h"
#include "xml.h"
#include "internal.h"
#include "virbuffer.h"
-#include "memory.h"
+#include "viralloc.h"
#include "util.h"
#include "xml.h"
#include "conf/network_conf.h"
#include "internal.h"
#include "virbuffer.h"
-#include "memory.h"
+#include "viralloc.h"
#include "util.h"
#include "xml.h"
#include "conf/node_device_conf.h"
#include "internal.h"
#include "virbuffer.h"
-#include "memory.h"
+#include "viralloc.h"
#include "util.h"
#include "xml.h"
#include "internal.h"
#include "virbuffer.h"
-#include "memory.h"
+#include "viralloc.h"
#include "util.h"
#include "xml.h"
#include "conf/storage_conf.h"
#include "internal.h"
#include "base64.h"
#include "virbuffer.h"
-#include "memory.h"
+#include "viralloc.h"
#include "util.h"
#include "xml.h"
#include "internal.h"
#include "virbuffer.h"
-#include "memory.h"
+#include "viralloc.h"
#include "util.h"
#include "virsh-domain.h"
#include "xml.h"
#include "internal.h"
#include "virbuffer.h"
-#include "memory.h"
+#include "viralloc.h"
#include "util.h"
#include "virfile.h"
#include "virsh-pool.h"
#include "virbuffer.h"
#include "console.h"
#include "util.h"
-#include "memory.h"
+#include "viralloc.h"
#include "xml.h"
#include "libvirt/libvirt-qemu.h"
#include "virfile.h"
#include <sys/utsname.h>
#include "util.h"
-#include "memory.h"
+#include "viralloc.h"
#include "virfile.h"
#include "virt-host-validate-common.h"