[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH v2 20/37] Adapt to VIR_STRDUP in src/rpc/*



---
 src/rpc/gendispatch.pl       | 13 +++++--------
 src/rpc/virnetclient.c       |  8 ++++----
 src/rpc/virnetmessage.c      | 11 ++++++-----
 src/rpc/virnetsaslcontext.c  |  3 ++-
 src/rpc/virnetserver.c       |  4 ++--
 src/rpc/virnetserverclient.c |  6 ++----
 src/rpc/virnetservermdns.c   |  4 ++--
 src/rpc/virnetsocket.c       |  6 ++++--
 src/rpc/virnetsshsession.c   | 22 +++++++++++-----------
 src/rpc/virnettlscontext.c   | 13 ++++++-------
 10 files changed, 44 insertions(+), 46 deletions(-)

diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl
index 7b93062..f1ddeed 100755
--- a/src/rpc/gendispatch.pl
+++ b/src/rpc/gendispatch.pl
@@ -610,9 +610,9 @@ elsif ($mode eq "server") {
                         # SPECIAL: virConnectGetType returns a constant string that must
                         #          not be freed. Therefore, duplicate the string here.
                         push(@vars_list, "const char *$1");
-                        push(@ret_list, "/* We have to strdup because remoteDispatchClientRequest will");
+                        push(@ret_list, "/* We have to VIR_STRDUP because remoteDispatchClientRequest will");
                         push(@ret_list, " * free this string after it's been serialised. */");
-                        push(@ret_list, "if (!(ret->type = strdup(type))) {");
+                        push(@ret_list, "if (VIR_STRDUP(ret->type, type) < 0) {");
                         push(@ret_list, "    virReportOOMError();");
                         push(@ret_list, "    goto cleanup;");
                         push(@ret_list, "}");
@@ -636,8 +636,7 @@ elsif ($mode eq "server") {
                          "        goto cleanup;\n" .
                          "    }\n" .
                          "    \n" .
-                         "    *$1_p = strdup($1);\n" .
-                         "    if (*$1_p == NULL) {\n" .
+                         "    if (VIR_STRDUP(*$1_p, $1) < 0) {\n" .
                          "        virReportOOMError();\n" .
                          "        goto cleanup;\n" .
                          "    }\n");
@@ -1562,12 +1561,10 @@ elsif ($mode eq "client") {
             print "\n";
             print "    /* This call is caller-frees (although that isn't clear from\n";
             print "     * the documentation).  However xdr_free will free up both the\n";
-            print "     * names and the list of pointers, so we have to strdup the\n";
+            print "     * names and the list of pointers, so we have to VIR_STRDUP the\n";
             print "     * names here. */\n";
             print "    for (i = 0; i < ret.$single_ret_list_name.${single_ret_list_name}_len; ++i) {\n";
-            print "        ${single_ret_list_name}[i] = strdup(ret.$single_ret_list_name.${single_ret_list_name}_val[i]);\n";
-            print "\n";
-            print "        if (${single_ret_list_name}[i] == NULL) {\n";
+            print "        if (VIR_STRDUP(${single_ret_list_name}[i], ret.$single_ret_list_name.${single_ret_list_name}_val[i]) < 0) {\n";
             print "            for (--i; i >= 0; --i)\n";
             print "                VIR_FREE(${single_ret_list_name}[i]);\n";
             print "\n";
diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c
index 1d228f0..edeb597 100644
--- a/src/rpc/virnetclient.c
+++ b/src/rpc/virnetclient.c
@@ -36,6 +36,7 @@
 #include "virlog.h"
 #include "virutil.h"
 #include "virerror.h"
+#include "virstring.h"
 
 #define VIR_FROM_THIS VIR_FROM_RPC
 
@@ -317,8 +318,7 @@ static virNetClientPtr virNetClientNew(virNetSocketPtr sock,
     client->wakeupSendFD = wakeupFD[1];
     wakeupFD[0] = wakeupFD[1] = -1;
 
-    if (hostname &&
-        !(client->hostname = strdup(hostname)))
+    if (hostname && VIR_STRDUP(client->hostname, hostname) < 0)
         goto no_memory;
 
     PROBE(RPC_CLIENT_NEW,
@@ -414,7 +414,7 @@ virNetClientPtr virNetClientNewLibSSH2(const char *host,
                     goto no_memory;
             }
         } else {
-            if (!(knownhosts = strdup(knownHostsPath)))
+            if (VIR_STRDUP(knownhosts, knownHostsPath) < 0)
                 goto no_memory;
         }
     }
@@ -438,7 +438,7 @@ virNetClientPtr virNetClientNewLibSSH2(const char *host,
                     VIR_FREE(privkey);
             }
         } else {
-            if (!(privkey = strdup(privkeyPath)))
+            if (VIR_STRDUP(privkey, privkeyPath) < 0)
                 goto no_memory;
         }
     }
