[libvirt] [PATCH 0/5] switch python bindings to use libvirt_util

As threatened here: https://www.redhat.com/archives/libvir-list/2012-February/msg00122.html and as requested here: https://www.redhat.com/archives/libvir-list/2012-January/msg00491.html along with some prerequisite patches. I was quite shocked when I discovered that we didn't have a syntax-check rule requiring the use of VIR_FREE, before these patches. Eric Blake (5): build: clean up CPPFLAGS/INCLUDES usage python: drop redundant function build: prohibit raw malloc and free build: expand rule to cover testsuite python: use libvirt_util to avoid raw free cfg.mk | 9 + daemon/Makefile.am | 20 +- examples/dominfo/Makefile.am | 4 +- examples/domsuspend/Makefile.am | 4 +- examples/hellolibvirt/Makefile.am | 4 +- examples/openauth/Makefile.am | 4 +- python/Makefile.am | 22 ++- python/generator.py | 4 +- python/libvirt-override.c | 364 ++++++++++++++++++------------------- python/typewrappers.c | 21 +-- python/typewrappers.h | 3 +- src/Makefile.am | 70 ++++---- src/conf/network_conf.c | 2 +- src/cpu/cpu.c | 4 +- src/libxl/libxl_conf.c | 13 +- src/rpc/virnetmessage.c | 23 ++- tests/Makefile.am | 9 +- tests/commandhelper.c | 6 +- tests/cputest.c | 36 ++-- tests/domainsnapshotxml2xmltest.c | 6 +- tests/interfacexml2xmltest.c | 6 +- tests/networkxml2argvtest.c | 10 +- tests/networkxml2xmltest.c | 10 +- tests/nodedevxml2xmltest.c | 6 +- tests/nodeinfotest.c | 10 +- tests/nwfilterxml2xmltest.c | 10 +- tests/qemuargv2xmltest.c | 20 +- tests/qemuxml2argvtest.c | 28 ++-- tests/qemuxml2xmltest.c | 10 +- tests/qemuxmlnstest.c | 23 ++- tests/qparamtest.c | 2 +- tests/sexpr2xmltest.c | 10 +- tests/storagepoolxml2xmltest.c | 10 +- tests/storagevolxml2xmltest.c | 14 +- tests/testutils.c | 9 +- tests/testutils.h | 3 +- tests/virshtest.c | 4 +- tests/xencapstest.c | 10 +- tests/xmconfigtest.c | 10 +- tests/xml2sexprtest.c | 10 +- tools/Makefile.am | 12 +- tools/virsh.c | 9 +- 42 files changed, 429 insertions(+), 435 deletions(-) -- 1.7.7.6

Our syntax checker missed all-lower-case variables (this will be fixed by the next .gnulib update). Additionally, anywhere that we mix in-tree files with generated files, automake recommends listing builddir prior to srcdir for VPATH builds. * src/Makefile.am (*_la_CFLAGS): Favor $(top_srcdir). (INCLUDES): Likewise, and follow automake recommendations on builddir before srcdir. * python/Makefile.am (INCLUDES): Swap directory order. * tests/Makefile.am (INCLUDES): Likewise. * tools/Makefile.am (INCLUDES): Likewise. * daemon/Makefile.am (INCLUDES): Likewise. (libvirtd.init, libvirtd.service): Favor $(). * examples/hellolibvirt/Makefile.am (hellolibvirt_LDADD): Likewise. * examples/openauth/Makefile.am (openauth_LDADD): Likewise. * examples/dominfo/Makefile.am (INCLUDES): Drop dead include. * examples/domsuspend/Makefile.am (INCLUDES): Likewise. --- daemon/Makefile.am | 20 +++++----- examples/dominfo/Makefile.am | 4 +- examples/domsuspend/Makefile.am | 4 +- examples/hellolibvirt/Makefile.am | 4 +- examples/openauth/Makefile.am | 4 +- python/Makefile.am | 4 +- src/Makefile.am | 70 ++++++++++++++++++------------------ tests/Makefile.am | 9 ++--- tools/Makefile.am | 12 +++--- 9 files changed, 65 insertions(+), 66 deletions(-) diff --git a/daemon/Makefile.am b/daemon/Makefile.am index 73a6e1f..e2c1357 100644 --- a/daemon/Makefile.am +++ b/daemon/Makefile.am @@ -1,12 +1,12 @@ ## Process this file with automake to produce Makefile.in -## Copyright (C) 2005-2011 Red Hat, Inc. +## Copyright (C) 2005-2012 Red Hat, Inc. ## See COPYING.LIB for the License of this software INCLUDES = \ - -I$(top_srcdir)/gnulib/lib -I../gnulib/lib \ - -I$(top_srcdir)/include -I$(top_builddir)/include \ - -I$(top_srcdir)/src -I../src \ + -I$(top_builddir)/gnulib/lib -I$(top_srcdir)/gnulib/lib \ + -I$(top_builddir)/include -I$(top_srcdir)/include \ + -I$(top_builddir)/src -I$(top_srcdir)/src \ -I$(top_srcdir)/src/util \ -I$(top_srcdir)/src/conf \ -I$(top_srcdir)/src/rpc \ @@ -320,18 +320,18 @@ endif # LIBVIRT_INIT_SCRIPT_SYSTEMD libvirtd.init: libvirtd.init.in $(top_builddir)/config.status $(AM_V_GEN)sed \ - -e s!\@localstatedir\@!@localstatedir@!g \ - -e s!\@sbindir\@!@sbindir@!g \ - -e s!\@sysconfdir\@!@sysconfdir@!g \ + -e s!\@localstatedir\@!$(localstatedir)!g \ + -e s!\@sbindir\@!$(sbindir)!g \ + -e s!\@sysconfdir\@!$(sysconfdir)!g \ < $< > $@-t && \ chmod a+x $@-t && \ mv $@-t $@ libvirtd.service: libvirtd.service.in $(top_builddir)/config.status $(AM_V_GEN)sed \ - -e s!\@localstatedir\@!@localstatedir@!g \ - -e s!\@sbindir\@!@sbindir@!g \ - -e s!\@sysconfdir\@!@sysconfdir@!g \ + -e s!\@localstatedir\@!$(localstatedir)!g \ + -e s!\@sbindir\@!$(sbindir)!g \ + -e s!\@sysconfdir\@!$(sysconfdir)!g \ < $< > $@-t && \ chmod a+x $@-t && \ mv $@-t $@ diff --git a/examples/dominfo/Makefile.am b/examples/dominfo/Makefile.am index 07982b0..188c53a 100644 --- a/examples/dominfo/Makefile.am +++ b/examples/dominfo/Makefile.am @@ -1,7 +1,7 @@ -## Copyright (C) 2005-2011 Red Hat, Inc. +## Copyright (C) 2005-2012 Red Hat, Inc. ## See COPYING.LIB for the License of this software -INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include -I@srcdir@/include +INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include LDADDS = $(STATIC_BINARIES) $(WARN_CFLAGS) $(top_builddir)/src/libvirt.la \ $(COVERAGE_LDFLAGS) diff --git a/examples/domsuspend/Makefile.am b/examples/domsuspend/Makefile.am index fc5e931..dbb38c5 100644 --- a/examples/domsuspend/Makefile.am +++ b/examples/domsuspend/Makefile.am @@ -1,7 +1,7 @@ -## Copyright (C) 2005-2011 Red Hat, Inc. +## Copyright (C) 2005-2012 Red Hat, Inc. ## See COPYING.LIB for the License of this software -INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include -I@srcdir@/include +INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include LDADDS = $(STATIC_BINARIES) $(WARN_CFLAGS) $(top_builddir)/src/libvirt.la \ $(COVERAGE_LDFLAGS) diff --git a/examples/hellolibvirt/Makefile.am b/examples/hellolibvirt/Makefile.am index a55fe19..e92fa9d 100644 --- a/examples/hellolibvirt/Makefile.am +++ b/examples/hellolibvirt/Makefile.am @@ -1,8 +1,8 @@ -## Copyright (C) 2005-2011 Red Hat, Inc. +## Copyright (C) 2005-2012 Red Hat, Inc. ## See COPYING.LIB for the License of this software INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include noinst_PROGRAMS = hellolibvirt hellolibvirt_CFLAGS = $(WARN_CFLAGS) hellolibvirt_SOURCES = hellolibvirt.c -hellolibvirt_LDADD = @top_builddir@/src/libvirt.la +hellolibvirt_LDADD = $(top_builddir)/src/libvirt.la diff --git a/examples/openauth/Makefile.am b/examples/openauth/Makefile.am index 844b572..b396150 100644 --- a/examples/openauth/Makefile.am +++ b/examples/openauth/Makefile.am @@ -1,8 +1,8 @@ -## Copyright (C) 2005-2011 Red Hat, Inc. +## Copyright (C) 2005-2012 Red Hat, Inc. ## See COPYING.LIB for the License of this software INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include noinst_PROGRAMS = openauth openauth_CFLAGS = $(WARN_CFLAGS) openauth_SOURCES = openauth.c -openauth_LDADD = @top_builddir@/src/libvirt.la +openauth_LDADD = $(top_builddir)/src/libvirt.la diff --git a/python/Makefile.am b/python/Makefile.am index 3068eee..81b160a 100644 --- a/python/Makefile.am +++ b/python/Makefile.am @@ -1,14 +1,14 @@ # Makefile for libvirt python library -## Copyright (C) 2005-2011 Red Hat, Inc. +## Copyright (C) 2005-2012 Red Hat, Inc. ## See COPYING.LIB for the License of this software SUBDIRS= . tests INCLUDES = \ $(PYTHON_INCLUDES) \ - -I$(top_srcdir)/include \ -I$(top_builddir)/include \ + -I$(top_srcdir)/include \ -I$(top_builddir)/$(subdir) \ $(GETTEXT_CPPFLAGS) diff --git a/src/Makefile.am b/src/Makefile.am index b25a439..6436c2c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -6,11 +6,11 @@ # No libraries with the exception of LIBXML should be listed # here. List them against the individual XXX_la_CFLAGS targets # that actually use them. Also keep GETTEXT_CPPFLAGS at the end. -INCLUDES = -I$(top_srcdir)/gnulib/lib \ - -I../gnulib/lib \ +INCLUDES = -I../gnulib/lib \ + -I$(top_srcdir)/gnulib/lib \ -I../include \ - -I@top_srcdir@/src/util \ - -I@top_srcdir@/include \ + -I$(top_srcdir)/include \ + -I$(top_srcdir)/src/util \ -DIN_LIBVIRT \ $(GETTEXT_CPPFLAGS) @@ -582,14 +582,14 @@ libvirt_conf_la_LDFLAGS = $(AM_LDFLAGS) noinst_LTLIBRARIES += libvirt_cpu.la libvirt_la_BUILT_LIBADD += libvirt_cpu.la libvirt_cpu_la_CFLAGS = \ - -I@top_srcdir@/src/conf $(AM_CFLAGS) + -I$(top_srcdir)/src/conf $(AM_CFLAGS) libvirt_cpu_la_SOURCES = $(CPU_SOURCES) if WITH_VMX noinst_LTLIBRARIES += libvirt_vmx.la libvirt_la_BUILT_LIBADD += libvirt_vmx.la libvirt_vmx_la_CFLAGS = \ - -I@top_srcdir@/src/conf $(AM_CFLAGS) + -I$(top_srcdir)/src/conf $(AM_CFLAGS) libvirt_vmx_la_SOURCES = $(VMX_SOURCES) endif @@ -597,7 +597,7 @@ if WITH_XENXS noinst_LTLIBRARIES += libvirt_xenxs.la libvirt_la_BUILT_LIBADD += libvirt_xenxs.la libvirt_xenxs_la_CFLAGS = \ - -I@top_srcdir@/src/conf $(AM_CFLAGS) + -I$(top_srcdir)/src/conf $(AM_CFLAGS) libvirt_xenxs_la_SOURCES = $(XENXS_SOURCES) endif @@ -607,7 +607,7 @@ libvirt_la_BUILT_LIBADD += libvirt_driver.la libvirt_driver_la_SOURCES = $(DRIVER_SOURCES) libvirt_driver_la_CFLAGS = $(NUMACTL_CFLAGS) $(GNUTLS_CFLAGS) \ - -I@top_srcdir@/src/conf $(AM_CFLAGS) + -I$(top_srcdir)/src/conf $(AM_CFLAGS) libvirt_driver_la_LIBADD = $(NUMACTL_LIBS) $(GNUTLS_LIBS) $(DLOPEN_LIBS) USED_SYM_FILES = libvirt_private.syms @@ -620,7 +620,7 @@ noinst_LTLIBRARIES += libvirt_driver_test.la libvirt_la_BUILT_LIBADD += libvirt_driver_test.la endif libvirt_driver_test_la_CFLAGS = \ - -I@top_srcdir@/src/conf $(AM_CFLAGS) + -I$(top_srcdir)/src/conf $(AM_CFLAGS) if WITH_DRIVER_MODULES libvirt_driver_test_la_LDFLAGS = -module -avoid-version $(AM_LDFLAGS) endif @@ -637,8 +637,8 @@ endif libvirt_driver_remote_la_CFLAGS = \ $(GNUTLS_CFLAGS) \ $(XDR_CFLAGS) \ - -I@top_srcdir@/src/conf \ - -I@top_srcdir@/src/rpc \ + -I$(top_srcdir)/src/conf \ + -I$(top_srcdir)/src/rpc \ $(AM_CFLAGS) libvirt_driver_remote_la_LDFLAGS = $(AM_LDFLAGS) libvirt_driver_remote_la_LIBADD = $(GNUTLS_LIBS) \ @@ -672,8 +672,8 @@ libvirt_la_BUILT_LIBADD += libvirt_driver_xen.la endif libvirt_driver_xen_la_CFLAGS = \ $(XEN_CFLAGS) \ - -I@top_srcdir@/src/conf \ - -I@top_srcdir@/src/xenxs \ + -I$(top_srcdir)/src/conf \ + -I$(top_srcdir)/src/xenxs \ $(AM_CFLAGS) libvirt_driver_xen_la_LDFLAGS = $(AM_LDFLAGS) libvirt_driver_xen_la_LIBADD = $(XEN_LIBS) @@ -697,7 +697,7 @@ libvirt_driver_phyp_la_LIBADD += ../gnulib/lib/libgnu.la libvirt_driver_phyp_la_LDFLAGS = -module -avoid-version $(AM_LDFLAGS) endif libvirt_driver_phyp_la_CFLAGS = $(LIBSSH2_CFLAGS) \ - -I@top_srcdir@/src/conf $(AM_CFLAGS) + -I$(top_srcdir)/src/conf $(AM_CFLAGS) libvirt_driver_phyp_la_SOURCES = $(PHYP_DRIVER_SOURCES) endif @@ -709,7 +709,7 @@ noinst_LTLIBRARIES += libvirt_driver_openvz.la libvirt_la_BUILT_LIBADD += libvirt_driver_openvz.la endif libvirt_driver_openvz_la_CFLAGS = \ - -I@top_srcdir@/src/conf $(AM_CFLAGS) + -I$(top_srcdir)/src/conf $(AM_CFLAGS) if WITH_DRIVER_MODULES libvirt_driver_openvz_la_LIBADD = ../gnulib/lib/libgnu.la libvirt_driver_openvz_la_LDFLAGS = -module -avoid-version $(AM_LDFLAGS) @@ -725,7 +725,7 @@ noinst_LTLIBRARIES += libvirt_driver_vmware.la libvirt_la_BUILT_LIBADD += libvirt_driver_vmware.la endif libvirt_driver_vmware_la_CFLAGS = \ - -I@top_srcdir@/src/conf -I@top_srcdir@/src/vmx $(AM_CFLAGS) + -I$(top_srcdir)/src/conf -I$(top_srcdir)/src/vmx $(AM_CFLAGS) if WITH_DRIVER_MODULES libvirt_driver_vmware_la_LIBADD = ../gnulib/lib/libgnu.la libvirt_driver_vmware_la_LDFLAGS = -module -avoid-version @@ -741,7 +741,7 @@ noinst_LTLIBRARIES += libvirt_driver_vbox.la libvirt_la_BUILT_LIBADD += libvirt_driver_vbox.la endif libvirt_driver_vbox_la_CFLAGS = \ - -I@top_srcdir@/src/conf $(AM_CFLAGS) + -I$(top_srcdir)/src/conf $(AM_CFLAGS) libvirt_driver_vbox_la_LIBADD = $(DLOPEN_LIBS) $(MSCOM_LIBS) if WITH_DRIVER_MODULES libvirt_driver_vbox_la_LIBADD += ../gnulib/lib/libgnu.la @@ -758,7 +758,7 @@ noinst_LTLIBRARIES += libvirt_driver_xenapi.la libvirt_la_BUILT_LIBADD += libvirt_driver_xenapi.la endif libvirt_driver_xenapi_la_CFLAGS = $(LIBXENSERVER_CFLAGS) $(LIBCURL_CFLAGS) \ - -I@top_srcdir@/src/conf $(AM_CFLAGS) + -I$(top_srcdir)/src/conf $(AM_CFLAGS) libvirt_driver_xenapi_la_LDFLAGS = $(AM_LDFLAGS) libvirt_driver_xenapi_la_LIBADD = $(LIBXENSERVER_LIBS) $(LIBCURL_LIBS) if WITH_DRIVER_MODULES @@ -777,8 +777,8 @@ noinst_LTLIBRARIES += libvirt_driver_libxl.la #libvirt_la_BUILT_LIBADD += libvirt_driver_libxl.la endif libvirt_driver_libxl_la_CFLAGS = $(LIBXL_CFLAGS) \ - -I@top_srcdir@/src/conf \ - -I@top_srcdir@/src/xenxs \ + -I$(top_srcdir)/src/conf \ + -I$(top_srcdir)/src/xenxs \ $(AM_CFLAGS) libvirt_driver_libxl_la_LDFLAGS = $(AM_LDFLAGS) libvirt_driver_libxl_la_LIBADD = $(LIBXL_LIBS) libvirt_xenxs.la @@ -800,7 +800,7 @@ endif libvirt_driver_qemu_la_CFLAGS = $(NUMACTL_CFLAGS) \ $(GNUTLS_CFLAGS) \ $(LIBXML_CFLAGS) \ - -I@top_srcdir@/src/conf $(AM_CFLAGS) + -I$(top_srcdir)/src/conf $(AM_CFLAGS) libvirt_driver_qemu_la_LDFLAGS = $(AM_LDFLAGS) libvirt_driver_qemu_la_LIBADD = $(NUMACTL_LIBS) \ $(CAPNG_LIBS) \ @@ -831,7 +831,7 @@ noinst_LTLIBRARIES += libvirt_driver_lxc.la #libvirt_la_BUILT_LIBADD += libvirt_driver_lxc.la endif libvirt_driver_lxc_la_CFLAGS = \ - -I@top_srcdir@/src/conf $(AM_CFLAGS) + -I$(top_srcdir)/src/conf $(AM_CFLAGS) libvirt_driver_lxc_la_LIBADD = $(CAPNG_LIBS) if WITH_SECDRIVER_SELINUX libvirt_driver_lxc_la_LIBADD += $(SELINUX_LIBS) @@ -862,7 +862,7 @@ noinst_LTLIBRARIES += libvirt_driver_uml.la #libvirt_la_BUILT_LIBADD += libvirt_driver_uml.la endif libvirt_driver_uml_la_CFLAGS = $(NUMACTL_CFLAGS) \ - -I@top_srcdir@/src/conf $(AM_CFLAGS) + -I$(top_srcdir)/src/conf $(AM_CFLAGS) libvirt_driver_uml_la_LDFLAGS = $(AM_LDFLAGS) libvirt_driver_uml_la_LIBADD = $(NUMACTL_LIBS) if WITH_DRIVER_MODULES @@ -887,7 +887,7 @@ noinst_LTLIBRARIES += libvirt_driver_esx.la libvirt_la_BUILT_LIBADD += libvirt_driver_esx.la endif libvirt_driver_esx_la_CFLAGS = $(LIBCURL_CFLAGS) \ - -I@top_srcdir@/src/conf -I@top_srcdir@/src/vmx $(AM_CFLAGS) + -I$(top_srcdir)/src/conf -I$(top_srcdir)/src/vmx $(AM_CFLAGS) libvirt_driver_esx_la_LDFLAGS = $(AM_LDFLAGS) libvirt_driver_esx_la_LIBADD = $(LIBCURL_LIBS) if WITH_DRIVER_MODULES @@ -913,7 +913,7 @@ noinst_LTLIBRARIES += libvirt_driver_hyperv.la libvirt_la_BUILT_LIBADD += libvirt_driver_hyperv.la endif libvirt_driver_hyperv_la_CFLAGS = $(OPENWSMAN_CFLAGS) \ - -I@top_srcdir@/src/conf $(AM_CFLAGS) + -I$(top_srcdir)/src/conf $(AM_CFLAGS) libvirt_driver_hyperv_la_LDFLAGS = $(AM_LDFLAGS) libvirt_driver_hyperv_la_LIBADD = $(OPENWSMAN_LIBS) if WITH_DRIVER_MODULES @@ -932,7 +932,7 @@ noinst_LTLIBRARIES += libvirt_driver_network.la #libvirt_la_BUILT_LIBADD += libvirt_driver_network.la endif libvirt_driver_network_la_CFLAGS = \ - -I@top_srcdir@/src/conf $(AM_CFLAGS) + -I$(top_srcdir)/src/conf $(AM_CFLAGS) if WITH_DRIVER_MODULES libvirt_driver_network_la_LIBADD = ../gnulib/lib/libgnu.la libvirt_driver_network_la_LDFLAGS = -module -avoid-version $(AM_LDFLAGS) @@ -952,7 +952,7 @@ noinst_LTLIBRARIES += libvirt_driver_interface.la libvirt_la_BUILT_LIBADD += libvirt_driver_interface.la endif libvirt_driver_interface_la_CFLAGS = $(NETCF_CFLAGS) \ - -I@top_srcdir@/src/conf $(AM_CFLAGS) + -I$(top_srcdir)/src/conf $(AM_CFLAGS) libvirt_driver_interface_la_LDFLAGS = $(AM_LDFLAGS) libvirt_driver_interface_la_LIBADD = $(NETCF_LIBS) if WITH_DRIVER_MODULES @@ -971,7 +971,7 @@ noinst_LTLIBRARIES += libvirt_driver_secret.la #libvirt_la_BUILT_LIBADD += libvirt_driver_secret.la endif libvirt_driver_secret_la_CFLAGS = \ - -I@top_srcdir@/src/conf $(AM_CFLAGS) + -I$(top_srcdir)/src/conf $(AM_CFLAGS) if WITH_DRIVER_MODULES libvirt_driver_secret_la_LIBADD = ../gnulib/lib/libgnu.la libvirt_driver_secret_la_LDFLAGS = -module -avoid-version $(AM_LDFLAGS) @@ -982,7 +982,7 @@ endif # Needed to keep automake quiet about conditionals libvirt_driver_storage_la_SOURCES = libvirt_driver_storage_la_CFLAGS = \ - -I@top_srcdir@/src/conf $(AM_CFLAGS) + -I$(top_srcdir)/src/conf $(AM_CFLAGS) libvirt_driver_storage_la_LDFLAGS = $(AM_LDFLAGS) libvirt_driver_storage_la_LIBADD = if WITH_SECDRIVER_SELINUX @@ -1045,7 +1045,7 @@ endif libvirt_driver_nodedev_la_SOURCES = $(NODE_DEVICE_DRIVER_SOURCES) libvirt_driver_nodedev_la_CFLAGS = \ - -I@top_srcdir@/src/conf $(AM_CFLAGS) + -I$(top_srcdir)/src/conf $(AM_CFLAGS) libvirt_driver_nodedev_la_LDFLAGS = $(AM_LDFLAGS) libvirt_driver_nodedev_la_LIBADD = \ libvirt_util.la \ @@ -1077,7 +1077,7 @@ libvirt_la_BUILT_LIBADD += libvirt_driver_nwfilter.la noinst_LTLIBRARIES += libvirt_driver_nwfilter.la endif libvirt_driver_nwfilter_la_CFLAGS = $(LIBPCAP_CFLAGS) \ - -I@top_srcdir@/src/conf $(AM_CFLAGS) + -I$(top_srcdir)/src/conf $(AM_CFLAGS) libvirt_driver_nwfilter_la_LDFLAGS = $(LD_AMFLAGS) libvirt_driver_nwfilter_la_LIBADD = $(LIBPCAP_LIBS) if WITH_DRIVER_MODULES @@ -1092,7 +1092,7 @@ libvirt_driver_security_la_SOURCES = $(SECURITY_DRIVER_SOURCES) noinst_LTLIBRARIES += libvirt_driver_security.la libvirt_la_BUILT_LIBADD += libvirt_driver_security.la libvirt_driver_security_la_CFLAGS = \ - -I@top_srcdir@/src/conf $(AM_CFLAGS) + -I$(top_srcdir)/src/conf $(AM_CFLAGS) libvirt_driver_security_la_LDFLAGS = $(AM_LDFLAGS) libvirt_driver_security_la_LIBADD = if WITH_SECDRIVER_SELINUX @@ -1532,7 +1532,7 @@ libvirt_lxc_CFLAGS = \ $(CAPNG_CFLAGS) \ $(YAJL_CFLAGS) \ $(AUDIT_CFLAGS) \ - -I@top_srcdir@/src/conf \ + -I$(top_srcdir)/src/conf \ $(AM_CFLAGS) if HAVE_LIBBLKID libvirt_lxc_CFLAGS += $(BLKID_CFLAGS) @@ -1558,8 +1558,8 @@ virt_aa_helper_LDADD = \ libvirt_util.la \ ../gnulib/lib/libgnu.la virt_aa_helper_CFLAGS = \ - -I@top_srcdir@/src/conf \ - -I@top_srcdir@/src/security \ + -I$(top_srcdir)/src/conf \ + -I$(top_srcdir)/src/security \ $(AM_CFLAGS) endif endif diff --git a/tests/Makefile.am b/tests/Makefile.am index ed47779..3fb9e2f 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,15 +1,14 @@ ## Process this file with automake to produce Makefile.in -## Copyright (C) 2005-2011 Red Hat, Inc. +## Copyright (C) 2005-2012 Red Hat, Inc. ## See COPYING.LIB for the License of this software SHELL = $(PREFERABLY_POSIX_SHELL) INCLUDES = \ - -I$(top_srcdir)/gnulib/lib -I../gnulib/lib \ - -I$(top_builddir)/include \ - -I$(top_srcdir)/include \ - -I$(top_srcdir)/src -I../src \ + -I$(top_builddir)/gnulib/lib -I$(top_srcdir)/gnulib/lib \ + -I$(top_builddir)/include -I$(top_srcdir)/include \ + -I$(top_builddir)/src -I$(top_srcdir)/src \ -I$(top_srcdir)/src/util \ -I$(top_srcdir)/src/conf \ $(GETTEXT_CPPFLAGS) diff --git a/tools/Makefile.am b/tools/Makefile.am index 6596a51..c0c907e 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -1,12 +1,12 @@ -## Copyright (C) 2005-2011 Red Hat, Inc. +## Copyright (C) 2005-2012 Red Hat, Inc. ## See COPYING.LIB for the License of this software INCLUDES = \ - -I../include -I$(top_srcdir)/include \ - -I$(top_srcdir)/gnulib/lib -I../gnulib/lib \ - -I$(top_srcdir)/src -I../src \ - -I$(top_srcdir)/src/util \ - -I$(top_srcdir) \ + -I$(top_builddir)/include -I$(top_srcdir)/include \ + -I$(top_builddir)/gnulib/lib -I$(top_srcdir)/gnulib/lib \ + -I$(top_builddir)/src -I$(top_srcdir)/src \ + -I$(top_srcdir)/src/util \ + -I$(top_srcdir) \ $(GETTEXT_CPPFLAGS) POD2MAN = pod2man -c "Virtualization Support" -r "$(PACKAGE)-$(VERSION)" -- 1.7.7.6

