On 05/03/2013 04:53 PM, Michal Privoznik wrote: > --- > src/datatypes.c | 76 +++++++++++++++++++++++++++------------------------------ > src/libvirt.c | 14 +++-------- > src/nodeinfo.c | 5 +--- > 3 files changed, 41 insertions(+), 54 deletions(-) > > @@ -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; Duplicate virReportOOMError in these two hunks. > @@ -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); > VIR_STRDUP accepts NULL now, you should check if pool is non-null as well. > 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); > } This function doesn't report any errors. But it's an improvement to report an extra message than crash on OOM. ACK Jan -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list