On Thu, Aug 09, 2018 at 09:42:11AM +0530, Sukrit Bhatnagar wrote: > 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@xxxxxxxxx> > --- > src/util/virnetlink.c | 43 ++++++++++++++++++++----------------------- > 1 file changed, 20 insertions(+), 23 deletions(-) > Actually, I squashed the following into this patch: diff --git a/src/util/virnetlink.c b/src/util/virnetlink.c index ecf62c9e72..cb8072ff94 100644 --- a/src/util/virnetlink.c +++ b/src/util/virnetlink.c @@ -297,13 +297,13 @@ int virNetlinkCommand(struct nl_msg *nl_msg, uint32_t src_pid, uint32_t dst_pid, unsigned int protocol, unsigned int groups) { - int ret = -1; struct sockaddr_nl nladdr = { .nl_family = AF_NETLINK, .nl_pid = dst_pid, .nl_groups = 0, }; struct pollfd fds[1]; + VIR_AUTOFREE(struct nlmsghdr *) temp_resp = NULL; VIR_AUTOPTR(virNetlinkHandle) nlhandle = NULL; int len = 0; @@ -311,28 +311,22 @@ int virNetlinkCommand(struct nl_msg *nl_msg, if (!(nlhandle = virNetlinkSendRequest(nl_msg, src_pid, nladdr, protocol, groups))) - goto cleanup; + return -1; - len = nl_recv(nlhandle, &nladdr, (unsigned char **)resp, NULL); + len = nl_recv(nlhandle, &nladdr, (unsigned char **)&temp_resp, NULL); if (len == 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nl_recv failed - returned 0 bytes")); - goto cleanup; + return -1; } if (len < 0) { virReportSystemError(errno, "%s", _("nl_recv failed")); - goto cleanup; + return -1; } - ret = 0; + VIR_STEAL_PTR(*resp, temp_resp); *respbuflen = len; - cleanup: - if (ret < 0) { - *resp = NULL; - *respbuflen = 0; - } - - return ret; + return 0; } Erik -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list