diff --git a/src/rpc/virnetmessage.c b/src/rpc/virnetmessage.c
index 647fef7..6b2aa47 100644
--- a/src/rpc/virnetmessage.c
+++ b/src/rpc/virnetmessage.c
@@ -29,6 +29,7 @@
 #include "virlog.h"
 #include "virfile.h"
 #include "virutil.h"
+#include "virstring.h"
 
 #define VIR_FROM_THIS VIR_FROM_RPC
 
@@ -485,21 +486,21 @@ void virNetMessageSaveError(virNetMessageErrorPtr rerr)
         rerr->code = verr->code;
         rerr->domain = verr->domain;
         if (verr->message && VIR_ALLOC(rerr->message) == 0)
-            *rerr->message = strdup(verr->message);
+            ignore_value(VIR_STRDUP_QUIET(*rerr->message , verr->message));
         rerr->level = verr->level;
         if (verr->str1 && VIR_ALLOC(rerr->str1) == 0)
-            *rerr->str1 = strdup(verr->str1);
+            ignore_value(VIR_STRDUP_QUIET(*rerr->str1, verr->str1));
         if (verr->str2 && VIR_ALLOC(rerr->str2) == 0)
-            *rerr->str2 = strdup(verr->str2);
+            ignore_value(VIR_STRDUP_QUIET(*rerr->str2, verr->str2));
         if (verr->str3 && VIR_ALLOC(rerr->str3) == 0)
-            *rerr->str3 = strdup(verr->str3);
+            ignore_value(VIR_STRDUP_QUIET(*rerr->str3, verr->str3));
         rerr->int1 = verr->int1;
         rerr->int2 = verr->int2;
     } else {
         rerr->code = VIR_ERR_INTERNAL_ERROR;
         rerr->domain = VIR_FROM_RPC;
         if (VIR_ALLOC(rerr->message) == 0)
-            *rerr->message = strdup(_("Library function returned error but did not set virError"));
+            ignore_value(VIR_STRDUP_QUIET(*rerr->message, _("Library function returned error but did not set virError")));
         rerr->level = VIR_ERR_ERROR;
     }
 }
diff --git a/src/rpc/virnetsaslcontext.c b/src/rpc/virnetsaslcontext.c
index 6943216..9edb870 100644
--- a/src/rpc/virnetsaslcontext.c
+++ b/src/rpc/virnetsaslcontext.c
@@ -29,6 +29,7 @@
 #include "viralloc.h"
 #include "virthread.h"
 #include "virlog.h"
+#include "virstring.h"
 
 #define VIR_FROM_THIS VIR_FROM_RPC
 
@@ -385,7 +386,7 @@ char *virNetSASLSessionListMechanisms(virNetSASLSessionPtr sasl)
                        err, sasl_errdetail(sasl->conn));
         goto cleanup;
     }
