mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-24 14:45:24 +00:00
qemu: agent: expand addrs upfront
qemuAgentGetInterfaceOneAddress returns exactly one address for every iteration of the loop (and we error out if not). Instead of expanding the addrs by one on every iteration, do it upfront since we know how many times the loop will execute. Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com> Reviewed-by: Neal Gompa <ngompa13@gmail.com>
This commit is contained in:
parent
269af9f692
commit
89b43c3e25
@ -2213,20 +2213,18 @@ qemuAgentGetInterfaces(qemuAgentPtr agent,
|
||||
/* If current iface already exists, continue with the count */
|
||||
addrs_count = iface->naddrs;
|
||||
|
||||
if (VIR_EXPAND_N(iface->addrs, addrs_count,
|
||||
virJSONValueArraySize(ip_addr_arr)) < 0)
|
||||
goto error;
|
||||
|
||||
for (j = 0; j < virJSONValueArraySize(ip_addr_arr); j++) {
|
||||
virJSONValuePtr ip_addr_obj = virJSONValueArrayGet(ip_addr_arr, j);
|
||||
virDomainIPAddressPtr ip_addr;
|
||||
|
||||
if (VIR_EXPAND_N(iface->addrs, addrs_count, 1) < 0)
|
||||
goto error;
|
||||
|
||||
ip_addr = &iface->addrs[addrs_count - 1];
|
||||
virDomainIPAddressPtr ip_addr = iface->addrs + iface->naddrs;
|
||||
iface->naddrs++;
|
||||
|
||||
if (qemuAgentGetInterfaceOneAddress(ip_addr, ip_addr_obj, name) < 0)
|
||||
goto error;
|
||||
}
|
||||
|
||||
iface->naddrs = addrs_count;
|
||||
}
|
||||
|
||||
*ifaces = g_steal_pointer(&ifaces_ret);
|
||||
|
Loading…
Reference in New Issue
Block a user