mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
util: arptable: use VIR_AUTOFREE instead of VIR_FREE for scalar types
By making use of GNU C's cleanup attribute handled by the VIR_AUTOFREE macro for declaring scalar variables, majority of the VIR_FREE calls can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar <skrtbhtngr@gmail.com> Reviewed-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
parent
d7bade31f6
commit
b00c9c390a
@ -71,9 +71,8 @@ virArpTableGet(void)
|
|||||||
{
|
{
|
||||||
int num = 0;
|
int num = 0;
|
||||||
int msglen;
|
int msglen;
|
||||||
void *nlData = NULL;
|
VIR_AUTOFREE(void *) nlData = NULL;
|
||||||
virArpTablePtr table = NULL;
|
virArpTablePtr table = NULL;
|
||||||
char *ipstr = NULL;
|
|
||||||
struct nlmsghdr* nh;
|
struct nlmsghdr* nh;
|
||||||
struct rtattr * tb[NDA_MAX+1];
|
struct rtattr * tb[NDA_MAX+1];
|
||||||
|
|
||||||
@ -108,7 +107,7 @@ virArpTableGet(void)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (nh->nlmsg_type == NLMSG_DONE)
|
if (nh->nlmsg_type == NLMSG_DONE)
|
||||||
goto end_of_netlink_messages;
|
return table;
|
||||||
|
|
||||||
VIR_WARNINGS_NO_CAST_ALIGN
|
VIR_WARNINGS_NO_CAST_ALIGN
|
||||||
parse_rtattr(tb, NDA_MAX, NDA_RTA(r),
|
parse_rtattr(tb, NDA_MAX, NDA_RTA(r),
|
||||||
@ -119,6 +118,7 @@ virArpTableGet(void)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (tb[NDA_DST]) {
|
if (tb[NDA_DST]) {
|
||||||
|
VIR_AUTOFREE(char *) ipstr = NULL;
|
||||||
virSocketAddr virAddr;
|
virSocketAddr virAddr;
|
||||||
if (VIR_REALLOC_N(table->t, num + 1) < 0)
|
if (VIR_REALLOC_N(table->t, num + 1) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -134,8 +134,6 @@ virArpTableGet(void)
|
|||||||
|
|
||||||
if (VIR_STRDUP(table->t[num].ipaddr, ipstr) < 0)
|
if (VIR_STRDUP(table->t[num].ipaddr, ipstr) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
VIR_FREE(ipstr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tb[NDA_LLADDR]) {
|
if (tb[NDA_LLADDR]) {
|
||||||
@ -154,14 +152,8 @@ virArpTableGet(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
end_of_netlink_messages:
|
|
||||||
VIR_FREE(nlData);
|
|
||||||
return table;
|
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virArpTableFree(table);
|
virArpTableFree(table);
|
||||||
VIR_FREE(ipstr);
|
|
||||||
VIR_FREE(nlData);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user