On Thu, Feb 02, 2012 at 17:33:20 -0700, Eric Blake wrote:
Our syntax checker missed all-lower-case variables (this will be fixed by the next .gnulib update). Additionally, anywhere that we mix in-tree files with generated files, automake recommends listing builddir prior to srcdir for VPATH builds.
* src/Makefile.am (*_la_CFLAGS): Favor $(top_srcdir). (INCLUDES): Likewise, and follow automake recommendations on builddir before srcdir. * python/Makefile.am (INCLUDES): Swap directory order. * tests/Makefile.am (INCLUDES): Likewise. * tools/Makefile.am (INCLUDES): Likewise. * daemon/Makefile.am (INCLUDES): Likewise. (libvirtd.init, libvirtd.service): Favor $(). * examples/hellolibvirt/Makefile.am (hellolibvirt_LDADD): Likewise. * examples/openauth/Makefile.am (openauth_LDADD): Likewise. * examples/dominfo/Makefile.am (INCLUDES): Drop dead include. * examples/domsuspend/Makefile.am (INCLUDES): Likewise. --- daemon/Makefile.am | 20 +++++----- examples/dominfo/Makefile.am | 4 +- examples/domsuspend/Makefile.am | 4 +- examples/hellolibvirt/Makefile.am | 4 +- examples/openauth/Makefile.am | 4 +- python/Makefile.am | 4 +- src/Makefile.am | 70 ++++++++++++++++++------------------ tests/Makefile.am | 9 ++--- tools/Makefile.am | 12 +++--- 9 files changed, 65 insertions(+), 66 deletions(-)
ACK Jirka

