Re: [PATCH v3 04/11] util: netlink: use VIR_AUTOPTR for aggregate types

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 13 Aug 2018 at 18:10, Erik Skultety <eskultet@xxxxxxxxxx> wrote:
>
> On Thu, Aug 09, 2018 at 09:42:12AM +0530, Sukrit Bhatnagar wrote:
> > By making use of GNU C's cleanup attribute handled by the
> > VIR_AUTOPTR macro for declaring aggregate pointer variables,
> > majority of the calls to *Free functions 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 | 72 ++++++++++++++++++++-------------------------------
> >  1 file changed, 28 insertions(+), 44 deletions(-)
> >
> > diff --git a/src/util/virnetlink.c b/src/util/virnetlink.c
> > index fcdc09d..66e80e2 100644
> > --- a/src/util/virnetlink.c
> > +++ b/src/util/virnetlink.c
> > @@ -297,15 +297,16 @@ 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_AUTOPTR(virNetlinkHandle) nlhandle = NULL;
> >      int len = 0;
> > +    VIR_AUTOPTR(virNetlinkHandle) nlhandle = NULL;
>
> unjustified code movement...
>
> > +
> > +    *respbuflen = 0;
>
> unnecessary initialization..

We need *respbuflen to be 0 if -1 is returned. So if this initialization is
removed, we need to add `*respbuflen = 0;` in the cleanup section below.

> >      memset(fds, 0, sizeof(fds));
> >
> > @@ -324,15 +325,12 @@ int virNetlinkCommand(struct nl_msg *nl_msg,
> >          goto cleanup;
> >      }
> >
> > -    ret = 0;
> >      *respbuflen = len;
> > - cleanup:
> > -    if (ret < 0) {
> > -        *resp = NULL;
> > -        *respbuflen = 0;
> > -    }
> > +    return 0;
> >
> > -    return ret;
> > + cleanup:
> > +    *resp = NULL;
> > +    return -1;
>
> I moved ^this hunk into the previous patch as I converted 1 more var into
> VIR_AUTOFREE.
>
> Reviewed-by: Erik Skultety <eskultet@xxxxxxxxxx>

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux