mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-17 01:55:17 +00:00
python: fix snapshot listing bugs
Python exceptions are different than libvirt errors, and we had some corner case bugs on OOM situations. * python/libvirt-override.c (libvirt_virDomainSnapshotListNames) (libvirt_virDomainSnapshotListChildrenNames): Use correct error returns, avoid segv on OOM, and avoid memory leaks on error. (cherry picked from commit a0de5d78ef593958bcb83e563fe54137fe43c4ff)
This commit is contained in:
parent
a570ecd600
commit
934e7c2217
@ -2025,15 +2025,18 @@ libvirt_virConnectListDefinedDomains(PyObject *self ATTRIBUTE_UNUSED,
|
|||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
libvirt_virDomainSnapshotListNames(PyObject *self ATTRIBUTE_UNUSED,
|
libvirt_virDomainSnapshotListNames(PyObject *self ATTRIBUTE_UNUSED,
|
||||||
PyObject *args) {
|
PyObject *args)
|
||||||
|
{
|
||||||
PyObject *py_retval;
|
PyObject *py_retval;
|
||||||
char **names = NULL;
|
char **names = NULL;
|
||||||
int c_retval, i;
|
int c_retval, i;
|
||||||
virDomainPtr dom;
|
virDomainPtr dom;
|
||||||
PyObject *pyobj_dom;
|
PyObject *pyobj_dom;
|
||||||
|
PyObject *pyobj_snap;
|
||||||
unsigned int flags;
|
unsigned int flags;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainSnapshotListNames", &pyobj_dom, &flags))
|
if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainSnapshotListNames",
|
||||||
|
&pyobj_dom, &flags))
|
||||||
return NULL;
|
return NULL;
|
||||||
dom = (virDomainPtr) PyvirDomain_Get(pyobj_dom);
|
dom = (virDomainPtr) PyvirDomain_Get(pyobj_dom);
|
||||||
|
|
||||||
@ -2045,7 +2048,7 @@ libvirt_virDomainSnapshotListNames(PyObject *self ATTRIBUTE_UNUSED,
|
|||||||
|
|
||||||
if (c_retval) {
|
if (c_retval) {
|
||||||
if (VIR_ALLOC_N(names, c_retval) < 0)
|
if (VIR_ALLOC_N(names, c_retval) < 0)
|
||||||
return VIR_PY_NONE;
|
return PyErr_NoMemory();
|
||||||
LIBVIRT_BEGIN_ALLOW_THREADS;
|
LIBVIRT_BEGIN_ALLOW_THREADS;
|
||||||
c_retval = virDomainSnapshotListNames(dom, names, c_retval, flags);
|
c_retval = virDomainSnapshotListNames(dom, names, c_retval, flags);
|
||||||
LIBVIRT_END_ALLOW_THREADS;
|
LIBVIRT_END_ALLOW_THREADS;
|
||||||
@ -2055,21 +2058,31 @@ libvirt_virDomainSnapshotListNames(PyObject *self ATTRIBUTE_UNUSED,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
py_retval = PyList_New(c_retval);
|
py_retval = PyList_New(c_retval);
|
||||||
|
if (!py_retval)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
if (names) {
|
for (i = 0; i < c_retval; i++) {
|
||||||
for (i = 0;i < c_retval;i++) {
|
if ((pyobj_snap = libvirt_constcharPtrWrap(names[i])) == NULL ||
|
||||||
PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i]));
|
PyList_SetItem(py_retval, i, pyobj_snap) < 0) {
|
||||||
|
Py_XDECREF(pyobj_snap);
|
||||||
|
Py_DECREF(py_retval);
|
||||||
|
py_retval = NULL;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
VIR_FREE(names[i]);
|
VIR_FREE(names[i]);
|
||||||
}
|
}
|
||||||
VIR_FREE(names);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
for (i = 0; i < c_retval; i++)
|
||||||
|
VIR_FREE(names[i]);
|
||||||
|
VIR_FREE(names);
|
||||||
return py_retval;
|
return py_retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
libvirt_virDomainSnapshotListChildrenNames(PyObject *self ATTRIBUTE_UNUSED,
|
libvirt_virDomainSnapshotListChildrenNames(PyObject *self ATTRIBUTE_UNUSED,
|
||||||
PyObject *args) {
|
PyObject *args)
|
||||||
|
{
|
||||||
PyObject *py_retval;
|
PyObject *py_retval;
|
||||||
char **names = NULL;
|
char **names = NULL;
|
||||||
int c_retval, i;
|
int c_retval, i;
|
||||||
@ -2077,7 +2090,8 @@ libvirt_virDomainSnapshotListChildrenNames(PyObject *self ATTRIBUTE_UNUSED,
|
|||||||
PyObject *pyobj_snap;
|
PyObject *pyobj_snap;
|
||||||
unsigned int flags;
|
unsigned int flags;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainSnapshotListChildrenNames", &pyobj_snap, &flags))
|
if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainSnapshotListChildrenNames",
|
||||||
|
&pyobj_snap, &flags))
|
||||||
return NULL;
|
return NULL;
|
||||||
snap = (virDomainSnapshotPtr) PyvirDomainSnapshot_Get(pyobj_snap);
|
snap = (virDomainSnapshotPtr) PyvirDomainSnapshot_Get(pyobj_snap);
|
||||||
|
|
||||||
@ -2089,9 +2103,10 @@ libvirt_virDomainSnapshotListChildrenNames(PyObject *self ATTRIBUTE_UNUSED,
|
|||||||
|
|
||||||
if (c_retval) {
|
if (c_retval) {
|
||||||
if (VIR_ALLOC_N(names, c_retval) < 0)
|
if (VIR_ALLOC_N(names, c_retval) < 0)
|
||||||
return VIR_PY_NONE;
|
return PyErr_NoMemory();
|
||||||
LIBVIRT_BEGIN_ALLOW_THREADS;
|
LIBVIRT_BEGIN_ALLOW_THREADS;
|
||||||
c_retval = virDomainSnapshotListChildrenNames(snap, names, c_retval, flags);
|
c_retval = virDomainSnapshotListChildrenNames(snap, names, c_retval,
|
||||||
|
flags);
|
||||||
LIBVIRT_END_ALLOW_THREADS;
|
LIBVIRT_END_ALLOW_THREADS;
|
||||||
if (c_retval < 0) {
|
if (c_retval < 0) {
|
||||||
VIR_FREE(names);
|
VIR_FREE(names);
|
||||||
@ -2100,14 +2115,21 @@ libvirt_virDomainSnapshotListChildrenNames(PyObject *self ATTRIBUTE_UNUSED,
|
|||||||
}
|
}
|
||||||
py_retval = PyList_New(c_retval);
|
py_retval = PyList_New(c_retval);
|
||||||
|
|
||||||
if (names) {
|
for (i = 0; i < c_retval; i++) {
|
||||||
for (i = 0;i < c_retval;i++) {
|
if ((pyobj_snap = libvirt_constcharPtrWrap(names[i])) == NULL ||
|
||||||
PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i]));
|
PyList_SetItem(py_retval, i, pyobj_snap) < 0) {
|
||||||
|
Py_XDECREF(pyobj_snap);
|
||||||
|
Py_DECREF(py_retval);
|
||||||
|
py_retval = NULL;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
VIR_FREE(names[i]);
|
VIR_FREE(names[i]);
|
||||||
}
|
}
|
||||||
VIR_FREE(names);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
for (i = 0; i < c_retval; i++)
|
||||||
|
VIR_FREE(names[i]);
|
||||||
|
VIR_FREE(names);
|
||||||
return py_retval;
|
return py_retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user