I noticed some redundant code while preparing my next patch. * python/generator.py (py_types): Fix 'const char *' mapping. * python/typewrappers.h (libvirt_charPtrConstWrap): Drop. * python/typewrappers.c (libvirt_charPtrConstWrap): Delete, since it is identical to libvirt_constcharPtrWrap. --- python/generator.py | 2 +- python/typewrappers.c | 13 ------------- python/typewrappers.h | 3 +-- 3 files changed, 2 insertions(+), 16 deletions(-) diff --git a/python/generator.py b/python/generator.py index b514af5..0728519 100755 --- a/python/generator.py +++ b/python/generator.py @@ -263,7 +263,7 @@ py_types = { 'unsigned long long': ('l', None, "longlong", "long long"), 'unsigned char *': ('z', None, "charPtr", "char *"), 'char *': ('z', None, "charPtr", "char *"), - 'const char *': ('z', None, "charPtrConst", "const char *"), + 'const char *': ('z', None, "constcharPtr", "const char *"), 'size_t': ('n', None, "size_t", "size_t"), 'virDomainPtr': ('O', "virDomain", "virDomainPtr", "virDomainPtr"), diff --git a/python/typewrappers.c b/python/typewrappers.c index b5758b4..9021ce3 100644 --- a/python/typewrappers.c +++ b/python/typewrappers.c @@ -118,19 +118,6 @@ libvirt_constcharPtrWrap(const char *str) } PyObject * -libvirt_charPtrConstWrap(const char *str) -{ - PyObject *ret; - - if (str == NULL) { - Py_INCREF(Py_None); - return (Py_None); - } - ret = PyString_FromString(str); - return (ret); -} - -PyObject * libvirt_virDomainPtrWrap(virDomainPtr node) { PyObject *ret; diff --git a/python/typewrappers.h b/python/typewrappers.h index 87ea1e5..1e34dfa 100644 --- a/python/typewrappers.h +++ b/python/typewrappers.h @@ -1,7 +1,7 @@ /* * libvirt_wrap.h: type wrappers for libvir python bindings * - * Copyright (C) 2005, 2011 Red Hat, Inc. + * Copyright (C) 2005, 2011-2012 Red Hat, Inc. * * Daniel Veillard <veillard@redhat.com> */ @@ -163,7 +163,6 @@ PyObject * libvirt_ulonglongWrap(unsigned long long val); PyObject * libvirt_charPtrWrap(char *str); PyObject * libvirt_charPtrSizeWrap(char *str, Py_ssize_t size); PyObject * libvirt_constcharPtrWrap(const char *str); -PyObject * libvirt_charPtrConstWrap(const char *str); PyObject * libvirt_virConnectPtrWrap(virConnectPtr node); PyObject * libvirt_virDomainPtrWrap(virDomainPtr node); PyObject * libvirt_virNetworkPtrWrap(virNetworkPtr node); -- 1.7.7.6

On Thu, Feb 02, 2012 at 17:33:21 -0700, Eric Blake wrote:
I noticed some redundant code while preparing my next patch.
* python/generator.py (py_types): Fix 'const char *' mapping. * python/typewrappers.h (libvirt_charPtrConstWrap): Drop. * python/typewrappers.c (libvirt_charPtrConstWrap): Delete, since it is identical to libvirt_constcharPtrWrap. --- python/generator.py | 2 +- python/typewrappers.c | 13 ------------- python/typewrappers.h | 3 +-- 3 files changed, 2 insertions(+), 16 deletions(-)
ACK Jirka

Our HACKING discourages use of malloc and free, for at least a couple of years now. But we weren't enforcing it, until now :) For now, I've exempted python and tests, and will clean those up in subsequent patches. Examples should be permanently exempt, since anyone copying our examples won't have use of our internal-only memory.h via libvirt_util.la. * cfg.mk (sc_prohibit_raw_allocation): New rule. (exclude_file_name_regexp--sc_prohibit_raw_allocation): and exemptions. * src/cpu/cpu.c (cpuDataFree): Avoid false positive. * src/conf/network_conf.c (virNetworkDNSSrvDefParseXML): Fix offenders. * src/libxl/libxl_conf.c (libxlMakeDomBuildInfo, libxlMakeVfb) (libxlMakeDeviceModelInfo): Likewise. * src/rpc/virnetmessage.c (virNetMessageSaveError): Likewise. * tools/virsh.c (_vshMalloc, _vshCalloc): Likewise. --- cfg.mk | 9 +++++++++ src/conf/network_conf.c | 2 +- src/cpu/cpu.c | 4 ++-- src/libxl/libxl_conf.c | 13 +++++++------ src/rpc/virnetmessage.c | 23 ++++++++++++----------- tools/virsh.c | 9 +++++---- 6 files changed, 36 insertions(+), 24 deletions(-) diff --git a/cfg.mk b/cfg.mk index c13db18..f91c90c 100644 --- a/cfg.mk +++ b/cfg.mk @@ -316,6 +316,12 @@ sc_prohibit_internal_functions: halt='use VIR_ macros instead of internal functions' \ $(_sc_search_regexp) +# 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' \ + $(_sc_search_regexp) + # Avoid functions that can lead to double-close bugs. sc_prohibit_close: @prohibit='([^>.]|^)\<[fp]?close *\(' \ @@ -737,6 +743,9 @@ exclude_file_name_regexp--sc_prohibit_newline_at_end_of_diagnostic = \ exclude_file_name_regexp--sc_prohibit_nonreentrant = \ ^((po|tests)/|docs/.*py$$|tools/(virsh|console)\.c$$) +exclude_file_name_regexp--sc_prohibit_raw_allocation = \ + ^(src/util/memory\.[ch]|(examples|python|tests)/.*)$$ + exclude_file_name_regexp--sc_prohibit_readlink = ^src/util/util\.c$$ exclude_file_name_regexp--sc_prohibit_setuid = ^src/util/util\.c$$ diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index c65c75c..44dd70b 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -592,7 +592,7 @@ virNetworkDNSSrvDefParseXML(virNetworkDNSDefPtr def, virAsprintf(&name, _("Service name is too long, limit is %d bytes"), DNS_RECORD_LENGTH_SRV); virNetworkReportError(VIR_ERR_XML_DETAIL, "%s", name); - free(name); + VIR_FREE(name); goto error; } diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c index 1f39934..01c31bb 100644 --- a/src/cpu/cpu.c +++ b/src/cpu/cpu.c @@ -1,7 +1,7 @@ /* * cpu.c: internal functions for CPU manipulation * - * Copyright (C) 2009-2011 Red Hat, Inc. + * Copyright (C) 2009-2012 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -220,7 +220,7 @@ cpuDataFree(const char *arch, return; } - driver->free(data); + (driver->free)(data); } diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index 24830e8..62621f1 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -1,6 +1,7 @@ /*---------------------------------------------------------------------------*/ -/* Copyright (c) 2011 SUSE LINUX Products GmbH, Nuernberg, Germany. - * Copyright (C) 2011 Univention GmbH. +/* Copyright (C) 2012 Red Hat, Inc. + * Copyright (c) 2011 SUSE LINUX Products GmbH, Nuernberg, Germany. + * Copyright (C) 2011 Univention GmbH. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -466,7 +467,7 @@ libxlMakeDomBuildInfo(virDomainDefPtr def, libxl_domain_config *d_config) } if (def->os.kernel) { /* libxl_init_build_info() sets kernel.path = strdup("hvmloader") */ - free(b_info->kernel.path); + VIR_FREE(b_info->kernel.path); if ((b_info->kernel.path = strdup(def->os.kernel)) == NULL) { virReportOOMError(); goto error; @@ -707,7 +708,7 @@ libxlMakeVfb(libxlDriverPrivatePtr driver, virDomainDefPtr def, listenAddr = virDomainGraphicsListenGetAddress(l_vfb, 0); if (listenAddr) { /* libxl_device_vfb_init() does strdup("127.0.0.1") */ - free(x_vfb->vnclisten); + VIR_FREE(x_vfb->vnclisten); if ((x_vfb->vnclisten = strdup(listenAddr)) == NULL) { virReportOOMError(); return -1; @@ -827,7 +828,7 @@ libxlMakeDeviceModelInfo(virDomainDefPtr def, libxl_domain_config *d_config) /* HVM-specific device model info */ dm_info->type = XENFV; if (def->os.nBootDevs > 0) { - free(dm_info->boot); + VIR_FREE(dm_info->boot); for (i = 0; i < def->os.nBootDevs; i++) { switch (def->os.bootDevs[i]) { case VIR_DOMAIN_BOOT_FLOPPY: @@ -866,7 +867,7 @@ libxlMakeDeviceModelInfo(virDomainDefPtr def, libxl_domain_config *d_config) /* driver handles selection of free port */ dm_info->vncunused = 0; if (d_config->vfbs[0].vnclisten) { - free(dm_info->vnclisten); + VIR_FREE(dm_info->vnclisten); if ((dm_info->vnclisten = strdup(d_config->vfbs[0].vnclisten)) == NULL) { virReportOOMError(); diff --git a/src/rpc/virnetmessage.c b/src/rpc/virnetmessage.c index 8abf5ab..17ecc90 100644 --- a/src/rpc/virnetmessage.c +++ b/src/rpc/virnetmessage.c @@ -1,7 +1,7 @@ /* * virnetmessage.c: basic RPC message encoding/decoding * - * Copyright (C) 2010-2011 Red Hat, Inc. + * Copyright (C) 2010-2012 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -466,26 +466,27 @@ void virNetMessageSaveError(virNetMessageErrorPtr rerr) if (rerr->code != VIR_ERR_OK) return; + memset(rerr, 0, sizeof(*rerr)); virErrorPtr verr = virGetLastError(); if (verr) { rerr->code = verr->code; rerr->domain = verr->domain; - rerr->message = verr->message ? malloc(sizeof(char*)) : NULL; - if (rerr->message) *rerr->message = strdup(verr->message); + if (verr->message && VIR_ALLOC(rerr->message) == 0) + *rerr->message = strdup(verr->message); rerr->level = verr->level; - rerr->str1 = verr->str1 ? malloc(sizeof(char*)) : NULL; - if (rerr->str1) *rerr->str1 = strdup(verr->str1); - rerr->str2 = verr->str2 ? malloc(sizeof(char*)) : NULL; - if (rerr->str2) *rerr->str2 = strdup(verr->str2); - rerr->str3 = verr->str3 ? malloc(sizeof(char*)) : NULL; - if (rerr->str3) *rerr->str3 = strdup(verr->str3); + if (verr->str1 && VIR_ALLOC(rerr->str1) == 0) + *rerr->str1 = strdup(verr->str1); + if (verr->str2 && VIR_ALLOC(rerr->str2) == 0) + *rerr->str2 = strdup(verr->str2); + if (verr->str3 && VIR_ALLOC(rerr->str3) == 0) + *rerr->str3 = strdup(verr->str3); rerr->int1 = verr->int1; rerr->int2 = verr->int2; } else { rerr->code = VIR_ERR_INTERNAL_ERROR; rerr->domain = VIR_FROM_RPC; - rerr->message = malloc(sizeof(char*)); - if (rerr->message) *rerr->message = strdup(_("Library function returned error but did not set virError")); + if (VIR_ALLOC(rerr->message) == 0) + *rerr->message = strdup(_("Library function returned error but did not set virError")); rerr->level = VIR_ERR_ERROR; } } diff --git a/tools/virsh.c b/tools/virsh.c index af78102..e496dd2 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -436,9 +436,9 @@ static int parseRateStr(const char *rateStr, virNetDevBandwidthRatePtr rate); static void * _vshMalloc(vshControl *ctl, size_t size, const char *filename, int line) { - void *x; + char *x; - if ((x = malloc(size))) + if (VIR_ALLOC_N(x, size) == 0) return x; vshError(ctl, _("%s: %d: failed to allocate %d bytes"), filename, line, (int) size); @@ -448,9 +448,10 @@ _vshMalloc(vshControl *ctl, size_t size, const char *filename, int line) static void * _vshCalloc(vshControl *ctl, size_t nmemb, size_t size, const char *filename, int line) { - void *x; + char *x; - if ((x = calloc(nmemb, size))) + if (!xalloc_oversized(nmemb, size) && + VIR_ALLOC_N(x, nmemb * size) == 0) return x; vshError(ctl, _("%s: %d: failed to allocate %d bytes"), filename, line, (int) (size*nmemb)); -- 1.7.7.6

On Thu, Feb 02, 2012 at 17:33:22 -0700, Eric Blake wrote:
Our HACKING discourages use of malloc and free, for at least a couple of years now. But we weren't enforcing it, until now :)
For now, I've exempted python and tests, and will clean those up in subsequent patches. Examples should be permanently exempt, since anyone copying our examples won't have use of our internal-only memory.h via libvirt_util.la.
* cfg.mk (sc_prohibit_raw_allocation): New rule. (exclude_file_name_regexp--sc_prohibit_raw_allocation): and exemptions. * src/cpu/cpu.c (cpuDataFree): Avoid false positive. * src/conf/network_conf.c (virNetworkDNSSrvDefParseXML): Fix offenders. * src/libxl/libxl_conf.c (libxlMakeDomBuildInfo, libxlMakeVfb) (libxlMakeDeviceModelInfo): Likewise. * src/rpc/virnetmessage.c (virNetMessageSaveError): Likewise. * tools/virsh.c (_vshMalloc, _vshCalloc): Likewise. --- cfg.mk | 9 +++++++++ src/conf/network_conf.c | 2 +- src/cpu/cpu.c | 4 ++-- src/libxl/libxl_conf.c | 13 +++++++------ src/rpc/virnetmessage.c | 23 ++++++++++++----------- tools/virsh.c | 9 +++++---- 6 files changed, 36 insertions(+), 24 deletions(-)
diff --git a/cfg.mk b/cfg.mk index c13db18..f91c90c 100644 --- a/cfg.mk +++ b/cfg.mk @@ -316,6 +316,12 @@ sc_prohibit_internal_functions: halt='use VIR_ macros instead of internal functions' \ $(_sc_search_regexp)
+# 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' \ + $(_sc_search_regexp) + # Avoid functions that can lead to double-close bugs. sc_prohibit_close: @prohibit='([^>.]|^)\<[fp]?close *\(' \ @@ -737,6 +743,9 @@ exclude_file_name_regexp--sc_prohibit_newline_at_end_of_diagnostic = \ exclude_file_name_regexp--sc_prohibit_nonreentrant = \ ^((po|tests)/|docs/.*py$$|tools/(virsh|console)\.c$$)
+exclude_file_name_regexp--sc_prohibit_raw_allocation = \ + ^(src/util/memory\.[ch]|(examples|python|tests)/.*)$$ + exclude_file_name_regexp--sc_prohibit_readlink = ^src/util/util\.c$$
exclude_file_name_regexp--sc_prohibit_setuid = ^src/util/util\.c$$ ... diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c index 1f39934..01c31bb 100644 --- a/src/cpu/cpu.c +++ b/src/cpu/cpu.c @@ -1,7 +1,7 @@ /* * cpu.c: internal functions for CPU manipulation * - * Copyright (C) 2009-2011 Red Hat, Inc. + * Copyright (C) 2009-2012 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -220,7 +220,7 @@ cpuDataFree(const char *arch, return; }
- driver->free(data); + (driver->free)(data); }
I was wondering why you changed this but then I realized it's just to shut up your new syntax-check rule. Nice. ACK Jirka

The bulk of this patch was done with: sed -i 's/\(\bfree *(/VIR_FREE(/g' tests/*.c followed by fixing the few compile errors that resulted. * cfg.mk (exclude_file_name_regexp--sc_prohibit_raw_allocation): Remove tests from exemption. * tests/testutils.h: Add common header. * tests/commandhelper.c: Fix offenders. * tests/cputest.c: Likewise. * tests/domainsnapshotxml2xmltest.c: Likewise. * tests/interfacexml2xmltest.c: Likewise. * tests/networkxml2argvtest.c: Likewise. * tests/networkxml2xmltest.c: Likewise. * tests/nodedevxml2xmltest.c: Likewise. * tests/nodeinfotest.c: Likewise. * tests/nwfilterxml2xmltest.c: Likewise. * tests/qemuargv2xmltest.c: Likewise. * tests/qemuxml2argvtest.c: Likewise. * tests/qemuxml2xmltest.c: Likewise. * tests/qemuxmlnstest.c: Likewise. * tests/qparamtest.c: Likewise. * tests/sexpr2xmltest.c: Likewise. * tests/storagepoolxml2xmltest.c: Likewise. * tests/storagevolxml2xmltest.c: Likewise. * tests/testutils.c: Likewise. * tests/virshtest.c: Likewise. * tests/xencapstest.c: Likewise. * tests/xmconfigtest.c: Likewise. * tests/xml2sexprtest.c: Likewise. --- cfg.mk | 2 +- tests/commandhelper.c | 6 +++--- tests/cputest.c | 36 +++++++++++++++++++----------------- tests/domainsnapshotxml2xmltest.c | 6 +++--- tests/interfacexml2xmltest.c | 6 +++--- tests/networkxml2argvtest.c | 10 +++++----- tests/networkxml2xmltest.c | 10 +++++----- tests/nodedevxml2xmltest.c | 6 +++--- tests/nodeinfotest.c | 10 +++++----- tests/nwfilterxml2xmltest.c | 10 +++++----- tests/qemuargv2xmltest.c | 20 ++++++++++---------- tests/qemuxml2argvtest.c | 28 ++++++++++++++-------------- tests/qemuxml2xmltest.c | 10 +++++----- tests/qemuxmlnstest.c | 23 ++++++++++++----------- tests/qparamtest.c | 2 +- tests/sexpr2xmltest.c | 10 +++++----- tests/storagepoolxml2xmltest.c | 10 +++++----- tests/storagevolxml2xmltest.c | 14 +++++++------- tests/testutils.c | 9 ++++----- tests/testutils.h | 3 ++- tests/virshtest.c | 4 ++-- tests/xencapstest.c | 10 +++++----- tests/xmconfigtest.c | 10 +++++----- tests/xml2sexprtest.c | 10 +++++----- 24 files changed, 134 insertions(+), 131 deletions(-) diff --git a/cfg.mk b/cfg.mk index f91c90c..f9c1558 100644 --- a/cfg.mk +++ b/cfg.mk @@ -744,7 +744,7 @@ exclude_file_name_regexp--sc_prohibit_nonreentrant = \ ^((po|tests)/|docs/.*py$$|tools/(virsh|console)\.c$$) exclude_file_name_regexp--sc_prohibit_raw_allocation = \ - ^(src/util/memory\.[ch]|(examples|python|tests)/.*)$$ + ^(src/util/memory\.[ch]|(examples|python)/.*)$$ exclude_file_name_regexp--sc_prohibit_readlink = ^src/util/util\.c$$ diff --git a/tests/commandhelper.c b/tests/commandhelper.c index cba208a..71d93be 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -1,7 +1,7 @@ /* * commandhelper.c: Auxiliary program for commandtest * - * Copyright (C) 2010-2011 Red Hat, Inc. + * Copyright (C) 2010-2012 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -42,8 +42,8 @@ static int envsort(const void *a, const void *b) { char *akey = strndup(astr, aeq - astr); char *bkey = strndup(bstr, beq - bstr); int ret = strcmp(akey, bkey); - free(akey); - free(bkey); + VIR_FREE(akey); + VIR_FREE(bkey); return ret; } diff --git a/tests/cputest.c b/tests/cputest.c index 17e14f7..15614a7 100644 --- a/tests/cputest.c +++ b/tests/cputest.c @@ -104,7 +104,7 @@ cpuTestLoadXML(const char *arch, const char *name) cleanup: xmlXPathFreeContext(ctxt); xmlFreeDoc(doc); - free(xml); + VIR_FREE(xml); return cpu; } @@ -129,7 +129,7 @@ cpuTestLoadMultiXML(const char *arch, goto error; n = virXPathNodeSet("/cpuTest/cpu", ctxt, &nodes); - if (n <= 0 || !(cpus = calloc(n, sizeof(virCPUDefPtr)))) + if (n <= 0 || (VIR_ALLOC_N(cpus, n) < 0)) goto error; for (i = 0; i < n; i++) { @@ -142,8 +142,8 @@ cpuTestLoadMultiXML(const char *arch, *count = n; cleanup: - free(xml); - free(nodes); + VIR_FREE(xml); + VIR_FREE(nodes); xmlXPathFreeContext(ctxt); xmlFreeDoc(doc); return cpus; @@ -152,7 +152,7 @@ error: if (cpus) { for (i = 0; i < n; i++) virCPUDefFree(cpus[i]); - free(cpus); + VIR_FREE(cpus); cpus = NULL; } goto cleanup; @@ -190,9 +190,9 @@ cpuTestCompareXML(const char *arch, ret = 0; cleanup: - free(xml); - free(expected); - free(actual); + VIR_FREE(xml); + VIR_FREE(expected); + VIR_FREE(actual); return ret; } @@ -381,10 +381,10 @@ cleanup: if (cpus) { for (i = 0; i < ncpus; i++) virCPUDefFree(cpus[i]); - free(cpus); + VIR_FREE(cpus); } virCPUDefFree(baseline); - free(result); + VIR_FREE(result); return ret; } @@ -414,7 +414,7 @@ cpuTestUpdate(const void *arg) cleanup: virCPUDefFree(host); virCPUDefFree(cpu); - free(result); + VIR_FREE(result); return ret; } @@ -473,11 +473,13 @@ static int cpuTestRun(const char *name, const struct data *data) { char *label = NULL; + char *tmp; if (virAsprintf(&label, "CPU %s(%s): %s", apis[data->api], data->arch, name) < 0) return -1; - free(virtTestLogContentAndReset()); + tmp = virtTestLogContentAndReset(); + VIR_FREE(tmp); if (virtTestRun(label, 1, cpuTest[data->api], data) < 0) { if (virTestGetDebug()) { @@ -485,14 +487,14 @@ cpuTestRun(const char *name, const struct data *data) if ((log = virtTestLogContentAndReset()) && strlen(log) > 0) fprintf(stderr, "\n%s\n", log); - free(log); + VIR_FREE(log); } - free(label); + VIR_FREE(label); return -1; } - free(label); + VIR_FREE(label); return 0; } @@ -513,7 +515,7 @@ mymain(void) if (virAsprintf(&map, "%s/src/cpu/cpu_map.xml", abs_top_srcdir) < 0 || cpuMapOverride(map) < 0) { - free(map); + VIR_FREE(map); return EXIT_FAILURE; } @@ -632,7 +634,7 @@ mymain(void) DO_TEST_GUESTDATA("x86", "host", "host+host-model-nofallback", models, "Penryn", -1); - free(map); + VIR_FREE(map); return (ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE); } diff --git a/tests/domainsnapshotxml2xmltest.c b/tests/domainsnapshotxml2xmltest.c index 5c2e670..978a2d4 100644 --- a/tests/domainsnapshotxml2xmltest.c +++ b/tests/domainsnapshotxml2xmltest.c @@ -51,8 +51,8 @@ testCompareXMLToXMLFiles(const char *inxml, const char *uuid, int internal) ret = 0; fail: - free(inXmlData); - free(actual); + VIR_FREE(inXmlData); + VIR_FREE(actual); virDomainSnapshotDefFree(def); return ret; } @@ -77,7 +77,7 @@ testCompareXMLToXMLHelper(const void *data) ret = testCompareXMLToXMLFiles(xml_in, info->uuid, info->internal); cleanup: - free(xml_in); + VIR_FREE(xml_in); return ret; } diff --git a/tests/interfacexml2xmltest.c b/tests/interfacexml2xmltest.c index dc08ea7..c5c5415 100644 --- a/tests/interfacexml2xmltest.c +++ b/tests/interfacexml2xmltest.c @@ -39,8 +39,8 @@ testCompareXMLToXMLFiles(const char *xml) ret = 0; fail: - free(xmlData); - free(actual); + VIR_FREE(xmlData); + VIR_FREE(actual); virInterfaceDefFree(dev); return ret; } @@ -57,7 +57,7 @@ testCompareXMLToXMLHelper(const void *data) result = testCompareXMLToXMLFiles(xml); - free (xml); + VIR_FREE(xml); return result; } diff --git a/tests/networkxml2argvtest.c b/tests/networkxml2argvtest.c index 5c6e29d..e000be9 100644 --- a/tests/networkxml2argvtest.c +++ b/tests/networkxml2argvtest.c @@ -91,9 +91,9 @@ static int testCompareXMLToArgvFiles(const char *inxml, const char *outargv) { ret = 0; fail: - free(inXmlData); - free(outArgvData); - free(actual); + VIR_FREE(inXmlData); + VIR_FREE(outArgvData); + VIR_FREE(actual); VIR_FREE(pidfile); virCommandFree(cmd); virNetworkObjFree(obj); @@ -118,8 +118,8 @@ testCompareXMLToArgvHelper(const void *data) result = testCompareXMLToArgvFiles(inxml, outxml); cleanup: - free(inxml); - free(outxml); + VIR_FREE(inxml); + VIR_FREE(outxml); return result; } diff --git a/tests/networkxml2xmltest.c b/tests/networkxml2xmltest.c index 6cb9d90..77528a8 100644 --- a/tests/networkxml2xmltest.c +++ b/tests/networkxml2xmltest.c @@ -42,9 +42,9 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml, ret = 0; fail: - free(inXmlData); - free(outXmlData); - free(actual); + VIR_FREE(inXmlData); + VIR_FREE(outXmlData); + VIR_FREE(actual); virNetworkDefFree(dev); return ret; } @@ -72,8 +72,8 @@ testCompareXMLToXMLHelper(const void *data) result = testCompareXMLToXMLFiles(inxml, outxml, info->flags); cleanup: - free(inxml); - free(outxml); + VIR_FREE(inxml); + VIR_FREE(outxml); return result; } diff --git a/tests/nodedevxml2xmltest.c b/tests/nodedevxml2xmltest.c index d0deaeb..ad93161 100644 --- a/tests/nodedevxml2xmltest.c +++ b/tests/nodedevxml2xmltest.c @@ -38,8 +38,8 @@ testCompareXMLToXMLFiles(const char *xml) ret = 0; fail: - free(xmlData); - free(actual); + VIR_FREE(xmlData); + VIR_FREE(actual); virNodeDeviceDefFree(dev); return ret; } @@ -56,7 +56,7 @@ testCompareXMLToXMLHelper(const void *data) result = testCompareXMLToXMLFiles(xml); - free(xml); + VIR_FREE(xml); return result; } diff --git a/tests/nodeinfotest.c b/tests/nodeinfotest.c index 0952a6b..32d964e 100644 --- a/tests/nodeinfotest.c +++ b/tests/nodeinfotest.c @@ -81,8 +81,8 @@ linuxTestCompareFiles(const char *cpuinfofile, ret = 0; fail: - free(expectData); - free(actualData); + VIR_FREE(expectData); + VIR_FREE(actualData); return ret; } @@ -117,9 +117,9 @@ linuxTestNodeInfo(const void *data) result = linuxTestCompareFiles(cpuinfo, sysfs_cpuinfo, output); cleanup: - free(cpuinfo); - free(output); - free(sysfs_cpuinfo); + VIR_FREE(cpuinfo); + VIR_FREE(output); + VIR_FREE(sysfs_cpuinfo); return result; } diff --git a/tests/nwfilterxml2xmltest.c b/tests/nwfilterxml2xmltest.c index 39afa5c..db7fe78 100644 --- a/tests/nwfilterxml2xmltest.c +++ b/tests/nwfilterxml2xmltest.c @@ -55,9 +55,9 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml, ret = 0; fail: - free(inXmlData); - free(outXmlData); - free(actual); + VIR_FREE(inXmlData); + VIR_FREE(outXmlData); + VIR_FREE(actual); virNWFilterDefFree(dev); return ret; } @@ -85,8 +85,8 @@ testCompareXMLToXMLHelper(const void *data) result = testCompareXMLToXMLFiles(inxml, outxml, tp->expect_warning); cleanup: - free(inxml); - free(outxml); + VIR_FREE(inxml); + VIR_FREE(outxml); return result; } diff --git a/tests/qemuargv2xmltest.c b/tests/qemuargv2xmltest.c index 28434ff..51f5aed 100644 --- a/tests/qemuargv2xmltest.c +++ b/tests/qemuargv2xmltest.c @@ -52,10 +52,10 @@ static int testCompareXMLToArgvFiles(const char *xml, if ((log = virtTestLogContentAndReset()) == NULL) goto fail; if ((*log != '\0') != expect_warning) { - free(log); + VIR_FREE(log); goto fail; } - free(log); + VIR_FREE(log); if (!(actualxml = virDomainDefFormat(vmdef, 0))) goto fail; @@ -72,9 +72,9 @@ static int testCompareXMLToArgvFiles(const char *xml, ret = 0; fail: - free(expectxml); - free(actualxml); - free(cmd); + VIR_FREE(expectxml); + VIR_FREE(actualxml); + VIR_FREE(cmd); virDomainDefFree(vmdef); return ret; } @@ -103,8 +103,8 @@ testCompareXMLToArgvHelper(const void *data) result = testCompareXMLToArgvFiles(xml, args, !!info->extraFlags); cleanup: - free(xml); - free(args); + VIR_FREE(xml); + VIR_FREE(args); return result; } @@ -192,8 +192,8 @@ mymain(void) driver.vncTLSx509certdir = strdup("/etc/pki/tls/qemu"); DO_TEST("graphics-vnc-tls"); driver.vncSASL = driver.vncTLSx509verify = driver.vncTLS = 0; - free(driver.vncSASLdir); - free(driver.vncTLSx509certdir); + VIR_FREE(driver.vncSASLdir); + VIR_FREE(driver.vncTLSx509certdir); driver.vncSASLdir = driver.vncTLSx509certdir = NULL; DO_TEST("graphics-sdl"); @@ -238,7 +238,7 @@ mymain(void) DO_TEST_FULL("qemu-ns-no-env", 1, NULL); - free(driver.stateDir); + VIR_FREE(driver.stateDir); virCapabilitiesFree(driver.caps); return(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE); diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 23234f2..c8ce77f 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -120,7 +120,7 @@ static int testCompareXMLToArgvFiles(const char *xml, if (vmdef->emulator && STRPREFIX(vmdef->emulator, "/.")) { if (!(emulator = strdup(vmdef->emulator + 1))) goto out; - free(vmdef->emulator); + VIR_FREE(vmdef->emulator); vmdef->emulator = NULL; if (virAsprintf(&vmdef->emulator, "%s/qemuxml2argvdata/%s", abs_srcdir, emulator) < 0) @@ -164,8 +164,8 @@ static int testCompareXMLToArgvFiles(const char *xml, qemuDomainPCIAddressSetFree(pciaddrs); } - - free(virtTestLogContentAndReset()); + log = virtTestLogContentAndReset(); + VIR_FREE(log); virResetLastError(); /* We do not call qemuCapsExtractVersionInfo() before calling @@ -233,10 +233,10 @@ static int testCompareXMLToArgvFiles(const char *xml, ret = 0; out: - free(log); - free(emulator); - free(expectargv); - free(actualargv); + VIR_FREE(log); + VIR_FREE(emulator); + VIR_FREE(expectargv); + VIR_FREE(actualargv); virCommandFree(cmd); virDomainDefFree(vmdef); virUnrefConnect(conn); @@ -275,8 +275,8 @@ testCompareXMLToArgvHelper(const void *data) info->expectFailure); cleanup: - free(xml); - free(args); + VIR_FREE(xml); + VIR_FREE(args); return result; } @@ -307,7 +307,7 @@ mymain(void) return EXIT_FAILURE; if (virAsprintf(&map, "%s/src/cpu/cpu_map.xml", abs_top_srcdir) < 0 || cpuMapOverride(map) < 0) { - free(map); + VIR_FREE(map); return EXIT_FAILURE; } @@ -499,8 +499,8 @@ mymain(void) driver.vncTLSx509certdir = strdup("/etc/pki/tls/qemu"); DO_TEST("graphics-vnc-tls", false, NONE); driver.vncSASL = driver.vncTLSx509verify = driver.vncTLS = 0; - free(driver.vncSASLdir); - free(driver.vncTLSx509certdir); + VIR_FREE(driver.vncSASLdir); + VIR_FREE(driver.vncTLSx509certdir); driver.vncSASLdir = driver.vncTLSx509certdir = NULL; DO_TEST("graphics-sdl", false, NONE); @@ -738,9 +738,9 @@ mymain(void) DO_TEST("pseries-vio-address-clash", true, QEMU_CAPS_DRIVE, QEMU_CAPS_CHARDEV, QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG); - free(driver.stateDir); + VIR_FREE(driver.stateDir); virCapabilitiesFree(driver.caps); - free(map); + VIR_FREE(map); return(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE); } diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index 346e310..b0f80d3 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -48,9 +48,9 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml) ret = 0; fail: - free(inXmlData); - free(outXmlData); - free(actual); + VIR_FREE(inXmlData); + VIR_FREE(outXmlData); + VIR_FREE(actual); virDomainDefFree(def); return ret; } @@ -81,8 +81,8 @@ testCompareXMLToXMLHelper(const void *data) } cleanup: - free(xml_in); - free(xml_out); + VIR_FREE(xml_in); + VIR_FREE(xml_out); return ret; } diff --git a/tests/qemuxmlnstest.c b/tests/qemuxmlnstest.c index 0432cc4..6ae5880 100644 --- a/tests/qemuxmlnstest.c +++ b/tests/qemuxmlnstest.c @@ -69,7 +69,7 @@ static int testCompareXMLToArgvFiles(const char *xml, if (vmdef->emulator && STRPREFIX(vmdef->emulator, "/.")) { if (!(emulator = strdup(vmdef->emulator + 1))) goto fail; - free(vmdef->emulator); + VIR_FREE(vmdef->emulator); vmdef->emulator = NULL; if (virAsprintf(&vmdef->emulator, "%s/qemuxml2argvdata/%s", abs_srcdir, emulator) < 0) @@ -107,7 +107,8 @@ static int testCompareXMLToArgvFiles(const char *xml, } - free(virtTestLogContentAndReset()); + log = virtTestLogContentAndReset(); + VIR_FREE(log); virResetLastError(); /* We do not call qemuCapsExtractVersionInfo() before calling @@ -159,10 +160,10 @@ static int testCompareXMLToArgvFiles(const char *xml, ret = 0; fail: - free(log); - free(emulator); - free(expectargv); - free(actualargv); + VIR_FREE(log); + VIR_FREE(emulator); + VIR_FREE(expectargv); + VIR_FREE(actualargv); virCommandFree(cmd); virDomainDefFree(vmdef); virUnrefConnect(conn); @@ -198,8 +199,8 @@ testCompareXMLToArgvHelper(const void *data) info->json, info->expectError); cleanup: - free(xml); - free(args); + VIR_FREE(xml); + VIR_FREE(args); return result; } @@ -231,7 +232,7 @@ mymain(void) return EXIT_FAILURE; if (virAsprintf(&map, "%s/src/cpu/cpu_map.xml", abs_top_srcdir) < 0 || cpuMapOverride(map) < 0) { - free(map); + VIR_FREE(map); return EXIT_FAILURE; } @@ -275,9 +276,9 @@ mymain(void) DO_TEST("qemu-ns-commandline-ns0", false, NONE); DO_TEST("qemu-ns-commandline-ns1", false, NONE); - free(driver.stateDir); + VIR_FREE(driver.stateDir); virCapabilitiesFree(driver.caps); - free(map); + VIR_FREE(map); return(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE); } diff --git a/tests/qparamtest.c b/tests/qparamtest.c index 6dfac43..78551c6 100644 --- a/tests/qparamtest.c +++ b/tests/qparamtest.c @@ -71,7 +71,7 @@ qparamFormatTest(const void *data) ret = 0; fail: - free(output); + VIR_FREE(output); free_qparam_set(actual); return ret; } diff --git a/tests/sexpr2xmltest.c b/tests/sexpr2xmltest.c index 126a78c..12d9086 100644 --- a/tests/sexpr2xmltest.c +++ b/tests/sexpr2xmltest.c @@ -67,9 +67,9 @@ testCompareFiles(const char *xml, const char *sexpr, int xendConfigVersion) ret = 0; fail: - free(xmlData); - free(sexprData); - free(gotxml); + VIR_FREE(xmlData); + VIR_FREE(sexprData); + VIR_FREE(gotxml); virDomainDefFree(def); if (conn) virUnrefConnect(conn); @@ -101,8 +101,8 @@ testCompareHelper(const void *data) result = testCompareFiles(xml, args, info->version); cleanup: - free(xml); - free(args); + VIR_FREE(xml); + VIR_FREE(args); return result; } diff --git a/tests/storagepoolxml2xmltest.c b/tests/storagepoolxml2xmltest.c index f2c1780..886f310 100644 --- a/tests/storagepoolxml2xmltest.c +++ b/tests/storagepoolxml2xmltest.c @@ -41,9 +41,9 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml) ret = 0; fail: - free(inXmlData); - free(outXmlData); - free(actual); + VIR_FREE(inXmlData); + VIR_FREE(outXmlData); + VIR_FREE(actual); virStoragePoolDefFree(dev); return ret; } @@ -65,8 +65,8 @@ testCompareXMLToXMLHelper(const void *data) result = testCompareXMLToXMLFiles(inxml, outxml); cleanup: - free(inxml); - free(outxml); + VIR_FREE(inxml); + VIR_FREE(outxml); return result; } diff --git a/tests/storagevolxml2xmltest.c b/tests/storagevolxml2xmltest.c index c8dddbb..742a02c 100644 --- a/tests/storagevolxml2xmltest.c +++ b/tests/storagevolxml2xmltest.c @@ -49,10 +49,10 @@ testCompareXMLToXMLFiles(const char *poolxml, const char *inxml, ret = 0; fail: - free(poolXmlData); - free(inXmlData); - free(outXmlData); - free(actual); + VIR_FREE(poolXmlData); + VIR_FREE(inXmlData); + VIR_FREE(outXmlData); + VIR_FREE(actual); virStoragePoolDefFree(pool); virStorageVolDefFree(dev); return ret; @@ -84,9 +84,9 @@ testCompareXMLToXMLHelper(const void *data) result = testCompareXMLToXMLFiles(poolxml, inxml, outxml); cleanup: - free(poolxml); - free(inxml); - free(outxml); + VIR_FREE(poolxml); + VIR_FREE(inxml); + VIR_FREE(outxml); return result; } diff --git a/tests/testutils.c b/tests/testutils.c index fccea17..8678546 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -128,8 +128,7 @@ virtTestRun(const char *title, int nloops, int (*body)(const void *data), const fprintf(stderr, "%2d) %-65s ... ", testCounter, title); } - if (nloops > 1 && (ts = calloc(nloops, - sizeof(double)))==NULL) + if (nloops > 1 && (VIR_ALLOC_N(ts, nloops) < 0)) return -1; for (i=0; i < nloops; i++) { @@ -181,7 +180,7 @@ virtTestRun(const char *title, int nloops, int (*body)(const void *data), const } } - free(ts); + VIR_FREE(ts); return ret; } @@ -236,7 +235,7 @@ virtTestLoadFile(const char *file, char **buf) if (ferror(fp)) { fprintf (stderr, "%s: read failed: %s\n", file, strerror(errno)); VIR_FORCE_FCLOSE(fp); - free(*buf); + VIR_FREE(*buf); return -1; } } @@ -512,7 +511,7 @@ virtTestErrorHook(int n, void *data ATTRIBUTE_UNUSED) if (symbols[i]) fprintf(stderr, " TRACE: %s\n", symbols[i]); } - free(symbols); + VIR_FREE(symbols); } } #endif diff --git a/tests/testutils.h b/tests/testutils.h index 03d8dc6..2fde1b5 100644 --- a/tests/testutils.h +++ b/tests/testutils.h @@ -1,7 +1,7 @@ /* * utils.c: test utils * - * Copyright (C) 2005, 2008-2011 Red Hat, Inc. + * Copyright (C) 2005, 2008-2012 Red Hat, Inc. * * See COPYING.LIB for the License of this software * @@ -12,6 +12,7 @@ # define __VIT_TEST_UTILS_H__ # include <stdio.h> +# include "memory.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 */ diff --git a/tests/virshtest.c b/tests/virshtest.c index 9a39d46..6474c19 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -76,7 +76,7 @@ testCompareOutputLit(const char *expectData, result = 0; cleanup: - free(actualData); + VIR_FREE(actualData); return result; } @@ -388,7 +388,7 @@ mymain(void) # undef DO_TEST - free(custom_uri); + VIR_FREE(custom_uri); return(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE); } diff --git a/tests/xencapstest.c b/tests/xencapstest.c index ca93857..321f38a 100644 --- a/tests/xencapstest.c +++ b/tests/xencapstest.c @@ -54,11 +54,11 @@ testCompareFiles(const char *hostmachine, const char *xml_rel, ret = 0; fail: - free(expectxml); - free(actualxml); - free(xml); - free(cpuinfo); - free(capabilities); + VIR_FREE(expectxml); + VIR_FREE(actualxml); + VIR_FREE(xml); + VIR_FREE(cpuinfo); + VIR_FREE(capabilities); VIR_FORCE_FCLOSE(fp1); VIR_FORCE_FCLOSE(fp2); diff --git a/tests/xmconfigtest.c b/tests/xmconfigtest.c index c184b8d..f1e028a 100644 --- a/tests/xmconfigtest.c +++ b/tests/xmconfigtest.c @@ -87,9 +87,9 @@ testCompareParseXML(const char *xmcfg, const char *xml, int xendConfigVersion) ret = 0; fail: - free(xmlData); - free(xmcfgData); - free(gotxmcfgData); + VIR_FREE(xmlData); + VIR_FREE(xmcfgData); + VIR_FREE(gotxmcfgData); if (conf) virConfFree(conf); virDomainDefFree(def); @@ -179,8 +179,8 @@ testCompareHelper(const void *data) result = testCompareFormatXML(cfg, xml, info->version); cleanup: - free(xml); - free(cfg); + VIR_FREE(xml); + VIR_FREE(cfg); return result; } diff --git a/tests/xml2sexprtest.c b/tests/xml2sexprtest.c index 41712d3..12d63b6 100644 --- a/tests/xml2sexprtest.c +++ b/tests/xml2sexprtest.c @@ -46,9 +46,9 @@ testCompareFiles(const char *xml, const char *sexpr, int xendConfigVersion) ret = 0; fail: - free(xmlData); - free(sexprData); - free(gotsexpr); + VIR_FREE(xmlData); + VIR_FREE(sexprData); + VIR_FREE(gotsexpr); virDomainDefFree(def); return ret; @@ -79,8 +79,8 @@ testCompareHelper(const void *data) result = testCompareFiles(xml, args, info->version); cleanup: - free(xml); - free(args); + VIR_FREE(xml); + VIR_FREE(args); return result; } -- 1.7.7.6

On Thu, Feb 02, 2012 at 17:33:23 -0700, Eric Blake wrote:
The bulk of this patch was done with:
sed -i 's/\(\bfree *(/VIR_FREE(/g' tests/*.c
followed by fixing the few compile errors that resulted.
* cfg.mk (exclude_file_name_regexp--sc_prohibit_raw_allocation): Remove tests from exemption. * tests/testutils.h: Add common header. * tests/commandhelper.c: Fix offenders. * tests/cputest.c: Likewise. * tests/domainsnapshotxml2xmltest.c: Likewise. * tests/interfacexml2xmltest.c: Likewise. * tests/networkxml2argvtest.c: Likewise. * tests/networkxml2xmltest.c: Likewise. * tests/nodedevxml2xmltest.c: Likewise. * tests/nodeinfotest.c: Likewise. * tests/nwfilterxml2xmltest.c: Likewise. * tests/qemuargv2xmltest.c: Likewise. * tests/qemuxml2argvtest.c: Likewise. * tests/qemuxml2xmltest.c: Likewise. * tests/qemuxmlnstest.c: Likewise. * tests/qparamtest.c: Likewise. * tests/sexpr2xmltest.c: Likewise. * tests/storagepoolxml2xmltest.c: Likewise. * tests/storagevolxml2xmltest.c: Likewise. * tests/testutils.c: Likewise. * tests/virshtest.c: Likewise. * tests/xencapstest.c: Likewise. * tests/xmconfigtest.c: Likewise. * tests/xml2sexprtest.c: Likewise.
Mostly mechanical. ACK Jirka

This patch starts the process of elevating the python binding code to be on the same level as the rest of libvirt when it comes to requiring good coding styles. Statically linking against the libvirt_util library makes it much easier to write good code, rather than having to open-code and reinvent things locally. Done by global search and replace of s/free(/VIR_FREE(/, followed by hand-inspection of remaining malloc and redundant memset. * cfg.mk (exclude_file_name_regexp--sc_prohibit_raw_allocation): Remove python from exemption. * python/Makefile.am (INCLUDES): Add gnulib and src/util. Drop $(top_builddir)/$(subdir), as automake already guarantees that. (mylibs, myqemulibs): Pull in libvirt_util and gnulib. (libvirtmod_la_CFLAGS): Catch compiler warnings if configured to use -Werror. * python/typewrappers.c (libvirt_charPtrSizeWrap) (libvirt_charPtrWrap): Convert free to VIR_FREE. * python/generator.py (print_function_wrapper): Likewise. * python/libvirt-override.c: Likewise. --- cfg.mk | 2 +- python/Makefile.am | 18 ++- python/generator.py | 2 +- python/libvirt-override.c | 364 +++++++++++++++++++++------------------------ python/typewrappers.c | 8 +- 5 files changed, 194 insertions(+), 200 deletions(-) diff --git a/cfg.mk b/cfg.mk index f9c1558..dcf44bb 100644 --- a/cfg.mk +++ b/cfg.mk @@ -744,7 +744,7 @@ exclude_file_name_regexp--sc_prohibit_nonreentrant = \ ^((po|tests)/|docs/.*py$$|tools/(virsh|console)\.c$$) exclude_file_name_regexp--sc_prohibit_raw_allocation = \ - ^(src/util/memory\.[ch]|(examples|python)/.*)$$ + ^(src/util/memory\.[ch]|examples/.*)$$ exclude_file_name_regexp--sc_prohibit_readlink = ^src/util/util\.c$$ diff --git a/python/Makefile.am b/python/Makefile.am index 81b160a..9b791d7 100644 --- a/python/Makefile.am +++ b/python/Makefile.am @@ -7,9 +7,13 @@ SUBDIRS= . tests INCLUDES = \ $(PYTHON_INCLUDES) \ + -I$(top_builddir)/gnulib/lib \ + -I$(top_srcdir)/gnulib/lib \ + -I$(top_builddir)/src \ + -I$(top_srcdir)/src \ + -I$(top_srcdir)/src/util \ -I$(top_builddir)/include \ -I$(top_srcdir)/include \ - -I$(top_builddir)/$(subdir) \ $(GETTEXT_CPPFLAGS) AM_CFLAGS = $(WARN_CFLAGS) @@ -35,8 +39,14 @@ EXTRA_DIST = \ $(DOCS) if WITH_PYTHON -mylibs = $(top_builddir)/src/libvirt.la -myqemulibs = $(top_builddir)/src/libvirt-qemu.la +mylibs = \ + $(top_builddir)/src/libvirt.la \ + $(top_builddir)/src/libvirt_util.la \ + $(top_builddir)/gnulib/lib/libgnu.la +myqemulibs = \ + $(top_builddir)/src/libvirt-qemu.la \ + $(top_builddir)/src/libvirt_util.la \ + $(top_builddir)/gnulib/lib/libgnu.la all-local: libvirt.py libvirt_qemu.py @@ -46,7 +56,7 @@ libvirtmod_la_SOURCES = libvirt-override.c typewrappers.c nodist_libvirtmod_la_SOURCES = libvirt.c libvirt.h # Python <= 2.4 header files contain a redundant decl, hence we # need extra flags here -libvirtmod_la_CFLAGS = $(WARN_PYTHON_CFLAGS) +libvirtmod_la_CFLAGS = $(WARN_CFLAGS) $(WARN_PYTHON_CFLAGS) libvirtmod_la_LDFLAGS = -module -avoid-version -shared -L$(top_builddir)/src/.libs \ $(CYGWIN_EXTRA_LDFLAGS) diff --git a/python/generator.py b/python/generator.py index 0728519..98072f0 100755 --- a/python/generator.py +++ b/python/generator.py @@ -580,7 +580,7 @@ def print_function_wrapper(module, name, output, export, include): if ret[0] == 'void': if file == "python_accessor": if args[1][1] == "char *": - c_call = "\n free(%s->%s);\n" % ( + c_call = "\n VIR_FREE(%s->%s);\n" % ( args[0][0], args[1][0], args[0][0], args[1][0]) c_call = c_call + " %s->%s = (%s)strdup((const xmlChar *)%s);\n" % (args[0][0], args[1][0], args[1][1], args[1][0]) diff --git a/python/libvirt-override.c b/python/libvirt-override.c index 18849f8..68e0b55 100644 --- a/python/libvirt-override.c +++ b/python/libvirt-override.c @@ -4,7 +4,7 @@ * entry points where an automatically generated stub is * unpractical * - * Copyright (C) 2005, 2007-2011 Red Hat, Inc. + * Copyright (C) 2005, 2007-2012 Red Hat, Inc. * * Daniel Veillard <veillard@redhat.com> */ @@ -21,6 +21,7 @@ #include "libvirt/virterror.h" #include "typewrappers.h" #include "libvirt.h" +#include "memory.h" #ifndef __CYGWIN__ extern void initlibvirtmod(void); @@ -122,7 +123,7 @@ libvirt_virDomainBlockStatsFlags(PyObject *self ATTRIBUTE_UNUSED, if (i_retval < 0) return VIR_PY_NONE; - if ((params = malloc(sizeof(*params)*nparams)) == NULL) + if (VIR_ALLOC_N(params, nparams) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; @@ -130,13 +131,13 @@ libvirt_virDomainBlockStatsFlags(PyObject *self ATTRIBUTE_UNUSED, LIBVIRT_END_ALLOW_THREADS; if (i_retval < 0) { - free(params); + VIR_FREE(params); return VIR_PY_NONE; } /* convert to a Python tuple of long objects */ if ((info = PyDict_New()) == NULL) { - free(params); + VIR_FREE(params); return VIR_PY_NONE; } @@ -169,7 +170,7 @@ libvirt_virDomainBlockStatsFlags(PyObject *self ATTRIBUTE_UNUSED, break; default: - free(params); + VIR_FREE(params); Py_DECREF(info); return VIR_PY_NONE; } @@ -178,7 +179,7 @@ libvirt_virDomainBlockStatsFlags(PyObject *self ATTRIBUTE_UNUSED, PyDict_SetItem(info, key, val); } - free(params); + VIR_FREE(params); return(info); } @@ -283,13 +284,13 @@ libvirt_virDomainGetSchedulerType(PyObject *self ATTRIBUTE_UNUSED, /* convert to a Python tuple of long objects */ if ((info = PyTuple_New(2)) == NULL) { - free(c_retval); + VIR_FREE(c_retval); return VIR_PY_NONE; } PyTuple_SetItem(info, 0, libvirt_constcharPtrWrap(c_retval)); PyTuple_SetItem(info, 1, PyInt_FromLong((long)nparams)); - free(c_retval); + VIR_FREE(c_retval); return(info); } @@ -314,9 +315,9 @@ libvirt_virDomainGetSchedulerParameters(PyObject *self ATTRIBUTE_UNUSED, if (c_retval == NULL) return VIR_PY_NONE; - free(c_retval); + VIR_FREE(c_retval); - if ((params = malloc(sizeof(*params)*nparams)) == NULL) + if (VIR_ALLOC_N(params, nparams) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; @@ -324,13 +325,13 @@ libvirt_virDomainGetSchedulerParameters(PyObject *self ATTRIBUTE_UNUSED, LIBVIRT_END_ALLOW_THREADS; if (i_retval < 0) { - free(params); + VIR_FREE(params); return VIR_PY_NONE; } /* convert to a Python tuple of long objects */ if ((info = PyDict_New()) == NULL) { - free(params); + VIR_FREE(params); return VIR_PY_NONE; } for (i = 0 ; i < nparams ; i++) { @@ -362,7 +363,7 @@ libvirt_virDomainGetSchedulerParameters(PyObject *self ATTRIBUTE_UNUSED, break; default: - free(params); + VIR_FREE(params); Py_DECREF(info); return VIR_PY_NONE; } @@ -370,7 +371,7 @@ libvirt_virDomainGetSchedulerParameters(PyObject *self ATTRIBUTE_UNUSED, key = libvirt_constcharPtrWrap(params[i].field); PyDict_SetItem(info, key, val); } - free(params); + VIR_FREE(params); return(info); } @@ -396,9 +397,9 @@ libvirt_virDomainGetSchedulerParametersFlags(PyObject *self ATTRIBUTE_UNUSED, if (c_retval == NULL) return VIR_PY_NONE; - free(c_retval); + VIR_FREE(c_retval); - if ((params = malloc(sizeof(*params)*nparams)) == NULL) + if (VIR_ALLOC_N(params, nparams) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; @@ -406,13 +407,13 @@ libvirt_virDomainGetSchedulerParametersFlags(PyObject *self ATTRIBUTE_UNUSED, LIBVIRT_END_ALLOW_THREADS; if (i_retval < 0) { - free(params); + VIR_FREE(params); return VIR_PY_NONE; } /* convert to a Python tuple of long objects */ if ((info = PyDict_New()) == NULL) { - free(params); + VIR_FREE(params); return VIR_PY_NONE; } for (i = 0 ; i < nparams ; i++) { @@ -444,7 +445,7 @@ libvirt_virDomainGetSchedulerParametersFlags(PyObject *self ATTRIBUTE_UNUSED, break; default: - free(params); + VIR_FREE(params); Py_DECREF(info); return VIR_PY_NONE; } @@ -452,7 +453,7 @@ libvirt_virDomainGetSchedulerParametersFlags(PyObject *self ATTRIBUTE_UNUSED, key = libvirt_constcharPtrWrap(params[i].field); PyDict_SetItem(info, key, val); } - free(params); + VIR_FREE(params); return(info); } @@ -477,9 +478,9 @@ libvirt_virDomainSetSchedulerParameters(PyObject *self ATTRIBUTE_UNUSED, if (c_retval == NULL) return VIR_PY_INT_FAIL; - free(c_retval); + VIR_FREE(c_retval); - if ((params = malloc(sizeof(*params)*nparams)) == NULL) + if (VIR_ALLOC_N(params, nparams) < 0) return VIR_PY_INT_FAIL; LIBVIRT_BEGIN_ALLOW_THREADS; @@ -487,7 +488,7 @@ libvirt_virDomainSetSchedulerParameters(PyObject *self ATTRIBUTE_UNUSED, LIBVIRT_END_ALLOW_THREADS; if (i_retval < 0) { - free(params); + VIR_FREE(params); return VIR_PY_INT_FAIL; } @@ -534,7 +535,7 @@ libvirt_virDomainSetSchedulerParameters(PyObject *self ATTRIBUTE_UNUSED, break; default: - free(params); + VIR_FREE(params); return VIR_PY_INT_FAIL; } } @@ -543,11 +544,11 @@ libvirt_virDomainSetSchedulerParameters(PyObject *self ATTRIBUTE_UNUSED, i_retval = virDomainSetSchedulerParameters(domain, params, nparams); LIBVIRT_END_ALLOW_THREADS; if (i_retval < 0) { - free(params); + VIR_FREE(params); return VIR_PY_INT_FAIL; } - free(params); + VIR_FREE(params); return VIR_PY_INT_SUCCESS; } @@ -574,9 +575,9 @@ libvirt_virDomainSetSchedulerParametersFlags(PyObject *self ATTRIBUTE_UNUSED, if (c_retval == NULL) return VIR_PY_INT_FAIL; - free(c_retval); + VIR_FREE(c_retval); - if ((params = malloc(sizeof(*params)*nparams)) == NULL) + if (VIR_ALLOC_N(params, nparams) < 0) return VIR_PY_INT_FAIL; LIBVIRT_BEGIN_ALLOW_THREADS; @@ -584,7 +585,7 @@ libvirt_virDomainSetSchedulerParametersFlags(PyObject *self ATTRIBUTE_UNUSED, LIBVIRT_END_ALLOW_THREADS; if (i_retval < 0) { - free(params); + VIR_FREE(params); return VIR_PY_INT_FAIL; } @@ -631,7 +632,7 @@ libvirt_virDomainSetSchedulerParametersFlags(PyObject *self ATTRIBUTE_UNUSED, break; default: - free(params); + VIR_FREE(params); return VIR_PY_INT_FAIL; } } @@ -640,11 +641,11 @@ libvirt_virDomainSetSchedulerParametersFlags(PyObject *self ATTRIBUTE_UNUSED, i_retval = virDomainSetSchedulerParametersFlags(domain, params, nparams, flags); LIBVIRT_END_ALLOW_THREADS; if (i_retval < 0) { - free(params); + VIR_FREE(params); return VIR_PY_INT_FAIL; } - free(params); + VIR_FREE(params); return VIR_PY_INT_SUCCESS; } @@ -672,7 +673,7 @@ libvirt_virDomainSetBlkioParameters(PyObject *self ATTRIBUTE_UNUSED, if (i_retval < 0) return VIR_PY_INT_FAIL; - if ((params = malloc(sizeof(*params)*nparams)) == NULL) + if (VIR_ALLOC_N(params, nparams) < 0) return VIR_PY_INT_FAIL; LIBVIRT_BEGIN_ALLOW_THREADS; @@ -680,7 +681,7 @@ libvirt_virDomainSetBlkioParameters(PyObject *self ATTRIBUTE_UNUSED, LIBVIRT_END_ALLOW_THREADS; if (i_retval < 0) { - free(params); + VIR_FREE(params); return VIR_PY_INT_FAIL; } @@ -727,7 +728,7 @@ libvirt_virDomainSetBlkioParameters(PyObject *self ATTRIBUTE_UNUSED, break; default: - free(params); + VIR_FREE(params); return VIR_PY_INT_FAIL; } } @@ -736,11 +737,11 @@ libvirt_virDomainSetBlkioParameters(PyObject *self ATTRIBUTE_UNUSED, i_retval = virDomainSetBlkioParameters(domain, params, nparams, flags); LIBVIRT_END_ALLOW_THREADS; if (i_retval < 0) { - free(params); + VIR_FREE(params); return VIR_PY_INT_FAIL; } - free(params); + VIR_FREE(params); return VIR_PY_INT_SUCCESS; } @@ -766,7 +767,7 @@ libvirt_virDomainGetBlkioParameters(PyObject *self ATTRIBUTE_UNUSED, if (i_retval < 0) return VIR_PY_NONE; - if ((params = malloc(sizeof(*params)*nparams)) == NULL) + if (VIR_ALLOC_N(params, nparams) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; @@ -774,13 +775,13 @@ libvirt_virDomainGetBlkioParameters(PyObject *self ATTRIBUTE_UNUSED, LIBVIRT_END_ALLOW_THREADS; if (i_retval < 0) { - free(params); + VIR_FREE(params); return VIR_PY_NONE; } /* convert to a Python tuple of long objects */ if ((info = PyDict_New()) == NULL) { - free(params); + VIR_FREE(params); return VIR_PY_NONE; } for (i = 0 ; i < nparams ; i++) { @@ -812,7 +813,7 @@ libvirt_virDomainGetBlkioParameters(PyObject *self ATTRIBUTE_UNUSED, break; default: - free(params); + VIR_FREE(params); Py_DECREF(info); return VIR_PY_NONE; } @@ -820,7 +821,7 @@ libvirt_virDomainGetBlkioParameters(PyObject *self ATTRIBUTE_UNUSED, key = libvirt_constcharPtrWrap(params[i].field); PyDict_SetItem(info, key, val); } - free(params); + VIR_FREE(params); return(info); } @@ -847,7 +848,7 @@ libvirt_virDomainSetMemoryParameters(PyObject *self ATTRIBUTE_UNUSED, if (i_retval < 0) return VIR_PY_INT_FAIL; - if ((params = malloc(sizeof(*params)*nparams)) == NULL) + if (VIR_ALLOC_N(params, nparams) < 0) return VIR_PY_INT_FAIL; LIBVIRT_BEGIN_ALLOW_THREADS; @@ -855,7 +856,7 @@ libvirt_virDomainSetMemoryParameters(PyObject *self ATTRIBUTE_UNUSED, LIBVIRT_END_ALLOW_THREADS; if (i_retval < 0) { - free(params); + VIR_FREE(params); return VIR_PY_INT_FAIL; } @@ -902,7 +903,7 @@ libvirt_virDomainSetMemoryParameters(PyObject *self ATTRIBUTE_UNUSED, break; default: - free(params); + VIR_FREE(params); return VIR_PY_INT_FAIL; } } @@ -911,11 +912,11 @@ libvirt_virDomainSetMemoryParameters(PyObject *self ATTRIBUTE_UNUSED, i_retval = virDomainSetMemoryParameters(domain, params, nparams, flags); LIBVIRT_END_ALLOW_THREADS; if (i_retval < 0) { - free(params); + VIR_FREE(params); return VIR_PY_INT_FAIL; } - free(params); + VIR_FREE(params); return VIR_PY_INT_SUCCESS; } @@ -941,7 +942,7 @@ libvirt_virDomainGetMemoryParameters(PyObject *self ATTRIBUTE_UNUSED, if (i_retval < 0) return VIR_PY_NONE; - if ((params = malloc(sizeof(*params)*nparams)) == NULL) + if (VIR_ALLOC_N(params, nparams) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; @@ -949,13 +950,13 @@ libvirt_virDomainGetMemoryParameters(PyObject *self ATTRIBUTE_UNUSED, LIBVIRT_END_ALLOW_THREADS; if (i_retval < 0) { - free(params); + VIR_FREE(params); return VIR_PY_NONE; } /* convert to a Python tuple of long objects */ if ((info = PyDict_New()) == NULL) { - free(params); + VIR_FREE(params); return VIR_PY_NONE; } for (i = 0 ; i < nparams ; i++) { @@ -987,7 +988,7 @@ libvirt_virDomainGetMemoryParameters(PyObject *self ATTRIBUTE_UNUSED, break; default: - free(params); + VIR_FREE(params); Py_DECREF(info); return VIR_PY_NONE; } @@ -995,7 +996,7 @@ libvirt_virDomainGetMemoryParameters(PyObject *self ATTRIBUTE_UNUSED, key = libvirt_constcharPtrWrap(params[i].field); PyDict_SetItem(info, key, val); } - free(params); + VIR_FREE(params); return(info); } @@ -1028,11 +1029,12 @@ libvirt_virDomainGetVcpus(PyObject *self ATTRIBUTE_UNUSED, if (i_retval < 0) return VIR_PY_NONE; - if ((cpuinfo = malloc(sizeof(*cpuinfo)*dominfo.nrVirtCpu)) == NULL) + if (VIR_ALLOC_N(cpuinfo, dominfo.nrVirtCpu) < 0) return VIR_PY_NONE; cpumaplen = VIR_CPU_MAPLEN(VIR_NODEINFO_MAXCPUS(nodeinfo)); - if ((cpumap = malloc(dominfo.nrVirtCpu * cpumaplen)) == NULL) + if (xalloc_oversized(dominfo.nrVirtCpu, cpumaplen) || + VIR_ALLOC_N(cpumap, dominfo.nrVirtCpu * cpumaplen) < 0) goto cleanup; LIBVIRT_BEGIN_ALLOW_THREADS; @@ -1074,14 +1076,14 @@ libvirt_virDomainGetVcpus(PyObject *self ATTRIBUTE_UNUSED, PyTuple_SetItem(pyretval, 0, pycpuinfo); PyTuple_SetItem(pyretval, 1, pycpumap); - free(cpuinfo); - free(cpumap); + VIR_FREE(cpuinfo); + VIR_FREE(cpumap); return(pyretval); cleanup: - free(cpuinfo); - free(cpumap); + VIR_FREE(cpuinfo); + VIR_FREE(cpumap); /* NB, Py_DECREF is a badly defined macro, so we require * braces here to avoid 'ambiguous else' warnings from * the compiler. @@ -1117,9 +1119,8 @@ libvirt_virDomainPinVcpu(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_INT_FAIL; cpumaplen = VIR_CPU_MAPLEN(VIR_NODEINFO_MAXCPUS(nodeinfo)); - if ((cpumap = malloc(cpumaplen)) == NULL) + if (VIR_ALLOC_N(cpumap, cpumaplen) < 0) return VIR_PY_INT_FAIL; - memset(cpumap, 0, cpumaplen); truth = PyBool_FromLong(1); for (i = 0 ; i < VIR_NODEINFO_MAXCPUS(nodeinfo) ; i++) { @@ -1134,7 +1135,7 @@ libvirt_virDomainPinVcpu(PyObject *self ATTRIBUTE_UNUSED, i_retval = virDomainPinVcpu(domain, vcpu, cpumap, cpumaplen); LIBVIRT_END_ALLOW_THREADS; Py_DECREF(truth); - free(cpumap); + VIR_FREE(cpumap); if (i_retval < 0) return VIR_PY_INT_FAIL; @@ -1165,9 +1166,8 @@ libvirt_virDomainPinVcpuFlags(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_INT_FAIL; cpumaplen = VIR_CPU_MAPLEN(VIR_NODEINFO_MAXCPUS(nodeinfo)); - if ((cpumap = malloc(cpumaplen)) == NULL) + if (VIR_ALLOC_N(cpumap, cpumaplen) < 0) return VIR_PY_INT_FAIL; - memset(cpumap, 0, cpumaplen); truth = PyBool_FromLong(1); for (i = 0 ; i < VIR_NODEINFO_MAXCPUS(nodeinfo) ; i++) { @@ -1182,7 +1182,7 @@ libvirt_virDomainPinVcpuFlags(PyObject *self ATTRIBUTE_UNUSED, i_retval = virDomainPinVcpuFlags(domain, vcpu, cpumap, cpumaplen, flags); LIBVIRT_END_ALLOW_THREADS; Py_DECREF(truth); - free(cpumap); + VIR_FREE(cpumap); if (i_retval < 0) return VIR_PY_INT_FAIL; @@ -1220,9 +1220,9 @@ libvirt_virDomainGetVcpuPinInfo(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; cpumaplen = VIR_CPU_MAPLEN(VIR_NODEINFO_MAXCPUS(nodeinfo)); - if ((cpumaps = malloc(dominfo.nrVirtCpu * cpumaplen)) == NULL) + if (xalloc_oversized(dominfo.nrVirtCpu, cpumaplen) || + VIR_ALLOC_N(cpumaps, dominfo.nrVirtCpu * cpumaplen) < 0) goto cleanup; - memset(cpumaps, 0, dominfo.nrVirtCpu * cpumaplen); LIBVIRT_BEGIN_ALLOW_THREADS; i_retval = virDomainGetVcpuPinInfo(domain, dominfo.nrVirtCpu, @@ -1246,12 +1246,12 @@ libvirt_virDomainGetVcpuPinInfo(PyObject *self ATTRIBUTE_UNUSED, PyList_SetItem(pycpumaps, vcpu, mapinfo); } - free(cpumaps); + VIR_FREE(cpumaps); return pycpumaps; cleanup: - free(cpumaps); + VIR_FREE(cpumaps); if (pycpumaps) { Py_DECREF(pycpumaps);} @@ -1504,8 +1504,7 @@ libvirt_virConnectOpenAuth(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { auth.ncredtype = PyList_Size(pycredtype); if (auth.ncredtype) { int i; - auth.credtype = malloc(sizeof(*auth.credtype) * auth.ncredtype); - if (auth.credtype == NULL) + if (VIR_ALLOC_N(auth.credtype, auth.ncredtype) < 0) return VIR_PY_NONE; for (i = 0 ; i < auth.ncredtype ; i++) { PyObject *val; @@ -1520,7 +1519,7 @@ libvirt_virConnectOpenAuth(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { c_retval = virConnectOpenAuth(name, &auth, flags); LIBVIRT_END_ALLOW_THREADS; - free(auth.credtype); + VIR_FREE(auth.credtype); py_retval = libvirt_virConnectPtrWrap((virConnectPtr) c_retval); return(py_retval); } @@ -1632,15 +1631,14 @@ libvirt_virConnectListDomainsID(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - ids = malloc(sizeof(*ids) * c_retval); - if (!ids) + if (VIR_ALLOC_N(ids, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virConnectListDomains(conn, ids, c_retval); LIBVIRT_END_ALLOW_THREADS; if (c_retval < 0) { - free(ids); + VIR_FREE(ids); return VIR_PY_NONE; } } @@ -1650,7 +1648,7 @@ libvirt_virConnectListDomainsID(PyObject *self ATTRIBUTE_UNUSED, for (i = 0;i < c_retval;i++) { PyList_SetItem(py_retval, i, libvirt_intWrap(ids[i])); } - free(ids); + VIR_FREE(ids); } return(py_retval); @@ -1677,14 +1675,13 @@ libvirt_virConnectListDefinedDomains(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - names = malloc(sizeof(*names) * c_retval); - if (!names) + if (VIR_ALLOC_N(names, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virConnectListDefinedDomains(conn, names, c_retval); LIBVIRT_END_ALLOW_THREADS; if (c_retval < 0) { - free(names); + VIR_FREE(names); return VIR_PY_NONE; } } @@ -1693,9 +1690,9 @@ libvirt_virConnectListDefinedDomains(PyObject *self ATTRIBUTE_UNUSED, if (names) { for (i = 0;i < c_retval;i++) { PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i])); - free(names[i]); + VIR_FREE(names[i]); } - free(names); + VIR_FREE(names); } return(py_retval); @@ -1722,14 +1719,13 @@ libvirt_virDomainSnapshotListNames(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - names = malloc(sizeof(*names) * c_retval); - if (!names) + if (VIR_ALLOC_N(names, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virDomainSnapshotListNames(dom, names, c_retval, flags); LIBVIRT_END_ALLOW_THREADS; if (c_retval < 0) { - free(names); + VIR_FREE(names); return VIR_PY_NONE; } } @@ -1738,9 +1734,9 @@ libvirt_virDomainSnapshotListNames(PyObject *self ATTRIBUTE_UNUSED, if (names) { for (i = 0;i < c_retval;i++) { PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i])); - free(names[i]); + VIR_FREE(names[i]); } - free(names); + VIR_FREE(names); } return(py_retval); @@ -1767,14 +1763,13 @@ libvirt_virDomainSnapshotListChildrenNames(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - names = malloc(sizeof(*names) * c_retval); - if (!names) + if (VIR_ALLOC_N(names, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virDomainSnapshotListChildrenNames(snap, names, c_retval, flags); LIBVIRT_END_ALLOW_THREADS; if (c_retval < 0) { - free(names); + VIR_FREE(names); return VIR_PY_NONE; } } @@ -1783,9 +1778,9 @@ libvirt_virDomainSnapshotListChildrenNames(PyObject *self ATTRIBUTE_UNUSED, if (names) { for (i = 0;i < c_retval;i++) { PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i])); - free(names[i]); + VIR_FREE(names[i]); } - free(names); + VIR_FREE(names); } return(py_retval); @@ -2047,14 +2042,13 @@ libvirt_virConnectListNetworks(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - names = malloc(sizeof(*names) * c_retval); - if (!names) + if (VIR_ALLOC_N(names, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virConnectListNetworks(conn, names, c_retval); LIBVIRT_END_ALLOW_THREADS; if (c_retval < 0) { - free(names); + VIR_FREE(names); return VIR_PY_NONE; } } @@ -2063,9 +2057,9 @@ libvirt_virConnectListNetworks(PyObject *self ATTRIBUTE_UNUSED, if (names) { for (i = 0;i < c_retval;i++) { PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i])); - free(names[i]); + VIR_FREE(names[i]); } - free(names); + VIR_FREE(names); } return(py_retval); @@ -2093,14 +2087,13 @@ libvirt_virConnectListDefinedNetworks(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - names = malloc(sizeof(*names) * c_retval); - if (!names) + if (VIR_ALLOC_N(names, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virConnectListDefinedNetworks(conn, names, c_retval); LIBVIRT_END_ALLOW_THREADS; if (c_retval < 0) { - free(names); + VIR_FREE(names); return VIR_PY_NONE; } } @@ -2109,9 +2102,9 @@ libvirt_virConnectListDefinedNetworks(PyObject *self ATTRIBUTE_UNUSED, if (names) { for (i = 0;i < c_retval;i++) { PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i])); - free(names[i]); + VIR_FREE(names[i]); } - free(names); + VIR_FREE(names); } return(py_retval); @@ -2255,8 +2248,7 @@ libvirt_virNodeGetCellsFreeMemory(PyObject *self ATTRIBUTE_UNUSED, PyObject *arg return VIR_PY_NONE; conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn); - freeMems = malloc(maxCells * sizeof(*freeMems)); - if (freeMems == NULL) + if (VIR_ALLOC_N(freeMems, maxCells) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; @@ -2264,7 +2256,7 @@ libvirt_virNodeGetCellsFreeMemory(PyObject *self ATTRIBUTE_UNUSED, PyObject *arg LIBVIRT_END_ALLOW_THREADS; if (c_retval < 0) { - free(freeMems); + VIR_FREE(freeMems); return VIR_PY_NONE; } py_retval = PyList_New(c_retval); @@ -2272,7 +2264,7 @@ libvirt_virNodeGetCellsFreeMemory(PyObject *self ATTRIBUTE_UNUSED, PyObject *arg PyList_SetItem(py_retval, i, libvirt_longlongWrap((long long) freeMems[i])); } - free(freeMems); + VIR_FREE(freeMems); return(py_retval); } @@ -2298,19 +2290,19 @@ libvirt_virNodeGetCPUStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) return VIR_PY_NONE; if (nparams) { - if (!(stats = malloc(sizeof(*stats) * nparams))) + if (VIR_ALLOC_N(stats, nparams) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virNodeGetCPUStats(conn, cpuNum, stats, &nparams, flags); LIBVIRT_END_ALLOW_THREADS; if (c_retval < 0) { - free(stats); + VIR_FREE(stats); return VIR_PY_NONE; } } if (!(ret = PyDict_New())) { - free(stats); + VIR_FREE(stats); return VIR_PY_NONE; } for (i = 0; i < nparams; i++) { @@ -2319,7 +2311,7 @@ libvirt_virNodeGetCPUStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) libvirt_ulonglongWrap(stats[i].value)); } - free(stats); + VIR_FREE(stats); return ret; } @@ -2345,19 +2337,19 @@ libvirt_virNodeGetMemoryStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) return VIR_PY_NONE; if (nparams) { - if (!(stats = malloc(sizeof(*stats) * nparams))) + if (VIR_ALLOC_N(stats, nparams) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virNodeGetMemoryStats(conn, cellNum, stats, &nparams, flags); LIBVIRT_END_ALLOW_THREADS; if (c_retval < 0) { - free(stats); + VIR_FREE(stats); return VIR_PY_NONE; } } if (!(ret = PyDict_New())) { - free(stats); + VIR_FREE(stats); return VIR_PY_NONE; } for (i = 0; i < nparams; i++) { @@ -2366,7 +2358,7 @@ libvirt_virNodeGetMemoryStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) libvirt_ulonglongWrap(stats[i].value)); } - free(stats); + VIR_FREE(stats); return ret; } @@ -2391,14 +2383,13 @@ libvirt_virConnectListStoragePools(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - names = malloc(sizeof(*names) * c_retval); - if (!names) + if (VIR_ALLOC_N(names, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virConnectListStoragePools(conn, names, c_retval); LIBVIRT_END_ALLOW_THREADS; if (c_retval < 0) { - free(names); + VIR_FREE(names); return VIR_PY_NONE; } } @@ -2406,8 +2397,8 @@ libvirt_virConnectListStoragePools(PyObject *self ATTRIBUTE_UNUSED, if (py_retval == NULL) { if (names) { for (i = 0;i < c_retval;i++) - free(names[i]); - free(names); + VIR_FREE(names[i]); + VIR_FREE(names); } return VIR_PY_NONE; } @@ -2415,9 +2406,9 @@ libvirt_virConnectListStoragePools(PyObject *self ATTRIBUTE_UNUSED, if (names) { for (i = 0;i < c_retval;i++) { PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i])); - free(names[i]); + VIR_FREE(names[i]); } - free(names); + VIR_FREE(names); } return(py_retval); @@ -2445,14 +2436,13 @@ libvirt_virConnectListDefinedStoragePools(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - names = malloc(sizeof(*names) * c_retval); - if (!names) + if (VIR_ALLOC_N(names, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virConnectListDefinedStoragePools(conn, names, c_retval); LIBVIRT_END_ALLOW_THREADS; if (c_retval < 0) { - free(names); + VIR_FREE(names); return VIR_PY_NONE; } } @@ -2460,8 +2450,8 @@ libvirt_virConnectListDefinedStoragePools(PyObject *self ATTRIBUTE_UNUSED, if (py_retval == NULL) { if (names) { for (i = 0;i < c_retval;i++) - free(names[i]); - free(names); + VIR_FREE(names[i]); + VIR_FREE(names); } return VIR_PY_NONE; } @@ -2469,9 +2459,9 @@ libvirt_virConnectListDefinedStoragePools(PyObject *self ATTRIBUTE_UNUSED, if (names) { for (i = 0;i < c_retval;i++) { PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i])); - free(names[i]); + VIR_FREE(names[i]); } - free(names); + VIR_FREE(names); } return(py_retval); @@ -2499,14 +2489,13 @@ libvirt_virStoragePoolListVolumes(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - names = malloc(sizeof(*names) * c_retval); - if (!names) + if (VIR_ALLOC_N(names, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virStoragePoolListVolumes(pool, names, c_retval); LIBVIRT_END_ALLOW_THREADS; if (c_retval < 0) { - free(names); + VIR_FREE(names); return VIR_PY_NONE; } } @@ -2514,8 +2503,8 @@ libvirt_virStoragePoolListVolumes(PyObject *self ATTRIBUTE_UNUSED, if (py_retval == NULL) { if (names) { for (i = 0;i < c_retval;i++) - free(names[i]); - free(names); + VIR_FREE(names[i]); + VIR_FREE(names); } return VIR_PY_NONE; } @@ -2523,9 +2512,9 @@ libvirt_virStoragePoolListVolumes(PyObject *self ATTRIBUTE_UNUSED, if (names) { for (i = 0;i < c_retval;i++) { PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i])); - free(names[i]); + VIR_FREE(names[i]); } - free(names); + VIR_FREE(names); } return(py_retval); @@ -2712,14 +2701,13 @@ libvirt_virNodeListDevices(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - names = malloc(sizeof(*names) * c_retval); - if (!names) + if (VIR_ALLOC_N(names, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virNodeListDevices(conn, cap, names, c_retval, flags); LIBVIRT_END_ALLOW_THREADS; if (c_retval < 0) { - free(names); + VIR_FREE(names); return VIR_PY_NONE; } } @@ -2728,9 +2716,9 @@ libvirt_virNodeListDevices(PyObject *self ATTRIBUTE_UNUSED, if (names) { for (i = 0;i < c_retval;i++) { PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i])); - free(names[i]); + VIR_FREE(names[i]); } - free(names); + VIR_FREE(names); } return(py_retval); @@ -2756,14 +2744,13 @@ libvirt_virNodeDeviceListCaps(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - names = malloc(sizeof(*names) * c_retval); - if (!names) + if (VIR_ALLOC_N(names, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virNodeDeviceListCaps(dev, names, c_retval); LIBVIRT_END_ALLOW_THREADS; if (c_retval < 0) { - free(names); + VIR_FREE(names); return VIR_PY_NONE; } } @@ -2772,9 +2759,9 @@ libvirt_virNodeDeviceListCaps(PyObject *self ATTRIBUTE_UNUSED, if (names) { for (i = 0;i < c_retval;i++) { PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i])); - free(names[i]); + VIR_FREE(names[i]); } - free(names); + VIR_FREE(names); } return(py_retval); @@ -2876,14 +2863,13 @@ libvirt_virConnectListSecrets(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - uuids = malloc(sizeof(*uuids) * c_retval); - if (!uuids) + if (VIR_ALLOC_N(uuids, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virConnectListSecrets(conn, uuids, c_retval); LIBVIRT_END_ALLOW_THREADS; if (c_retval < 0) { - free(uuids); + VIR_FREE(uuids); return VIR_PY_NONE; } } @@ -2892,9 +2878,9 @@ libvirt_virConnectListSecrets(PyObject *self ATTRIBUTE_UNUSED, if (uuids) { for (i = 0;i < c_retval;i++) { PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(uuids[i])); - free(uuids[i]); + VIR_FREE(uuids[i]); } - free(uuids); + VIR_FREE(uuids); } return py_retval; @@ -2923,8 +2909,7 @@ libvirt_virSecretGetValue(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; py_retval = PyString_FromStringAndSize((const char *)c_retval, size); - memset(c_retval, 0, size); - free(c_retval); + VIR_FREE(c_retval); return py_retval; } @@ -3050,14 +3035,13 @@ libvirt_virConnectListNWFilters(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - uuids = malloc(sizeof(*uuids) * c_retval); - if (!uuids) + if (VIR_ALLOC_N(uuids, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virConnectListNWFilters(conn, uuids, c_retval); LIBVIRT_END_ALLOW_THREADS; if (c_retval < 0) { - free(uuids); + VIR_FREE(uuids); return VIR_PY_NONE; } } @@ -3066,9 +3050,9 @@ libvirt_virConnectListNWFilters(PyObject *self ATTRIBUTE_UNUSED, if (uuids) { for (i = 0;i < c_retval;i++) { PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(uuids[i])); - free(uuids[i]); + VIR_FREE(uuids[i]); } - free(uuids); + VIR_FREE(uuids); } return py_retval; @@ -3095,14 +3079,13 @@ libvirt_virConnectListInterfaces(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - names = malloc(sizeof(*names) * c_retval); - if (!names) + if (VIR_ALLOC_N(names, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virConnectListInterfaces(conn, names, c_retval); LIBVIRT_END_ALLOW_THREADS; if (c_retval < 0) { - free(names); + VIR_FREE(names); return VIR_PY_NONE; } } @@ -3110,8 +3093,8 @@ libvirt_virConnectListInterfaces(PyObject *self ATTRIBUTE_UNUSED, if (py_retval == NULL) { if (names) { for (i = 0;i < c_retval;i++) - free(names[i]); - free(names); + VIR_FREE(names[i]); + VIR_FREE(names); } return VIR_PY_NONE; } @@ -3119,9 +3102,9 @@ libvirt_virConnectListInterfaces(PyObject *self ATTRIBUTE_UNUSED, if (names) { for (i = 0;i < c_retval;i++) { PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i])); - free(names[i]); + VIR_FREE(names[i]); } - free(names); + VIR_FREE(names); } return(py_retval); @@ -3150,14 +3133,13 @@ libvirt_virConnectListDefinedInterfaces(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - names = malloc(sizeof(*names) * c_retval); - if (!names) + if (VIR_ALLOC_N(names, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virConnectListDefinedInterfaces(conn, names, c_retval); LIBVIRT_END_ALLOW_THREADS; if (c_retval < 0) { - free(names); + VIR_FREE(names); return VIR_PY_NONE; } } @@ -3165,8 +3147,8 @@ libvirt_virConnectListDefinedInterfaces(PyObject *self ATTRIBUTE_UNUSED, if (py_retval == NULL) { if (names) { for (i = 0;i < c_retval;i++) - free(names[i]); - free(names); + VIR_FREE(names[i]); + VIR_FREE(names); } return VIR_PY_NONE; } @@ -3174,9 +3156,9 @@ libvirt_virConnectListDefinedInterfaces(PyObject *self ATTRIBUTE_UNUSED, if (names) { for (i = 0;i < c_retval;i++) { PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i])); - free(names[i]); + VIR_FREE(names[i]); } - free(names); + VIR_FREE(names); } return(py_retval); @@ -3204,13 +3186,13 @@ libvirt_virConnectBaselineCPU(PyObject *self ATTRIBUTE_UNUSED, int i; ncpus = PyList_Size(list); - if ((xmlcpus = malloc(ncpus * sizeof(*xmlcpus))) == NULL) + if (VIR_ALLOC_N(xmlcpus, ncpus) < 0) return VIR_PY_INT_FAIL; for (i = 0; i < ncpus; i++) { xmlcpus[i] = PyString_AsString(PyList_GetItem(list, i)); if (xmlcpus[i] == NULL) { - free(xmlcpus); + VIR_FREE(xmlcpus); return VIR_PY_INT_FAIL; } } @@ -3220,13 +3202,13 @@ libvirt_virConnectBaselineCPU(PyObject *self ATTRIBUTE_UNUSED, base_cpu = virConnectBaselineCPU(conn, xmlcpus, ncpus, flags); LIBVIRT_END_ALLOW_THREADS; - free(xmlcpus); + VIR_FREE(xmlcpus); if (base_cpu == NULL) return VIR_PY_INT_FAIL; pybase_cpu = PyString_FromString(base_cpu); - free(base_cpu); + VIR_FREE(base_cpu); if (pybase_cpu == NULL) return VIR_PY_INT_FAIL; @@ -3332,7 +3314,7 @@ libvirt_virDomainSetBlockIoTune(PyObject *self ATTRIBUTE_UNUSED, if (c_ret < 0) return VIR_PY_INT_FAIL; - if ((params = malloc(sizeof(*params)*nparams)) == NULL) + if (VIR_ALLOC_N(params, nparams) < 0) return VIR_PY_INT_FAIL; LIBVIRT_BEGIN_ALLOW_THREADS; @@ -3340,7 +3322,7 @@ libvirt_virDomainSetBlockIoTune(PyObject *self ATTRIBUTE_UNUSED, LIBVIRT_END_ALLOW_THREADS; if (c_ret < 0) { - free(params); + VIR_FREE(params); return VIR_PY_INT_FAIL; } @@ -3384,7 +3366,7 @@ libvirt_virDomainSetBlockIoTune(PyObject *self ATTRIBUTE_UNUSED, break; default: - free(params); + VIR_FREE(params); return VIR_PY_INT_FAIL; } } @@ -3394,11 +3376,11 @@ libvirt_virDomainSetBlockIoTune(PyObject *self ATTRIBUTE_UNUSED, LIBVIRT_END_ALLOW_THREADS; if (c_ret < 0) { - free(params); + VIR_FREE(params); return VIR_PY_INT_FAIL; } - free(params); + VIR_FREE(params); return VIR_PY_INT_SUCCESS; } @@ -3426,7 +3408,7 @@ libvirt_virDomainGetBlockIoTune(PyObject *self ATTRIBUTE_UNUSED, if (c_ret < 0) return VIR_PY_NONE; - if ((params = malloc(sizeof(*params)*nparams)) == NULL) + if (VIR_ALLOC_N(params, nparams) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; @@ -3434,13 +3416,13 @@ libvirt_virDomainGetBlockIoTune(PyObject *self ATTRIBUTE_UNUSED, LIBVIRT_END_ALLOW_THREADS; if (c_ret < 0) { - free(params); + VIR_FREE(params); return VIR_PY_NONE; } /* convert to a Python tuple of long objects */ if ((pyreply = PyDict_New()) == NULL) { - free(params); + VIR_FREE(params); return VIR_PY_NONE; } for (i = 0 ; i < nparams ; i++) { @@ -3472,7 +3454,7 @@ libvirt_virDomainGetBlockIoTune(PyObject *self ATTRIBUTE_UNUSED, break; default: - free(params); + VIR_FREE(params); Py_DECREF(pyreply); return VIR_PY_NONE; } @@ -3480,7 +3462,7 @@ libvirt_virDomainGetBlockIoTune(PyObject *self ATTRIBUTE_UNUSED, key = libvirt_constcharPtrWrap(params[i].field); PyDict_SetItem(pyreply, key, val); } - free(params); + VIR_FREE(params); return(pyreply); } @@ -3508,7 +3490,7 @@ libvirt_virDomainGetDiskErrors(PyObject *self ATTRIBUTE_UNUSED, ndisks = count; if (ndisks) { - if (!(disks = malloc(sizeof(*disks) * ndisks))) + if (VIR_ALLOC_N(disks, ndisks) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; @@ -3531,8 +3513,8 @@ libvirt_virDomainGetDiskErrors(PyObject *self ATTRIBUTE_UNUSED, cleanup: if (disks) { for (i = 0; i < count; i++) - free(disks[i].disk); - free(disks); + VIR_FREE(disks[i].disk); + VIR_FREE(disks); } return py_retval; } @@ -4974,7 +4956,7 @@ libvirt_virStreamRecv(PyObject *self ATTRIBUTE_UNUSED, } stream = PyvirStream_Get(pyobj_stream); - if ((buf = malloc(nbytes+1 > 0 ? nbytes+1 : 1)) == NULL) + if (VIR_ALLOC_N(buf, nbytes+1 > 0 ? nbytes+1 : 1) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; @@ -5109,7 +5091,7 @@ libvirt_virDomainBlockPeek(PyObject *self ATTRIBUTE_UNUSED, domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain); - if ((buf = malloc(size)) == NULL) + if (VIR_ALLOC_N(buf, size) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; @@ -5122,7 +5104,7 @@ libvirt_virDomainBlockPeek(PyObject *self ATTRIBUTE_UNUSED, py_retval = PyString_FromStringAndSize(buf, size); cleanup: - free(buf); + VIR_FREE(buf); return py_retval; } @@ -5144,7 +5126,7 @@ libvirt_virDomainMemoryPeek(PyObject *self ATTRIBUTE_UNUSED, domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain); - if ((buf = malloc(size)) == NULL) + if (VIR_ALLOC_N(buf, size) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; @@ -5157,7 +5139,7 @@ libvirt_virDomainMemoryPeek(PyObject *self ATTRIBUTE_UNUSED, py_retval = PyString_FromStringAndSize(buf, size); cleanup: - free(buf); + VIR_FREE(buf); return py_retval; } diff --git a/python/typewrappers.c b/python/typewrappers.c index 9021ce3..3f200b3 100644 --- a/python/typewrappers.c +++ b/python/typewrappers.c @@ -2,7 +2,7 @@ * types.c: converter functions between the internal representation * and the Python objects * - * Copyright (C) 2005, 2007 Red Hat, Inc. + * Copyright (C) 2005, 2007, 2012 Red Hat, Inc. * * Daniel Veillard <veillard@redhat.com> */ @@ -16,6 +16,8 @@ #include "typewrappers.h" +#include "memory.h" + #ifndef Py_CAPSULE_H typedef void(*PyCapsule_Destructor)(void *, void *); #endif @@ -86,7 +88,7 @@ libvirt_charPtrSizeWrap(char *str, Py_ssize_t size) return (Py_None); } ret = PyString_FromStringAndSize(str, size); - free(str); + VIR_FREE(str); return (ret); } @@ -100,7 +102,7 @@ libvirt_charPtrWrap(char *str) return (Py_None); } ret = PyString_FromString(str); - free(str); + VIR_FREE(str); return (ret); } -- 1.7.7.6

On Thu, Feb 02, 2012 at 17:33:24 -0700, Eric Blake wrote:
This patch starts the process of elevating the python binding code to be on the same level as the rest of libvirt when it comes to requiring good coding styles. Statically linking against the libvirt_util library makes it much easier to write good code, rather than having to open-code and reinvent things locally.
Done by global search and replace of s/free(/VIR_FREE(/, followed by hand-inspection of remaining malloc and redundant memset.
* cfg.mk (exclude_file_name_regexp--sc_prohibit_raw_allocation): Remove python from exemption. * python/Makefile.am (INCLUDES): Add gnulib and src/util. Drop $(top_builddir)/$(subdir), as automake already guarantees that. (mylibs, myqemulibs): Pull in libvirt_util and gnulib. (libvirtmod_la_CFLAGS): Catch compiler warnings if configured to use -Werror. * python/typewrappers.c (libvirt_charPtrSizeWrap) (libvirt_charPtrWrap): Convert free to VIR_FREE. * python/generator.py (print_function_wrapper): Likewise. * python/libvirt-override.c: Likewise. --- cfg.mk | 2 +- python/Makefile.am | 18 ++- python/generator.py | 2 +- python/libvirt-override.c | 364 +++++++++++++++++++++------------------------ python/typewrappers.c | 8 +- 5 files changed, 194 insertions(+), 200 deletions(-)
ACK Jirka

On 02/03/2012 02:12 AM, Jiri Denemark wrote:
On Thu, Feb 02, 2012 at 17:33:24 -0700, Eric Blake wrote:
This patch starts the process of elevating the python binding code to be on the same level as the rest of libvirt when it comes to requiring good coding styles. Statically linking against the libvirt_util library makes it much easier to write good code, rather than having to open-code and reinvent things locally.
Done by global search and replace of s/free(/VIR_FREE(/, followed by hand-inspection of remaining malloc and redundant memset.
* cfg.mk (exclude_file_name_regexp--sc_prohibit_raw_allocation): Remove python from exemption. * python/Makefile.am (INCLUDES): Add gnulib and src/util. Drop $(top_builddir)/$(subdir), as automake already guarantees that. (mylibs, myqemulibs): Pull in libvirt_util and gnulib. (libvirtmod_la_CFLAGS): Catch compiler warnings if configured to use -Werror. * python/typewrappers.c (libvirt_charPtrSizeWrap) (libvirt_charPtrWrap): Convert free to VIR_FREE. * python/generator.py (print_function_wrapper): Likewise. * python/libvirt-override.c: Likewise. --- cfg.mk | 2 +- python/Makefile.am | 18 ++- python/generator.py | 2 +- python/libvirt-override.c | 364 +++++++++++++++++++++------------------------ python/typewrappers.c | 8 +- 5 files changed, 194 insertions(+), 200 deletions(-)
ACK
Series pushed. -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
participants (2)
-
Eric Blake
-
Jiri Denemark