[PATCH 5/9] rpc: use g_autofree and remove unnecessary label

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

 



Signed-off-by: Jiang Jiacheng <jiangjiacheng@xxxxxxxxxx>
---
 src/rpc/virnetclientprogram.c |  6 ++----
 src/rpc/virnettlscontext.c    | 16 +++++-----------
 2 files changed, 7 insertions(+), 15 deletions(-)

diff --git a/src/rpc/virnetclientprogram.c b/src/rpc/virnetclientprogram.c
index 5da118bfd3..b93c495347 100644
--- a/src/rpc/virnetclientprogram.c
+++ b/src/rpc/virnetclientprogram.c
@@ -208,7 +208,7 @@ int virNetClientProgramDispatch(virNetClientProgram *prog,
                                 virNetMessage *msg)
 {
     virNetClientProgramEvent *event;
-    char *evdata;
+    g_autofree char *evdata = NULL;
 
     VIR_DEBUG("prog=%d ver=%d type=%d status=%d serial=%d proc=%d",
               msg->header.prog, msg->header.vers, msg->header.type,
@@ -250,14 +250,12 @@ int virNetClientProgramDispatch(virNetClientProgram *prog,
     evdata = g_new0(char, event->msg_len);
 
     if (virNetMessageDecodePayload(msg, event->msg_filter, evdata) < 0)
-        goto cleanup;
+        return 0;
 
     event->func(prog, client, evdata, prog->eventOpaque);
 
     xdr_free(event->msg_filter, evdata);
 
- cleanup:
-    VIR_FREE(evdata);
     return 0;
 }
 
diff --git a/src/rpc/virnettlscontext.c b/src/rpc/virnettlscontext.c
index acfc4f9323..cfd26f0701 100644
--- a/src/rpc/virnettlscontext.c
+++ b/src/rpc/virnettlscontext.c
@@ -474,7 +474,7 @@ static gnutls_x509_crt_t virNetTLSContextLoadCertFromFile(const char *certFile,
 {
     gnutls_datum_t data;
     gnutls_x509_crt_t cert = NULL;
-    char *buf = NULL;
+    g_autofree char *buf = NULL;
     int ret = -1;
 
     VIR_DEBUG("isServer %d certFile %s",
@@ -506,7 +506,6 @@ static gnutls_x509_crt_t virNetTLSContextLoadCertFromFile(const char *certFile,
     if (ret != 0) {
         g_clear_pointer(&cert, gnutls_x509_crt_deinit);
     }
-    VIR_FREE(buf);
     return cert;
 }
 
@@ -517,14 +516,13 @@ static int virNetTLSContextLoadCACertListFromFile(const char *certFile,
                                                   size_t *ncerts)
 {
     gnutls_datum_t data;
-    char *buf = NULL;
-    int ret = -1;
+    g_autofree char *buf = NULL;
 
     *ncerts = 0;
     VIR_DEBUG("certFile %s", certFile);
 
     if (virFileReadAll(certFile, (1<<16), &buf) < 0)
-        goto cleanup;
+        return -1;
 
     data.data = (unsigned char *)buf;
     data.size = strlen(buf);
@@ -533,15 +531,11 @@ static int virNetTLSContextLoadCACertListFromFile(const char *certFile,
         virReportError(VIR_ERR_SYSTEM_ERROR,
                        _("Unable to import CA certificate list %s"),
                        certFile);
-        goto cleanup;
+        return -1;
     }
     *ncerts = certMax;
 
-    ret = 0;
-
- cleanup:
-    VIR_FREE(buf);
-    return ret;
+    return 0;
 }
 
 
-- 
2.33.0





[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux