summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile.am18
-rwxr-xr-xgenerator.py2
-rw-r--r--libvirt-override.c364
-rw-r--r--typewrappers.c8
4 files changed, 193 insertions, 199 deletions
diff --git a/Makefile.am b/Makefile.am
index 81b160a..9b791d7 100644
--- a/Makefile.am
+++ b/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/generator.py b/generator.py
index 0728519..98072f0 100755
--- a/generator.py
+++ b/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/libvirt-override.c b/libvirt-override.c
index 18849f8..68e0b55 100644
--- a/libvirt-override.c
+++ b/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/typewrappers.c b/typewrappers.c
index 9021ce3..3f200b3 100644
--- a/typewrappers.c
+++ b/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);
}