Signed-off-by: Pavel Hrdina <phrdina@xxxxxxxxxx> --- libvirt-override.c | 69 ++++++++++++++++++------------------------------------ 1 file changed, 23 insertions(+), 46 deletions(-) diff --git a/libvirt-override.c b/libvirt-override.c index 4d0fb92..0df6844 100644 --- a/libvirt-override.c +++ b/libvirt-override.c @@ -405,14 +405,11 @@ libvirt_virDomainMemoryStats(PyObject *self ATTRIBUTE_UNUSED, val = libvirt_ulonglongWrap(stats[i].val); if (!key || !val || PyDict_SetItem(info, key, val) < 0) { - Py_DECREF(info); - info = NULL; + Py_CLEAR(info); goto cleanup; } - Py_DECREF(key); - Py_DECREF(val); - key = NULL; - val = NULL; + Py_CLEAR(key); + Py_CLEAR(val); } cleanup: @@ -2174,8 +2171,7 @@ libvirt_virConnectGetCPUModelNames(PyObject *self ATTRIBUTE_UNUSED, return rv; error: - Py_XDECREF(rv); - rv = NULL; + Py_CLEAR(rv); goto done; } #endif /* LIBVIR_CHECK_VERSION(1, 1, 3) */ @@ -2283,8 +2279,7 @@ libvirt_virConnectListAllDomains(PyObject *self ATTRIBUTE_UNUSED, if (!(tmp = libvirt_virDomainPtrWrap(doms[i])) || PyList_SetItem(py_retval, i, tmp) < 0) { Py_XDECREF(tmp); - Py_DECREF(py_retval); - py_retval = NULL; + Py_CLEAR(py_retval); goto cleanup; } /* python steals the pointer */ @@ -2390,8 +2385,7 @@ libvirt_virDomainSnapshotListNames(PyObject *self ATTRIBUTE_UNUSED, if ((pyobj_snap = libvirt_constcharPtrWrap(names[i])) == NULL || PyList_SetItem(py_retval, i, pyobj_snap) < 0) { Py_XDECREF(pyobj_snap); - Py_DECREF(py_retval); - py_retval = NULL; + Py_CLEAR(py_retval); goto cleanup; } VIR_FREE(names[i]); @@ -2436,8 +2430,7 @@ libvirt_virDomainListAllSnapshots(PyObject *self ATTRIBUTE_UNUSED, if ((pyobj_snap = libvirt_virDomainSnapshotPtrWrap(snaps[i])) == NULL || PyList_SetItem(py_retval, i, pyobj_snap) < 0) { Py_XDECREF(pyobj_snap); - Py_DECREF(py_retval); - py_retval = NULL; + Py_CLEAR(py_retval); goto cleanup; } snaps[i] = NULL; @@ -2493,8 +2486,7 @@ libvirt_virDomainSnapshotListChildrenNames(PyObject *self ATTRIBUTE_UNUSED, if ((pyobj_snap = libvirt_constcharPtrWrap(names[i])) == NULL || PyList_SetItem(py_retval, i, pyobj_snap) < 0) { Py_XDECREF(pyobj_snap); - Py_DECREF(py_retval); - py_retval = NULL; + Py_CLEAR(py_retval); goto cleanup; } VIR_FREE(names[i]); @@ -2539,8 +2531,7 @@ libvirt_virDomainSnapshotListAllChildren(PyObject *self ATTRIBUTE_UNUSED, if ((pyobj_snap = libvirt_virDomainSnapshotPtrWrap(snaps[i])) == NULL || PyList_SetItem(py_retval, i, pyobj_snap) < 0) { Py_XDECREF(pyobj_snap); - Py_DECREF(py_retval); - py_retval = NULL; + Py_CLEAR(py_retval); goto cleanup; } snaps[i] = NULL; @@ -2834,8 +2825,7 @@ libvirt_virDomainGetSecurityLabelList(PyObject *self ATTRIBUTE_UNUSED, return py_retval; error: - Py_XDECREF(py_retval); - py_retval = NULL; + Py_CLEAR(py_retval); goto cleanup; } #endif /* LIBVIR_CHECK_VERSION(0, 10, 0) */ @@ -3049,8 +3039,7 @@ libvirt_virConnectListAllNetworks(PyObject *self ATTRIBUTE_UNUSED, if (!(tmp = libvirt_virNetworkPtrWrap(nets[i])) || PyList_SetItem(py_retval, i, tmp) < 0) { Py_XDECREF(tmp); - Py_DECREF(py_retval); - py_retval = NULL; + Py_CLEAR(py_retval); goto cleanup; } /* python steals the pointer */ @@ -3286,8 +3275,7 @@ libvirt_virNodeGetCPUStats(PyObject *self ATTRIBUTE_UNUSED, val = libvirt_ulonglongWrap(stats[i].value); if (!key || !val || PyDict_SetItem(ret, key, val) < 0) { - Py_DECREF(ret); - ret = NULL; + Py_CLEAR(ret); goto error; } @@ -3352,8 +3340,7 @@ libvirt_virNodeGetMemoryStats(PyObject *self ATTRIBUTE_UNUSED, val = libvirt_ulonglongWrap(stats[i].value); if (!key || !val || PyDict_SetItem(ret, key, val) < 0) { - Py_DECREF(ret); - ret = NULL; + Py_CLEAR(ret); goto error; } @@ -3512,8 +3499,7 @@ libvirt_virConnectListAllStoragePools(PyObject *self ATTRIBUTE_UNUSED, if (!(tmp = libvirt_virStoragePoolPtrWrap(pools[i])) || PyList_SetItem(py_retval, i, tmp) < 0) { Py_XDECREF(tmp); - Py_DECREF(py_retval); - py_retval = NULL; + Py_CLEAR(py_retval); goto cleanup; } /* python steals the pointer */ @@ -3617,8 +3603,7 @@ libvirt_virStoragePoolListAllVolumes(PyObject *self ATTRIBUTE_UNUSED, if (!(tmp = libvirt_virStorageVolPtrWrap(vols[i])) || PyList_SetItem(py_retval, i, tmp) < 0) { Py_XDECREF(tmp); - Py_DECREF(py_retval); - py_retval = NULL; + Py_CLEAR(py_retval); goto cleanup; } /* python steals the pointer */ @@ -3889,8 +3874,7 @@ libvirt_virConnectListAllNodeDevices(PyObject *self ATTRIBUTE_UNUSED, if (!(tmp = libvirt_virNodeDevicePtrWrap(devices[i])) || PyList_SetItem(py_retval, i, tmp) < 0) { Py_XDECREF(tmp); - Py_DECREF(py_retval); - py_retval = NULL; + Py_CLEAR(py_retval); goto cleanup; } /* python steals the pointer */ @@ -4110,8 +4094,7 @@ libvirt_virConnectListAllSecrets(PyObject *self ATTRIBUTE_UNUSED, if (!(tmp = libvirt_virSecretPtrWrap(secrets[i])) || PyList_SetItem(py_retval, i, tmp) < 0) { Py_XDECREF(tmp); - Py_DECREF(py_retval); - py_retval = NULL; + Py_CLEAR(py_retval); goto cleanup; } /* python steals the pointer */ @@ -4344,8 +4327,7 @@ libvirt_virConnectListAllNWFilters(PyObject *self ATTRIBUTE_UNUSED, if (!(tmp = libvirt_virNWFilterPtrWrap(filters[i])) || PyList_SetItem(py_retval, i, tmp) < 0) { Py_XDECREF(tmp); - Py_DECREF(py_retval); - py_retval = NULL; + Py_CLEAR(py_retval); goto cleanup; } /* python steals the pointer */ @@ -4507,8 +4489,7 @@ libvirt_virConnectListAllInterfaces(PyObject *self ATTRIBUTE_UNUSED, if (!(tmp = libvirt_virInterfacePtrWrap(ifaces[i])) || PyList_SetItem(py_retval, i, tmp) < 0) { Py_XDECREF(tmp); - Py_DECREF(py_retval); - py_retval = NULL; + Py_CLEAR(py_retval); goto cleanup; } /* python steals the pointer */ @@ -4644,8 +4625,7 @@ libvirt_virDomainGetJobStats(PyObject *self ATTRIBUTE_UNUSED, if (PyDict_SetItem(dict, libvirt_constcharPtrWrap("type"), libvirt_intWrap(type)) < 0) { - Py_DECREF(dict); - dict = NULL; + Py_CLEAR(dict); goto cleanup; } @@ -5012,8 +4992,7 @@ libvirt_virDomainInterfaceAddresses(PyObject *self ATTRIBUTE_UNUSED, return py_retval; error: - Py_XDECREF(py_retval); - py_retval = NULL; + Py_CLEAR(py_retval); goto cleanup; } #endif /* LIBVIR_CHECK_VERSION(1, 2, 14) */ @@ -7694,12 +7673,11 @@ libvirt_virNodeGetCPUMap(PyObject *self ATTRIBUTE_UNUSED, VIR_FREE(cpumap); return ret; error: - Py_XDECREF(ret); + Py_CLEAR(ret); Py_XDECREF(pycpumap); Py_XDECREF(pyused); Py_XDECREF(pycpunum); Py_XDECREF(pyonline); - ret = NULL; goto cleanup; } #endif /* LIBVIR_CHECK_VERSION(1, 0, 0) */ @@ -8187,8 +8165,7 @@ libvirt_virNetworkGetDHCPLeases(PyObject *self ATTRIBUTE_UNUSED, return py_retval; error: - Py_XDECREF(py_retval); - py_retval = NULL; + Py_CLEAR(py_retval); goto cleanup; } -- 2.5.3 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list