[libvirt PATCH 07/20] openvz: refactor openvzDomainSetNetwork

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

 



Signed-off-by: Ján Tomko <jtomko@xxxxxxxxxx>
---
 src/openvz/openvz_driver.c | 21 +++++++--------------
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c
index 073de66611..cffdb20898 100644
--- a/src/openvz/openvz_driver.c
+++ b/src/openvz/openvz_driver.c
@@ -661,13 +661,12 @@ openvzDomainSetNetwork(virConnectPtr conn, const char *vpsid,
                        virDomainNetDef *net,
                        virBuffer *configBuf)
 {
-    int rc = -1;
     char macaddr[VIR_MAC_STRING_BUFLEN];
     virMacAddr host_mac;
     char host_macaddr[VIR_MAC_STRING_BUFLEN];
     struct openvz_driver *driver =  conn->privateData;
-    virCommand *cmd = NULL;
-    char *guest_ifname = NULL;
+    g_autoptr(virCommand) cmd = NULL;
+    g_autofree char *guest_ifname = NULL;
 
     if (net == NULL)
         return 0;
@@ -703,7 +702,7 @@ openvzDomainSetNetwork(virConnectPtr conn, const char *vpsid,
             if (guest_ifname == NULL) {
                 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                                _("Could not generate eth name for container"));
-                goto cleanup;
+                return -1;
             }
         }
 
@@ -714,7 +713,7 @@ openvzDomainSetNetwork(virConnectPtr conn, const char *vpsid,
             if (net->ifname == NULL) {
                 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                                _("Could not generate veth name"));
-                goto cleanup;
+                return -1;
             }
         }
 
@@ -744,23 +743,17 @@ openvzDomainSetNetwork(virConnectPtr conn, const char *vpsid,
 
         /* --ipadd ip */
         for (i = 0; i < net->guestIP.nips; i++) {
-            char *ipStr = virSocketAddrFormat(&net->guestIP.ips[i]->address);
+            g_autofree char *ipStr = virSocketAddrFormat(&net->guestIP.ips[i]->address);
             if (!ipStr)
-                goto cleanup;
+                return -1;
             virCommandAddArgList(cmd, "--ipadd", ipStr, NULL);
-            VIR_FREE(ipStr);
         }
     }
 
     /* TODO: processing NAT and physical device */
 
     virCommandAddArg(cmd, "--save");
-    rc = virCommandRun(cmd, NULL);
-
- cleanup:
-    virCommandFree(cmd);
-    VIR_FREE(guest_ifname);
-    return rc;
+    return virCommandRun(cmd, NULL);
 }
 
 
-- 
2.31.1




[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