[libvirt PATCHv2 15/16] qemuAgentGetInterfaceOneAddress: check for errors early

Ján Tomko jtomko at redhat.com
Wed Oct 7 12:35:36 UTC 2020


For readability, and to ensure we do allocation when
returning 0.

Signed-off-by: Ján Tomko <jtomko at redhat.com>
---
 src/qemu/qemu_agent.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
index 301707b136..60247e1616 100644
--- a/src/qemu/qemu_agent.c
+++ b/src/qemu/qemu_agent.c
@@ -2073,11 +2073,9 @@ qemuAgentGetInterfaceOneAddress(virDomainIPAddressPtr ip_addr,
                        _("qemu agent didn't provide 'ip-address-type'"
                          " field for interface '%s'"), name);
         return -1;
-    } else if (STREQ(type, "ipv4")) {
-        ip_addr->type = VIR_IP_ADDR_TYPE_IPV4;
-    } else if (STREQ(type, "ipv6")) {
-        ip_addr->type = VIR_IP_ADDR_TYPE_IPV6;
-    } else {
+    }
+
+    if (STRNEQ(type, "ipv4") && STRNEQ(type, "ipv6")) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("unknown ip address type '%s'"),
                        type);
@@ -2091,7 +2089,6 @@ qemuAgentGetInterfaceOneAddress(virDomainIPAddressPtr ip_addr,
                          " field for interface '%s'"), name);
         return -1;
     }
-    ip_addr->addr = g_strdup(addr);
 
     if (virJSONValueObjectGetNumberUint(ip_addr_obj, "prefix",
                                         &ip_addr->prefix) < 0) {
@@ -2100,6 +2097,12 @@ qemuAgentGetInterfaceOneAddress(virDomainIPAddressPtr ip_addr,
         return -1;
     }
 
+    if (STREQ(type, "ipv4"))
+        ip_addr->type = VIR_IP_ADDR_TYPE_IPV4;
+    else
+        ip_addr->type = VIR_IP_ADDR_TYPE_IPV6;
+
+    ip_addr->addr = g_strdup(addr);
     return 0;
 }
 
-- 
2.26.2




More information about the libvir-list mailing list