---
src/datatypes.c | 76 +++++++++++++++++++++++++++------------------------------
src/libvirt.c | 14 +++--------
src/nodeinfo.c | 5 +---
3 files changed, 41 insertions(+), 54 deletions(-)
diff --git a/src/datatypes.c b/src/datatypes.c
index d3cf5f2..41e9c57 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,8 +226,8 @@ virGetDomain(virConnectPtr conn, const char *name, const unsigned char
*uuid)
if (!(ret = virObjectNew(virDomainClass)))
return NULL;
- if (!(ret->name = strdup(name)))
- goto no_memory;
+ if (VIR_STRDUP(ret->name, name) < 0)
+ goto error;
ret->conn = virObjectRef(conn);
ret->id = -1;
@@ -234,8 +235,7 @@ virGetDomain(virConnectPtr conn, const char *name, const unsigned char
*uuid)
return ret;
-no_memory:
- virReportOOMError();
+error:
virObjectUnref(ret);
return NULL;
}
@@ -297,15 +297,15 @@ virGetNetwork(virConnectPtr conn, const char *name, const unsigned
char *uuid)
if (!(ret = virObjectNew(virNetworkClass)))
return NULL;
- if (!(ret->name = strdup(name)))
- goto no_memory;
+ if (VIR_STRDUP(ret->name, name) < 0)
+ goto error;
ret->conn = virObjectRef(conn);
memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
return ret;
-no_memory:
+error:
virReportOOMError();
virObjectUnref(ret);
return NULL;
@@ -372,16 +372,15 @@ virGetInterface(virConnectPtr conn, const char *name, const char
*mac)
if (!(ret = virObjectNew(virInterfaceClass)))
return NULL;
- if (!(ret->name = strdup(name)))
- goto no_memory;
- if (!(ret->mac = strdup(mac)))
- goto no_memory;
+ if (VIR_STRDUP(ret->name, name) < 0 ||
+ VIR_STRDUP(ret->mac, mac) < 0)
+ goto error;
ret->conn = virObjectRef(conn);
return ret;
-no_memory:
+error:
virReportOOMError();
virObjectUnref(ret);
return NULL;
@@ -446,8 +445,8 @@ virGetStoragePool(virConnectPtr conn, const char *name,
if (!(ret = virObjectNew(virStoragePoolClass)))
return NULL;
- if (!(ret->name = strdup(name)))
- goto no_memory;
+ if (VIR_STRDUP(ret->name, name) < 0)
+ goto error;
ret->conn = virObjectRef(conn);
memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
@@ -458,8 +457,7 @@ virGetStoragePool(virConnectPtr conn, const char *name,
return ret;
-no_memory:
- virReportOOMError();
+error:
virObjectUnref(ret);
return NULL;
}
@@ -530,12 +528,10 @@ virGetStorageVol(virConnectPtr conn, const char *pool, const char
*name,
if (!(ret = virObjectNew(virStorageVolClass)))
return NULL;
- if (!(ret->pool = strdup(pool)))
- goto no_memory;
- if (!(ret->name = strdup(name)))
- goto no_memory;
- if (!(ret->key = strdup(key)))
- goto no_memory;
+ if (VIR_STRDUP(ret->pool, pool) < 0 ||
+ VIR_STRDUP(ret->name, name) < 0 ||
+ VIR_STRDUP(ret->key, key) < 0)
+ goto error;
ret->conn = virObjectRef(conn);
@@ -545,8 +541,7 @@ virGetStorageVol(virConnectPtr conn, const char *pool, const char
*name,
return ret;
-no_memory:
- virReportOOMError();
+error:
virObjectUnref(ret);
return NULL;
}
@@ -610,13 +605,13 @@ virGetNodeDevice(virConnectPtr conn, const char *name)
if (!(ret = virObjectNew(virNodeDeviceClass)))
return NULL;
- if (!(ret->name = strdup(name)))
- goto no_memory;
+ if (VIR_STRDUP(ret->name, name) < 0)
+ goto error;
ret->conn = virObjectRef(conn);
return ret;
-no_memory:
- virReportOOMError();
+
+error:
virObjectUnref(ret);
return NULL;
}
@@ -680,14 +675,14 @@ virGetSecret(virConnectPtr conn, const unsigned char *uuid,
memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
ret->usageType = usageType;
- if (!(ret->usageID = strdup(usageID)))
- goto no_memory;
+ if (VIR_STRDUP(ret->usageID, usageID) < 0)
+ goto error;
ret->conn = virObjectRef(conn);
return ret;
-no_memory:
- virReportOOMError();
+
+error:
virObjectUnref(ret);
return NULL;
}
@@ -775,16 +770,16 @@ virGetNWFilter(virConnectPtr conn, const char *name,
if (!(ret = virObjectNew(virNWFilterClass)))
return NULL;
- if (!(ret->name = strdup(name)))
- goto no_memory;
+ if (VIR_STRDUP(ret->name, name) < 0)
+ goto error;
memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
ret->conn = virObjectRef(conn);
return ret;
-no_memory:
- virReportOOMError();
+
+error:
virObjectUnref(ret);
return NULL;
}
@@ -832,13 +827,14 @@ virGetDomainSnapshot(virDomainPtr domain, const char *name)
if (!(ret = virObjectNew(virDomainSnapshotClass)))
return NULL;
- if (!(ret->name = strdup(name)))
- goto no_memory;
+ if (VIR_STRDUP(ret->name, name) < 0)
+ goto cleanup;
+
ret->domain = virObjectRef(domain);
return ret;
-no_memory:
- virReportOOMError();
+
+cleanup:
virObjectUnref(ret);
return NULL;
}
diff --git a/src/libvirt.c b/src/libvirt.c
index 467f6dd..5007971 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -213,11 +213,9 @@ static int virConnectAuthCallbackDefault(virConnectCredentialPtr
cred,
}
if (cred[i].type != VIR_CRED_EXTERNAL) {
- if (STREQ(bufptr, "") && cred[i].defresult)
- cred[i].result = strdup(cred[i].defresult);
- else
- cred[i].result = strdup(bufptr);
- if (!cred[i].result)
+ if (VIR_STRDUP(cred[i].result,
+ STREQ(bufptr, "") && cred[i].defresult ?
+ cred[i].defresult : bufptr) < 0)
return -1;
cred[i].resultlen = strlen(cred[i].result);
}
@@ -1046,11 +1044,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))) {
- virReportOOMError();
- return -1;
- }
- return 0;
+ return VIR_STRDUP(*uri, offset+1);
}
entry = entry->next;
diff --git a/src/nodeinfo.c b/src/nodeinfo.c
index 95c2f33..ca28452 100644
--- a/src/nodeinfo.c
+++ b/src/nodeinfo.c
@@ -984,11 +984,8 @@ int nodeGetMemoryStats(virConnectPtr conn ATTRIBUTE_UNUSED,
FILE *meminfo;
if (cellNum == VIR_NODE_MEMORY_STATS_ALL_CELLS) {
- meminfo_path = strdup(MEMINFO_PATH);
- if (!meminfo_path) {
- virReportOOMError();
+ if (VIR_STRDUP(meminfo_path, MEMINFO_PATH) < 0)
return -1;
- }
} else {
# if WITH_NUMACTL
if (numa_available() < 0) {
--
1.8.1.5