--- src/datatypes.c | 25 +++++++++++++------------ src/libvirt.c | 9 +++++---- src/nodeinfo.c | 3 +-- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/datatypes.c b/src/datatypes.c index d3cf5f2..71aab04 100644 --- a/src/datatypes.c +++ b/src/datatypes.c @@ -27,6 +27,7 @@ #include "virlog.h" #include "viralloc.h" #include "viruuid.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_NONE @@ -225,7 +226,7 @@ virGetDomain(virConnectPtr conn, const char *name, const unsigned char *uuid) if (!(ret = virObjectNew(virDomainClass))) return NULL; - if (!(ret->name = strdup(name))) + if (VIR_STRDUP(ret->name, name) < 0) goto no_memory; ret->conn = virObjectRef(conn); @@ -297,7 +298,7 @@ virGetNetwork(virConnectPtr conn, const char *name, const unsigned char *uuid) if (!(ret = virObjectNew(virNetworkClass))) return NULL; - if (!(ret->name = strdup(name))) + if (VIR_STRDUP(ret->name, name) < 0) goto no_memory; ret->conn = virObjectRef(conn); @@ -372,9 +373,9 @@ virGetInterface(virConnectPtr conn, const char *name, const char *mac) if (!(ret = virObjectNew(virInterfaceClass))) return NULL; - if (!(ret->name = strdup(name))) + if (VIR_STRDUP(ret->name, name) < 0) goto no_memory; - if (!(ret->mac = strdup(mac))) + if (VIR_STRDUP(ret->mac, mac) < 0) goto no_memory; ret->conn = virObjectRef(conn); @@ -446,7 +447,7 @@ virGetStoragePool(virConnectPtr conn, const char *name, if (!(ret = virObjectNew(virStoragePoolClass))) return NULL; - if (!(ret->name = strdup(name))) + if (VIR_STRDUP(ret->name, name) < 0) goto no_memory; ret->conn = virObjectRef(conn); @@ -530,11 +531,11 @@ virGetStorageVol(virConnectPtr conn, const char *pool, const char *name, if (!(ret = virObjectNew(virStorageVolClass))) return NULL; - if (!(ret->pool = strdup(pool))) + if (VIR_STRDUP(ret->pool, pool) < 0) goto no_memory; - if (!(ret->name = strdup(name))) + if (VIR_STRDUP(ret->name, name) < 0) goto no_memory; - if (!(ret->key = strdup(key))) + if (VIR_STRDUP(ret->key, key) < 0) goto no_memory; ret->conn = virObjectRef(conn); @@ -610,7 +611,7 @@ virGetNodeDevice(virConnectPtr conn, const char *name) if (!(ret = virObjectNew(virNodeDeviceClass))) return NULL; - if (!(ret->name = strdup(name))) + if (VIR_STRDUP(ret->name, name) < 0) goto no_memory; ret->conn = virObjectRef(conn); @@ -680,7 +681,7 @@ virGetSecret(virConnectPtr conn, const unsigned char *uuid, memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN); ret->usageType = usageType; - if (!(ret->usageID = strdup(usageID))) + if (VIR_STRDUP(ret->usageID, usageID) < 0) goto no_memory; ret->conn = virObjectRef(conn); @@ -775,7 +776,7 @@ virGetNWFilter(virConnectPtr conn, const char *name, if (!(ret = virObjectNew(virNWFilterClass))) return NULL; - if (!(ret->name = strdup(name))) + if (VIR_STRDUP(ret->name, name) < 0) goto no_memory; memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN); @@ -832,7 +833,7 @@ virGetDomainSnapshot(virDomainPtr domain, const char *name) if (!(ret = virObjectNew(virDomainSnapshotClass))) return NULL; - if (!(ret->name = strdup(name))) + if (VIR_STRDUP(ret->name, name) < 0) goto no_memory; ret->domain = virObjectRef(domain); diff --git a/src/libvirt.c b/src/libvirt.c index 15b37a3..1ebb2c5 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -212,11 +212,12 @@ static int virConnectAuthCallbackDefault(virConnectCredentialPtr cred, } if (cred[i].type != VIR_CRED_EXTERNAL) { + int rc; if (STREQ(bufptr, "") && cred[i].defresult) - cred[i].result = strdup(cred[i].defresult); + rc = VIR_STRDUP(cred[i].result, cred[i].defresult); else - cred[i].result = strdup(bufptr); - if (!cred[i].result) + rc = VIR_STRDUP(cred[i].result, bufptr); + if (rc < 0) return -1; cred[i].resultlen = strlen(cred[i].result); } @@ -1045,7 +1046,7 @@ virConnectOpenFindURIAliasMatch(virConfValuePtr value, const char *alias, char * STREQLEN(entry->str, alias, alias_len)) { VIR_DEBUG("Resolved alias '%s' to '%s'", alias, offset+1); - if (!(*uri = strdup(offset+1))) { + if (VIR_STRDUP(*uri, offset+1) < 0) { virReportOOMError(); return -1; } diff --git a/src/nodeinfo.c b/src/nodeinfo.c index 95c2f33..e3a0329 100644 --- a/src/nodeinfo.c +++ b/src/nodeinfo.c @@ -984,8 +984,7 @@ int nodeGetMemoryStats(virConnectPtr conn ATTRIBUTE_UNUSED, FILE *meminfo; if (cellNum == VIR_NODE_MEMORY_STATS_ALL_CELLS) { - meminfo_path = strdup(MEMINFO_PATH); - if (!meminfo_path) { + if (VIR_STRDUP(meminfo_path, MEMINFO_PATH) < 0) { virReportOOMError(); return -1; } -- 1.8.1.5 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list