]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
Rework remoteSerializeDHCPLease
authorJán Tomko <jtomko@redhat.com>
Tue, 24 Jun 2014 12:37:55 +0000 (14:37 +0200)
committerJán Tomko <jtomko@redhat.com>
Tue, 24 Jun 2014 12:41:50 +0000 (14:41 +0200)
Don't leak the temporary variables on success if NULL is returned
for that field.

Don't dereference NULL on failure to allocate some of the temporaries.

Introduced by commit 990c3b6

daemon/remote.c

index ae19b2a7ab3bd9e09de56526f4b3b05cb3a83de9..9ffc1cb8c78baa7ce8aea45ab2c01a8d19bfaded 100644 (file)
@@ -6213,36 +6213,51 @@ remoteSerializeDHCPLease(remote_network_dhcp_lease *lease_dst, virNetworkDHCPLea
     char **hostname_tmp = NULL;
     char **clientid_tmp = NULL;
 
-    if (VIR_ALLOC(mac_tmp) < 0 ||
-        VIR_ALLOC(iaid_tmp) < 0 ||
-        VIR_ALLOC(hostname_tmp) < 0 ||
-        VIR_ALLOC(clientid_tmp) < 0)
-        goto error;
-
     lease_dst->expirytime = lease_src->expirytime;
     lease_dst->type = lease_src->type;
     lease_dst->prefix = lease_src->prefix;
 
     if (VIR_STRDUP(lease_dst->iface, lease_src->iface) < 0 ||
-        VIR_STRDUP(lease_dst->ipaddr, lease_src->ipaddr) < 0 ||
-        VIR_STRDUP(*mac_tmp, lease_src->mac) < 0 ||
-        VIR_STRDUP(*iaid_tmp, lease_src->iaid) < 0 ||
-        VIR_STRDUP(*hostname_tmp, lease_src->hostname) < 0 ||
-        VIR_STRDUP(*clientid_tmp, lease_src->clientid) < 0)
+        VIR_STRDUP(lease_dst->ipaddr, lease_src->ipaddr) < 0)
         goto error;
 
-    lease_dst->mac = *mac_tmp ? mac_tmp : NULL;
-    lease_dst->iaid = *iaid_tmp ? iaid_tmp : NULL;
-    lease_dst->hostname = *hostname_tmp ? hostname_tmp : NULL;
-    lease_dst->clientid = *clientid_tmp ? clientid_tmp : NULL;
+    if (lease_src->mac) {
+        if (VIR_ALLOC(mac_tmp) < 0 ||
+            VIR_STRDUP(*mac_tmp, lease_src->mac) < 0)
+            goto error;
+    }
+    if (lease_src->iaid) {
+        if (VIR_ALLOC(iaid_tmp) < 0 ||
+            VIR_STRDUP(*iaid_tmp, lease_src->iaid) < 0)
+            goto error;
+    }
+    if (lease_src->hostname) {
+        if (VIR_ALLOC(hostname_tmp) < 0 ||
+            VIR_STRDUP(*hostname_tmp, lease_src->hostname) < 0)
+            goto error;
+    }
+    if (lease_src->clientid) {
+        if (VIR_ALLOC(clientid_tmp) < 0 ||
+            VIR_STRDUP(*clientid_tmp, lease_src->clientid) < 0)
+            goto error;
+    }
+
+    lease_dst->mac = mac_tmp;
+    lease_dst->iaid = iaid_tmp;
+    lease_dst->hostname = hostname_tmp;
+    lease_dst->clientid = clientid_tmp;
 
     return 0;
 
  error:
-    VIR_FREE(*mac_tmp);
-    VIR_FREE(*iaid_tmp);
-    VIR_FREE(*hostname_tmp);
-    VIR_FREE(*clientid_tmp);
+    if (mac_tmp)
+        VIR_FREE(*mac_tmp);
+    if (iaid_tmp)
+        VIR_FREE(*iaid_tmp);
+    if (hostname_tmp)
+        VIR_FREE(*hostname_tmp);
+    if (clientid_tmp)
+        VIR_FREE(*clientid_tmp);
     VIR_FREE(mac_tmp);
     VIR_FREE(iaid_tmp);
     VIR_FREE(hostname_tmp);