-    if (!(ret = strdup(mechlist))) {
+    if (VIR_STRDUP(ret, mechlist) < 0) {
         virReportOOMError();
         goto cleanup;
     }
diff --git a/src/rpc/virnetserver.c b/src/rpc/virnetserver.c
index e536cc3..292b7b6 100644
--- a/src/rpc/virnetserver.c
+++ b/src/rpc/virnetserver.c
@@ -37,6 +37,7 @@
 #include "virfile.h"
 #include "virnetservermdns.h"
 #include "virdbus.h"
+#include "virstring.h"
 
 #ifndef SA_SIGINFO
 # define SA_SIGINFO 0
@@ -387,8 +388,7 @@ virNetServerPtr virNetServerNew(size_t min_workers,
     srv->privileged = geteuid() == 0;
     srv->autoShutdownInhibitFd = -1;
 
-    if (mdnsGroupName &&
-        !(srv->mdnsGroupName = strdup(mdnsGroupName))) {
+    if (mdnsGroupName && VIR_STRDUP(srv->mdnsGroupName, mdnsGroupName) < 0) {
         virReportOOMError();
         goto error;
     }
diff --git a/src/rpc/virnetserverclient.c b/src/rpc/virnetserverclient.c
index 2bde5c7..caa6824 100644
--- a/src/rpc/virnetserverclient.c
+++ b/src/rpc/virnetserverclient.c
@@ -681,8 +681,7 @@ virNetServerClientCreateIdentity(virNetServerClientPtr client)
 #if WITH_SASL
     if (client->sasl) {
         const char *identity = virNetSASLSessionGetIdentity(client->sasl);
-        if (identity &&
-            !(saslname = strdup(identity))) {
+        if (identity && VIR_STRDUP(saslname, identity) < 0) {
             virReportOOMError();
             goto cleanup;
         }
@@ -692,8 +691,7 @@ virNetServerClientCreateIdentity(virNetServerClientPtr client)
 #if WITH_GNUTLS
     if (client->tls) {
         const char *identity = virNetTLSSessionGetX509DName(client->tls);
-        if (identity &&
-            !(x509dname = strdup(identity))) {
+        if (identity && VIR_STRDUP(x509dname, identity) < 0) {
             virReportOOMError();
             goto cleanup;
         }
diff --git a/src/rpc/virnetservermdns.c b/src/rpc/virnetservermdns.c
index 26e24d5..eb24390 100644
--- a/src/rpc/virnetservermdns.c
+++ b/src/rpc/virnetservermdns.c
@@ -479,7 +479,7 @@ virNetServerMDNSGroupPtr virNetServerMDNSAddGroup(virNetServerMDNS *mdns,
         return NULL;
     }
 
-    if (!(group->name = strdup(name))) {
+    if (VIR_STRDUP(group->name, name) < 0) {
         VIR_FREE(group);
         virReportOOMError();
         return NULL;
@@ -525,7 +525,7 @@ virNetServerMDNSEntryPtr virNetServerMDNSAddEntry(virNetServerMDNSGroupPtr group
     }
 
     entry->port = port;
-    if (!(entry->type = strdup(type))) {
+    if (VIR_STRDUP(entry->type, type) < 0) {
         VIR_FREE(entry);
         virReportOOMError();
         return NULL;
diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c
index e950d7f..10f0b28 100644
--- a/src/rpc/virnetsocket.c
+++ b/src/rpc/virnetsocket.c
@@ -800,11 +800,13 @@ virNetSocketNewConnectLibSSH2(const char *host,
     if (virNetSSHSessionSetChannelCommand(sess, command) != 0)
         goto error;
 
-    if (!(authMethodNext = authMethodsCopy = strdup(authMethods))) {
+    if (VIR_STRDUP(authMethodNext, authMethods) < 0) {
         virReportOOMError();
         goto error;
     }
 
+    authMethodsCopy = authMethodNext;
+
     while ((authMethod = strsep(&authMethodNext, ","))) {
         if (STRCASEEQ(authMethod, "keyboard-interactive"))
             ret = virNetSSHSessionAuthAddKeyboardAuth(sess, username, -1);
@@ -1180,7 +1182,7 @@ int virNetSocketGetSecurityContext(virNetSocketPtr sock,
         goto cleanup;
     }
 
-    if (!(*context = strdup(seccon))) {
+    if (VIR_STRDUP(*context, seccon) < 0) {
         virReportOOMError();
         goto cleanup;
     }
diff --git a/src/rpc/virnetsshsession.c b/src/rpc/virnetsshsession.c
index 27750fc..c134d76 100644
--- a/src/rpc/virnetsshsession.c
+++ b/src/rpc/virnetsshsession.c
@@ -233,7 +233,7 @@ virNetSSHKbIntCb(const char *name ATTRIBUTE_UNUSED,
 
     /* fill data structures for auth callback */
     for (i = 0; i < num_prompts; i++) {
-        if (!(askcred[i].prompt = strdup(prompts[i].text))) {
+        if (VIR_STRDUP(askcred[i].prompt, prompts[i].text) < 0) {
             priv->authCbErr = VIR_NET_SSH_AUTHCB_OOM;
             goto cleanup;
         }
@@ -959,8 +959,8 @@ virNetSSHSessionAuthAddPasswordAuth(virNetSSHSessionPtr sess,
 
     virObjectLock(sess);
 
-    if (!(user = strdup(username)) ||
-        !(pass = strdup(password)))
+    if (VIR_STRDUP(user, username) < 0 ||
+        VIR_STRDUP(pass, password) < 0)
         goto no_memory;
 
     if (!(auth = virNetSSHSessionAuthMethodNew(sess)))
@@ -997,7 +997,7 @@ virNetSSHSessionAuthAddAgentAuth(virNetSSHSessionPtr sess,
 
     virObjectLock(sess);
 
-    if (!(user = strdup(username)))
+    if (VIR_STRDUP(user, username) < 0)
         goto no_memory;
 
     if (!(auth = virNetSSHSessionAuthMethodNew(sess)))
@@ -1037,11 +1037,11 @@ virNetSSHSessionAuthAddPrivKeyAuth(virNetSSHSessionPtr sess,
 
     virObjectLock(sess);
 
-    if (!(user = strdup(username)) ||
-        !(file = strdup(keyfile)))
+    if (VIR_STRDUP(user, username) < 0 ||
+        VIR_STRDUP(file, keyfile) < 0)
         goto no_memory;
 
-    if (password && !(pass = strdup(password)))
+    if (password && VIR_STRDUP(pass, password) < 0)
         goto no_memory;
 
     if (!(auth = virNetSSHSessionAuthMethodNew(sess)))
@@ -1081,7 +1081,7 @@ virNetSSHSessionAuthAddKeyboardAuth(virNetSSHSessionPtr sess,
 
     virObjectLock(sess);
 
-    if (!(user = strdup(username)))
+    if (VIR_STRDUP(user, username) < 0)
         goto no_memory;
 
     if (!(auth = virNetSSHSessionAuthMethodNew(sess)))
@@ -1111,7 +1111,7 @@ virNetSSHSessionSetChannelCommand(virNetSSHSessionPtr sess,
 
     VIR_FREE(sess->channelCommand);
 
-    if (command && !(sess->channelCommand = strdup(command))) {
+    if (command && VIR_STRDUP(sess->channelCommand, command) < 0) {
         virReportOOMError();
         ret = -1;
     }
@@ -1137,7 +1137,7 @@ virNetSSHSessionSetHostKeyVerification(virNetSSHSessionPtr sess,
 
     VIR_FREE(sess->hostname);
 
-    if (hostname && !(sess->hostname = strdup(hostname)))
+    if (hostname && VIR_STRDUP(sess->hostname, hostname) < 0)
         goto no_memory;
 
     /* load the known hosts file */
@@ -1162,7 +1162,7 @@ virNetSSHSessionSetHostKeyVerification(virNetSSHSessionPtr sess,
         /* set filename only if writing to the known hosts file is requested */
         if (!(flags & VIR_NET_SSH_HOSTKEY_FILE_READONLY)) {
             VIR_FREE(sess->knownHostsFile);
-            if (!(sess->knownHostsFile = strdup(hostsfile)))
+            if (VIR_STRDUP(sess->knownHostsFile, hostsfile) < 0)
                 goto no_memory;
         }
     }
diff --git a/src/rpc/virnettlscontext.c b/src/rpc/virnettlscontext.c
index 7f5975d..a80aefe 100644
--- a/src/rpc/virnettlscontext.c
+++ b/src/rpc/virnettlscontext.c
@@ -836,22 +836,22 @@ static int virNetTLSContextLocateCredentials(const char *pkipath,
      */
     if (!*cacert) {
         VIR_DEBUG("Using default TLS CA certificate path");
-        if (!(*cacert = strdup(LIBVIRT_CACERT)))
+        if (VIR_STRDUP(*cacert, LIBVIRT_CACERT) < 0)
             goto out_of_memory;
     }
 
     if (!*cacrl) {
         VIR_DEBUG("Using default TLS CA revocation list path");
-        if (!(*cacrl = strdup(LIBVIRT_CACRL)))
+        if (VIR_STRDUP(*cacrl, LIBVIRT_CACRL) < 0)
             goto out_of_memory;
     }
 
     if (!*key && !*cert) {
         VIR_DEBUG("Using default TLS key/certificate path");
-        if (!(*key = strdup(isServer ? LIBVIRT_SERVERKEY : LIBVIRT_CLIENTKEY)))
+        if (VIR_STRDUP(*key, isServer ? LIBVIRT_SERVERKEY : LIBVIRT_CLIENTKEY) < 0)
             goto out_of_memory;
 
-        if (!(*cert = strdup(isServer ? LIBVIRT_SERVERCERT : LIBVIRT_CLIENTCERT)))
+        if (VIR_STRDUP(*cert, isServer ? LIBVIRT_SERVERCERT : LIBVIRT_CLIENTCERT) < 0)
             goto out_of_memory;
     }
 
@@ -1028,7 +1028,7 @@ static int virNetTLSContextValidCertificate(virNetTLSContextPtr ctxt,
                                "[session]", gnutls_strerror(ret));
                 goto authfail;
             }
-            if (!(sess->x509dname = strdup(dname))) {
+            if (VIR_STRDUP(sess->x509dname, dname) < 0) {
                 virReportOOMError();
                 goto authfail;
             }
@@ -1168,8 +1168,7 @@ virNetTLSSessionPtr virNetTLSSessionNew(virNetTLSContextPtr ctxt,
     if (!(sess = virObjectLockableNew(virNetTLSSessionClass)))
         return NULL;
 
-    if (hostname &&
-        !(sess->hostname = strdup(hostname))) {
+    if (hostname && VIR_STRDUP(sess->hostname, hostname) < 0) {
         virReportOOMError();
         goto error;
     }
-- 
1.8.1.5


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]